diff --git a/package.json b/package.json index d42204b..61ac9f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "no-coin", - "version": "0.3.2", + "version": "0.3.3", "description": "Stop coin miners on the web!", "repository": { "type": "git", diff --git a/src/js/background.js b/src/js/background.js index 022c23b..653801b 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -83,7 +83,34 @@ const removeDomainFromWhitelist = (domain) => { config.whitelist = config.whitelist.filter(w => w.domain !== domain); saveConfig(); -} +}; + +const runBlocker = (blacklist) => { + const blacklistedUrls = blacklist.split('\n'); + + chrome.webRequest.onBeforeRequest.addListener(details => { + // Globally paused + if (!config.toggle) { + return { cancel: false }; + } + + // Is domain white listed + if (isDomainWhitelisted(domains[details.tabId])) { + return { cancel: false }; + } + + return { cancel: true }; + }, { + urls: blacklistedUrls + }, ['blocking']); +}; + +const runFallbackBlocker = () => { + fetch(chrome.runtime.getURL('blacklist.txt')) + .then(resp => { + resp.text().then(text => runBlocker(text)); + }); +}; /** * Main @@ -104,38 +131,18 @@ if (!config.toggle) { changeToggleIcon(false); } -// Load the blacklist and run the request checker -const blacklist = chrome.runtime.getURL("blacklist.txt"); +// Load the blacklist and run the blocker +const blacklist = 'https://raw.githubusercontent.com/keraf/aaaNoCoin/master/src/blacklist.txt'; fetch(blacklist) .then(resp => { - resp.text() - .then(text => { - const blacklistedUrls = text.split('\r\n'); - - chrome.webRequest.onBeforeRequest.addListener(details => { - // Globally paused - if (!config.toggle) { - return { cancel: false }; - } - - // Is domain white listed - if (isDomainWhitelisted(domains[details.tabId])) { - return { cancel: false }; - } - - return { cancel: true }; - }, { - urls: blacklistedUrls - }, ['blocking']); - }) - .catch(err => { - // TODO: Handle this - console.log(err); - }); + if (resp.status === 200) { + resp.text().then(text => runBlocker(text)); + } else { + runFallbackBlocker(); + } }) .catch(err => { - // TODO: Handle this - console.log(err); + runFallbackBlocker(); }); // Communication with the popup and content scripts diff --git a/src/js/popup.js b/src/js/popup.js index a716e93..eddcb1e 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -44,14 +44,12 @@ document.querySelector('.toggle').addEventListener('click', () => { const listElements = document.getElementsByClassName('list'); for (let i = 0; i < listElements.length; i++) { listElements[i].addEventListener('click', (e) => { - console.log(e); chrome.runtime.sendMessage({ type: 'WHITELIST', time: e.target.getAttribute('data-time'), tabId: currentTabId, whitelisted, }, (response) => { - console.log(response); setWhitelistOptions(response); chrome.tabs.reload(currentTabId); });