diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cbd8472..2c8a868 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -35,6 +35,7 @@ jobs: CLIENT_SECRET: ${{ secrets.MOZ_DEPLOY_JWT_SECRET }} run: | jq -s '.[0] * .[1]' manifest.base.json manifest.gecko.json > manifest.json + git add manifest.json git archive -o package.zip HEAD VERSION_NUMBER=$(jq -r .version manifest.json) ACCESS_TOKEN=$(npx jwtgen -a HS256 -s ${CLIENT_SECRET} -c "iss=${CLIENT_ID}" -e 300) @@ -48,8 +49,8 @@ jobs: REFRESH_TOKEN: ${{ secrets.CHROME_DEPLOY_REFRESH_TOKEN }} run: | jq -s '.[0] * .[1]' manifest.base.json manifest.blink.json > manifest.json - STASH_NAME=$(git stash create) - git archive -o package.zip ${STASH_NAME} + git add manifest.json + git archive -o package.zip HEAD ACCESS_TOKEN=$(curl "https://accounts.google.com/o/oauth2/token" -d "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&refresh_token=${REFRESH_TOKEN}&grant_type=refresh_token&redirect_uri=urn:ietf:wg:oauth:2.0:oob" | jq -r .access_token) curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -X PUT -T package.zip "https://www.googleapis.com/upload/chromewebstore/v1.1/items/${APP_ID}" curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -H "Content-Length: 0" -X POST "https://www.googleapis.com/chromewebstore/v1.1/items/${APP_ID}/publish" diff --git a/html/options.html b/html/options.html index ac9cf33..38ee03f 100644 --- a/html/options.html +++ b/html/options.html @@ -33,11 +33,13 @@ <label for="context-menu-search-by-image"></label> </div> + <!-- Depercated for now. <div class="toggle" id="context-menu-search-by-image-new-tab-toggle"> <span data-localise="__MSG_settingsToggle_contextMenu_searchByImageNewTab__">Open "Search by Image" context menu item results in a new tab:</span> <input type="checkbox" id="context-menu-search-by-image-new-tab" /> <label for="context-menu-search-by-image-new-tab"></label> </div> + --> <!-- Depercated for now. <div class="toggle"> diff --git a/js/background.blink.js b/js/background.blink.js deleted file mode 100644 index c102f47..0000000 --- a/js/background.blink.js +++ /dev/null @@ -1,28 +0,0 @@ -'use-strict'; - -import setupContextMenu from './background.base.js'; - -const DEBUG = false; - -chrome.runtime.onInstalled.addListener(setupContextMenu); - -chrome.contextMenus.onClicked.addListener((info, tab) => { - if (DEBUG) - console.log('ViewImage: Search By Image context menu item clicked.', info, tab); - - if (info.menuItemId === 'ViewImage-SearchByImage') { - chrome.storage.sync.get(['options', 'defaultOptions'], function (storage) { - const options = Object.assign(storage.defaultOptions, storage.options); - - if (options['context-menu-search-by-image-new-tab']) { - chrome.tabs.executeScript(tab.id, { - code: `window.open('https://lens.google.com/uploadbyurl?url=${encodeURIComponent(info.srcUrl)}', '_blank').focus();` - }); - } else { - chrome.tabs.executeScript(tab.id, { - code: `window.location.href = 'https://lens.google.com/uploadbyurl?url=${encodeURIComponent(info.srcUrl)}';` - }); - } - }); - } -}); diff --git a/js/background.gecko.js b/js/background.gecko.js deleted file mode 100644 index 87061f5..0000000 --- a/js/background.gecko.js +++ /dev/null @@ -1,38 +0,0 @@ -'use-strict'; - -import setupContextMenu from './background.base.js'; - -const DEBUG = false; - -setupContextMenu(); - -chrome.contextMenus.onClicked.addListener( - (info, tab) => { - - if (DEBUG) - console.log('ViewImage: Search By Image context menu item clicked.', info, tab); - - if (info.menuItemId === 'ViewImage-SearchByImage') { - chrome.permissions.request({ - permissions: ['tabs'], - origins: [tab.url], - }, (granted) => { - if (granted) { - chrome.storage.sync.get(['options', 'defaultOptions'], function (storage) { - const options = Object.assign(storage.defaultOptions, storage.options); - - if (options['context-menu-search-by-image-new-tab']) { - chrome.tabs.executeScript(tab.id, { - code: `window.open('https://lens.google.com/uploadbyurl?url=${encodeURIComponent(info.srcUrl)}', '_blank').focus();` - }); - } else { - chrome.tabs.executeScript(tab.id, { - code: `window.location.href = 'https://lens.google.com/uploadbyurl?url=${encodeURIComponent(info.srcUrl)}';` - }); - } - }); - } - }); - } - } -); diff --git a/js/background.base.js b/js/background.js similarity index 58% rename from js/background.base.js rename to js/background.js index c5dfac6..6274eea 100644 --- a/js/background.base.js +++ b/js/background.js @@ -1,6 +1,8 @@ 'use-strict'; -export function toI18n(str) { +const DEBUG = false; + +function toI18n(str) { return str.replace(/__MSG_(\w+)__/g, function (match, v1) { return v1 ? chrome.i18n.getMessage(v1) : ''; }); @@ -11,13 +13,13 @@ const defaultOptions = { 'open-in-new-tab': true, 'open-search-by-in-new-tab': true, 'show-globe-icon': true, - 'hide-images-subject-to-copyright': false, + //'hide-images-subject-to-copyright': false, 'manually-set-button-text': false, 'no-referrer': false, 'button-text-view-image': '', 'button-text-search-by-image': '', 'context-menu-search-by-image': true, - 'context-menu-search-by-image-new-tab': false, + //'context-menu-search-by-image-new-tab': false, }; // Save default options to storage @@ -25,11 +27,14 @@ chrome.storage.sync.get('defaultOptions', function () { chrome.storage.sync.set({ defaultOptions }); }); +chrome.runtime.onInstalled.addListener(() => { + chrome.storage.sync.get(['options', 'defaultOptions'], (storage) => { + if (!storage.hasOwnProperty('options')) { + storage.options = {}; + } -export default function setupContextMenu() { - chrome.storage.sync.get(['options', 'defaultOptions'], function (storage) { const options = Object.assign(storage.defaultOptions, storage.options); - + // Setup "Search by image" context menu item if (options['context-menu-search-by-image']) { chrome.contextMenus.create( @@ -40,5 +45,16 @@ export default function setupContextMenu() { } ); } - }); -} + }); +}); + +chrome.contextMenus.onClicked.addListener((info, tab) => { + if (DEBUG) + console.log('ViewImage: Search By Image context menu item clicked.', info, tab); + + if (info.menuItemId === 'ViewImage-SearchByImage') { + chrome.tabs.create({ + url: `https://lens.google.com/uploadbyurl?url=${encodeURIComponent(info.srcUrl)}`, + }); + } +}); diff --git a/js/options.js b/js/options.js index f93f6ba..45679da 100644 --- a/js/options.js +++ b/js/options.js @@ -30,14 +30,14 @@ const save = function (object) { // Update visibility of page elements; const update_page = function () { - var showContextMenuToggle = document.getElementById('context-menu-search-by-image'); - var openNewTabToggle = document.getElementById('context-menu-search-by-image-new-tab-toggle'); - - if (showContextMenuToggle.checked) { - openNewTabToggle.classList.remove('disabled'); - } else { - openNewTabToggle.classList.add('disabled'); - } + // var showContextMenuToggle = document.getElementById('context-menu-search-by-image'); + // var openNewTabToggle = document.getElementById('context-menu-search-by-image-new-tab-toggle'); + + // if (showContextMenuToggle.checked) { + // openNewTabToggle.classList.remove('disabled'); + // } else { + // openNewTabToggle.classList.add('disabled'); + // } var manualButtonToggle = document.getElementById('manually-set-button-text'); var manualButtonText = document.getElementById('manual-toggle'); diff --git a/manifest.base.json b/manifest.base.json index 2e00240..193791c 100644 --- a/manifest.base.json +++ b/manifest.base.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "__MSG_appName__", - "version": "4.0.0", + "version": "4.1.0", "description": "__MSG_appDesc__", "default_locale": "en", "icons": { @@ -17,7 +17,6 @@ "default_popup": "html/popup.html" }, "permissions": [ - "activeTab", "contextMenus", "storage" ], diff --git a/manifest.blink.json b/manifest.blink.json index 6b8c485..af94840 100644 --- a/manifest.blink.json +++ b/manifest.blink.json @@ -1,6 +1,6 @@ { "background": { - "service_worker": "js/background.blink.js", + "service_worker": "js/background.js", "type": "module" } } diff --git a/manifest.gecko.json b/manifest.gecko.json index 29f29f6..27f1c53 100644 --- a/manifest.gecko.json +++ b/manifest.gecko.json @@ -6,7 +6,7 @@ }, "background": { "scripts": [ - "js/background.gecko.js" + "js/background.js" ], "type": "module" }