diff --git a/background.js b/background.js index 8153469..2c0a55f 100644 --- a/background.js +++ b/background.js @@ -3,9 +3,10 @@ var BETTER_ALTERNATIVES = []; chrome.runtime.onInstalled.addListener(function() { console.log('onInstalled....'); + onStartup(); }); -// fetch and save data when chrome restarted, alarm will continue running when chrome is restarted +// fetch and save data when chrome restarted chrome.runtime.onStartup.addListener(() => { console.log('onStartup....'); onStartup(); @@ -29,7 +30,7 @@ function onStartup(){ } function getMatch(url){ - var match = BETTER_ALTERNATIVES.find(pattern => url.match(new Regexp(pattern[0]))); + var match = BETTER_ALTERNATIVES.find(pattern => url.match(new RegExp(pattern[0]))); if(match) return match[1]; else return null; @@ -40,6 +41,9 @@ chrome.runtime.onMessage.addListener((msg, sender, response) => { case 'getMatch': response(getMatch(msg.url)); break; + case 'reloadList': + onStartup(); + break; default: response('unknown request'); break; diff --git a/contentscript.js b/contentscript.js index bdac3d3..191d5a4 100644 --- a/contentscript.js +++ b/contentscript.js @@ -11,6 +11,9 @@ TODO - Pop-up should be dismissable (per URL / per domain). - Once dismissed, popup should not be shown on the same url/domain. Use cookies or localStorage for this. - Since we're replacing innerHTML, we should protect against XSS attacks. + - Fix and test the options UI + - Test and fix for Chrome, Brave & Firefox + */ function showBetter(alternative) { @@ -29,8 +32,6 @@ function showBetter(alternative) { document.body.appendChild(betterdiv); } -showBetter(findBetter(document.location.href)); - chrome.runtime.sendMessage({type: 'getMatch', url: document.location.href}, (response) => { if (response) { showBetter(response); diff --git a/manifest.json b/manifest.json index 9734219..206ef30 100644 --- a/manifest.json +++ b/manifest.json @@ -14,5 +14,8 @@ } ], "manifest_version": 2, - "options_page": "options.html" + "options_ui": { + "page": "options.html", + "open_in_tab": false + } } \ No newline at end of file diff --git a/options.html b/options.html index a49a6f5..be2347c 100644 --- a/options.html +++ b/options.html @@ -30,7 +30,8 @@ button {

Choose a different source of suggestions!

- + +
diff --git a/options.js b/options.js index c15bb43..70dcf0b 100644 --- a/options.js +++ b/options.js @@ -3,6 +3,12 @@ let submit = document.getElementById('betterSourceSubmit'); submit.addEventListener('click', function() { chrome.storage.sync.set({betterSourceURL: input.value}, function() { - console.log('Set betterSource = ' + input.value); - }) + console.log('Set betterSource = ' + input.value); + }); + + chrome.runtime.sendMessage({type: 'reloadList', url: input.value}, (response) => { + if (response) { + console.log("BETTER_ALTERNATIVES list is reloaded"); + } + }); });