commit b7474d2451519c23912d1601e2b650ef1e9c9b6b Author: OverPoweredDev Date: Mon Jun 21 16:48:25 2021 +0530 can finally add websites to the hover-on list diff --git a/src/background/background.js b/src/background/background.js index ef36291..a730d2d 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -3,18 +3,24 @@ window.browser = (function () { })(); browser.runtime.onMessage.addListener(function(request, sender, sendResponse) { - if (request.method == "getEnabledList") + if (request.method === "getEnabledList") { sendResponse({list: getEnabledWebsiteList()}); - else + } else { sendResponse({}); // snub them. + } }); browser.runtime.onInstalled.addListener(function () { browser.contextMenus.create({ "id": "enableTranslation", - "title": "Enable Hover-On Translation", + "title": "Toggle Hover-On Translation", "documentUrlPatterns": [""], - "contexts": ["page"] + "contexts": ["page"], }); }); +chrome.contextMenus.onClicked.addListener(function (info, tab) { + if (info.menuItemId === "enableTranslation") { + addToEnabledWebsiteList(getGlobalSettings(), tab.url); + } +}); \ No newline at end of file diff --git a/src/background/storage.js b/src/background/storage.js index b764129..71397a5 100644 --- a/src/background/storage.js +++ b/src/background/storage.js @@ -255,15 +255,15 @@ function removeFromEnabledWebsiteList(settings, url){ saveEnabledWebsiteList(settings, list); } -// Note: url must only include the hostname function addToEnabledWebsiteList(settings, url) { + let hostname = new URL(url).hostname; let list = getEnabledWebsiteList(); - if(!list.includes(url)) { - list.push(url); + if(!list.includes(hostname)) { + list.push(hostname); } - saveEnabledWebsiteList(list); + saveEnabledWebsiteList(settings, list); } diff --git a/src/content/hover.js b/src/content/hover.js index a26d4e8..628fdfe 100644 --- a/src/content/hover.js +++ b/src/content/hover.js @@ -10,7 +10,7 @@ function addHoverTag() { // bind to each hover $('hover').hover( - function() { $('#word').text($(this).css('background-color','#ffff66').text()); }, + function() { $('#word').text($(this).css({"background-color":"#b4b4b4", "transition-delay":".5s"}).text()); }, function() { $('#word').text(''); $(this).css('background-color',''); } ); } \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index 2cf7222..3e3910b 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -46,6 +46,7 @@ ], "permissions": [ "tabs", - "contextMenus" + "contextMenus", + "activeTab" ] } \ No newline at end of file