commit 78100fff69dbf9dd1fff1349630cb4f2756cc663 Author: OverPoweredDev Date: Fri Jun 18 17:01:06 2021 +0530 fixed problems in enabling/disabling hover-on realised I was loading a different localStorage in the contentScripts diff --git a/src/background/background.js b/src/background/background.js index 918eed0..ef36291 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -2,6 +2,12 @@ window.browser = (function () { return window.browser || window.chrome; })(); +browser.runtime.onMessage.addListener(function(request, sender, sendResponse) { + if (request.method == "getEnabledList") + sendResponse({list: getEnabledWebsiteList()}); + else + sendResponse({}); // snub them. +}); browser.runtime.onInstalled.addListener(function () { browser.contextMenus.create({ diff --git a/src/background/storage.js b/src/background/storage.js index f1c1a46..b764129 100644 --- a/src/background/storage.js +++ b/src/background/storage.js @@ -233,22 +233,37 @@ function getEnabledWebsiteList(){ return settings.enabledWebsites; } -function saveEnabledWebsiteList(newList) { +function saveEnabledWebsiteList(settings, newList) { if(newList === null) { return; } - let settings = getGlobalSettings(); settings.enabledWebsites = newList; - saveGlobalSettings(); + saveGlobalSettings(settings); } -function removeFromEnabledWebsiteList(url){ +function removeFromEnabledWebsiteList(settings, url){ + let list = getEnabledWebsiteList(); + + if(list.includes(url)) { + let index = list.indexOf(url); + if (index !== -1) { + list.splice(index, 1); + } + } + saveEnabledWebsiteList(settings, list); } -function addToEnabledWebsiteList(url) { +// Note: url must only include the hostname +function addToEnabledWebsiteList(settings, url) { + let list = getEnabledWebsiteList(); + + if(!list.includes(url)) { + list.push(url); + } + saveEnabledWebsiteList(list); } diff --git a/src/content/content.js b/src/content/content.js index 6486c14..4195732 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -1,6 +1,13 @@ -enabledList = getEnabledWebsiteList(); +let enabledList; -if(enabledList.includes(window.location.hostname)) { - addHoverTag(); +chrome.runtime.sendMessage({method: "getEnabledList"}, function (response) { + enabledList = response.list; + addHoverElements(); +}); + +function addHoverElements() { + if (enabledList.includes(window.location.hostname)) { + addHoverTag(); + } } diff --git a/src/popup/options.js b/src/popup/options.js index e179291..ac60b1a 100644 --- a/src/popup/options.js +++ b/src/popup/options.js @@ -21,7 +21,10 @@ $(".enabled-language").on('click', function () { // TODO: delete a website from the hover list $(".delete-website").on('click', function () { + let hostname = $(this).attr("data-url"); + removeFromEnabledWebsiteList(globalSettings, hostname); + updateEnabledTable($("#enabled-website-tbody")); }); function init() { @@ -39,7 +42,7 @@ function updateEnabledTable(parent) { parent.empty(); let rowIter = 1; list.forEach((websiteURL) => { - parent.append("" + rowIter + "" + websiteURL + "trash icon"); + parent.append("" + rowIter + "" + websiteURL + "trash icon"); rowIter++; }); } diff --git a/src/settings/settings.js b/src/settings/settings.js index 3ab1296..a199862 100644 --- a/src/settings/settings.js +++ b/src/settings/settings.js @@ -42,7 +42,12 @@ $("#source-select").on('click', async function () { }); // TODO: hover-enabled table +$(".delete-website").on('click', function () { + let hostname = $(this).attr("data-url"); + removeFromEnabledWebsiteList(globalSettings, hostname); + updateEnabledTable($("#enabled-website-tbody")); +}); function init() { globalSettings = getGlobalSettings(); @@ -114,7 +119,7 @@ function updateEnabledTable(parent) { parent.empty(); let rowIter = 1; list.forEach((websiteURL) => { - parent.append("" + rowIter + "" + websiteURL + "trash icon"); + parent.append("" + rowIter + "" + websiteURL + "trash icon"); rowIter++; }); } \ No newline at end of file