Fix off switch not working

This commit is contained in:
Yamboy1 2020-01-12 09:30:10 +13:00
parent c155eeb4a7
commit 345bf471d9
3 changed files with 23 additions and 26 deletions

View file

@ -9,7 +9,6 @@
],
"background": {
"scripts": [
"scripts/browserActionOnClicked.js",
"scripts/runtimeOnStartup.js",
"scripts/storageOnChanged.js",
"scripts/tabOnUpdated.js"

View file

@ -1,5 +0,0 @@
chrome.browserAction.onClicked.addListener(() => {
chrome.storage.local.get('enabled', ({ enabled }) => {
chrome.storage.local.set({ enabled: !enabled });
});
});

View file

@ -1,4 +1,6 @@
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
chrome.storage.local.get(async ({ enabled }) => {
if (!enabled) return;
if (!changeInfo.url) return;
const { id, type } = getId(tab.url);
if (!id) return;
@ -21,6 +23,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
}
chrome.tabs.update(tabId, { url: newUrl });
});
});
});
function getId(url) {