-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat((background) added rule store to look up rules
- Loading branch information
1 parent
07b50cd
commit f636b53
Showing
8 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# vue-chrome-interceptor | ||
# vue-interceptor | ||
|
||
A simple chrome extension which helps in url redirection, modify request/response headers written vue with vuetify. | ||
A simple chrome/firefox extension which helps in url redirection, modify request/response headers written in vue with vuetify. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ruleStore } from './rules-store'; | ||
import { utils } from './utils'; | ||
|
||
class BackgroundScript { | ||
init() { | ||
try { | ||
ruleStore.init(); | ||
browser.browserAction.onClicked.addListener(this.handleBrowserAction); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
// Handlers | ||
handleBrowserAction() { | ||
const optionsUrl = chrome.extension.getURL('options.html'); | ||
utils.openOptionsPage(optionsUrl); | ||
} | ||
} | ||
|
||
export const backgroundScript = new BackgroundScript(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
browser.browserAction.onClicked.addListener(function() { | ||
console.log('Hello from the background'); | ||
}); | ||
import { backgroundScript } from './background-script'; | ||
|
||
backgroundScript.init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Rule } from '@/libs'; | ||
import { RedirectRulesMap } from './types'; | ||
import { rulesRepository } from '../libs/storage/rules-repository'; | ||
|
||
class RuleStore { | ||
allRules: Rule[] = []; | ||
redirectRules: RedirectRulesMap = {}; | ||
|
||
async init() { | ||
this.allRules = await this.fetchAll(); | ||
this.allRules.forEach(rule => { | ||
console.log(rule); | ||
}); | ||
} | ||
|
||
async fetchAll() { | ||
return await rulesRepository.fetchAll(); | ||
} | ||
} | ||
|
||
export const ruleStore = new RuleStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface RedirectRulesMap { | ||
[fromUrl: string]: string; | ||
} | ||
|
||
export interface ModifyHeaderRulesMap { | ||
[url: string]: { | ||
key: string; | ||
value: string | number; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Utils { | ||
openOptionsPage(optionsUrl: string) { | ||
chrome.tabs.query({}, function(extensionTabs: chrome.tabs.Tab[]) { | ||
let found = false; | ||
|
||
for (let i = 0, len = extensionTabs.length; i < len; i++) { | ||
if (optionsUrl === extensionTabs[i].url) { | ||
found = true; | ||
chrome.tabs.update(extensionTabs[i].id ?? Math.random(), { | ||
selected: true | ||
}); | ||
break; | ||
} | ||
} | ||
if (found === false) { | ||
chrome.tabs.create({ url: optionsUrl }); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export const utils = new Utils(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters