Skip to content

Commit

Permalink
Always open search by image in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
bijij committed Jul 26, 2023
1 parent 4cb6763 commit cf88fba
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 88 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
2 changes: 2 additions & 0 deletions html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
28 changes: 0 additions & 28 deletions js/background.blink.js

This file was deleted.

38 changes: 0 additions & 38 deletions js/background.gecko.js

This file was deleted.

32 changes: 24 additions & 8 deletions js/background.base.js → js/background.js
Original file line number Diff line number Diff line change
@@ -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) : '';
});
Expand All @@ -11,25 +13,28 @@ 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
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')) {

Check failure on line 32 in js/background.js

View workflow job for this annotation

GitHub Actions / build

Do not access Object.prototype method 'hasOwnProperty' from target object

Check failure on line 32 in js/background.js

View workflow job for this annotation

GitHub Actions / build

Do not access Object.prototype method 'hasOwnProperty' from target object
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(
Expand All @@ -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)}`,
});
}
});
16 changes: 8 additions & 8 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions manifest.base.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -17,7 +17,6 @@
"default_popup": "html/popup.html"
},
"permissions": [
"activeTab",
"contextMenus",
"storage"
],
Expand Down
2 changes: 1 addition & 1 deletion manifest.blink.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"background": {
"service_worker": "js/background.blink.js",
"service_worker": "js/background.js",
"type": "module"
}
}
2 changes: 1 addition & 1 deletion manifest.gecko.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"background": {
"scripts": [
"js/background.gecko.js"
"js/background.js"
],
"type": "module"
}
Expand Down

0 comments on commit cf88fba

Please sign in to comment.