From 32dc67db284b5803c9925df07f2cc47127acfdf6 Mon Sep 17 00:00:00 2001 From: Kace Cottam Date: Sun, 26 May 2024 16:44:58 -0700 Subject: [PATCH] Add Page Action (icon in URL bar) with setting to enable --- src/_locales/en/messages.json | 3 +++ src/manifest.json | 11 +++++++++++ src/pages/background/background.js | 7 +++++++ src/pages/options/widgets/general.js | 6 ++++++ src/pages/options/widgets/general.pug | 4 ++++ 5 files changed, 31 insertions(+) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 251bbebe..a4cb6278 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -93,6 +93,9 @@ "message": "Redirect to original", "description": "Used in context menus when right clicking on a page/tab" }, + "pageAction": { + "message": "Show in Page Action" + }, "redirectLink": { "message": "Attempt to redirect", "description": "Used in context menus when right clicking on a hyperlink" diff --git a/src/manifest.json b/src/manifest.json index 0cacd75f..bb19e39a 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -44,6 +44,17 @@ "128": "assets/images/libredirect-128.png" } }, + "page_action": { + "default_title": "__MSG_extensionName__", + "browser_style": false, + "default_popup": "pages/popup/popup.html", + "default_icon": { + "16": "assets/images/libredirect-16.png", + "32": "assets/images/libredirect-32.png", + "48": "assets/images/libredirect-48.png", + "128": "assets/images/libredirect-128.png" + } + }, "options_ui": { "page": "pages/options/index.html", "browser_style": false, diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 0c4d0923..c4772396 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -28,6 +28,13 @@ browser.runtime.onInstalled.addListener(async details => { let tabIdRedirects = {} +// page action +browser.tabs.onUpdated.addListener(async (id, changeInfo, tabInfo) => { + const { pageAction } = await utils.getOptions() + if (!pageAction) return; + browser.pageAction.show(tabInfo.id); +}); + // true == Always redirect, false == Never redirect, null/undefined == follow options for services browser.webRequest.onBeforeRequest.addListener( details => { diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index 30a8a0c8..3e2a87b8 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -121,6 +121,11 @@ bookmarksMenuElement.addEventListener('change', async event => { browser.permissions.remove({ permissions: ["bookmarks"] }, r => bookmarksMenuElement.checked = !r) }) +const pageActionElement = document.getElementById('pageAction') +pageActionElement.addEventListener('change', event => { + setOption('pageAction', 'checkbox', event) +}) + let themeElement = document.getElementById("theme") themeElement.addEventListener("change", event => { setOption("theme", "select", event) @@ -149,6 +154,7 @@ let options = await utils.getOptions() themeElement.value = options.theme fetchInstancesElement.value = options.fetchInstances redirectOnlyInIncognitoElement.checked = options.redirectOnlyInIncognito +pageActionElement.checked = options.pageAction browser.permissions.contains({ permissions: ["bookmarks"] }, r => bookmarksMenuElement.checked = r) for (const service in config.services) document.getElementById(service).checked = options.popupServices.includes(service) diff --git a/src/pages/options/widgets/general.pug b/src/pages/options/widgets/general.pug index 1388584a..ba649975 100644 --- a/src/pages/options/widgets/general.pug +++ b/src/pages/options/widgets/general.pug @@ -25,6 +25,10 @@ section(class="block-option" id="general_page") label(for='bookmarksMenu' data-localise="__MSG_bookmarksMenu__") Bookmarks menu input(id='bookmarksMenu' type="checkbox") + div(class="block block-option") + label(for='pageAction' data-localise="__MSG_pageAction__") Use Page Action + input(id='pageAction' type="checkbox") + div(class="block block-option") label(data-localise="__MSG_excludeFromRedirecting__") Excluded from redirecting