From 9d7b827c914f1d0ffaef41d93b4539885399862a Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Mon, 20 May 2024 15:45:42 -0400 Subject: Create Firefox version Continue to use manifest v2 for the Firefox version to avoid https://bugzil.la/1851083. --- .gitignore | 3 +-- background.js | 58 -------------------------------------------------- build.ninja | 39 ++++++++++++++++++++++----------- chrome/background.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ chrome/manifest.json | 28 ++++++++++++++++++++++++ chrome/options.js | 47 ++++++++++++++++++++++++++++++++++++++++ chrome/screenshot.png | Bin 0 -> 171326 bytes common/options.html | 21 ++++++++++++++++++ firefox/background.js | 44 ++++++++++++++++++++++++++++++++++++++ firefox/manifest.json | 33 ++++++++++++++++++++++++++++ firefox/options.js | 47 ++++++++++++++++++++++++++++++++++++++++ manifest.json | 28 ------------------------ options.html | 21 ------------------ options.js | 47 ---------------------------------------- screenshot.png | Bin 171326 -> 0 bytes 15 files changed, 303 insertions(+), 169 deletions(-) delete mode 100644 background.js create mode 100644 chrome/background.js create mode 100644 chrome/manifest.json create mode 100644 chrome/options.js create mode 100644 chrome/screenshot.png create mode 100644 common/options.html create mode 100644 firefox/background.js create mode 100644 firefox/manifest.json create mode 100644 firefox/options.js delete mode 100644 manifest.json delete mode 100644 options.html delete mode 100644 options.js delete mode 100644 screenshot.png diff --git a/.gitignore b/.gitignore index e93caca..04cda5a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,7 @@ .ninja_* # Generated files -wayback_machine_button -icon_bordered.png +build *.zip diff --git a/background.js b/background.js deleted file mode 100644 index 922b57f..0000000 --- a/background.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2017 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -const MENU_ITEM_OPEN_LINK = 'openLink'; - -function open(url) { - chrome.storage.sync.get({ - clickBehavior: 'search', - }, function(items) { - let waybackStem = 'https://web.archive.org/web/*/'; - if (items.clickBehavior == 'direct') { - waybackStem = 'https://web.archive.org/web/'; - } - chrome.tabs.update(null, {url: waybackStem + url}); - }); -} - -chrome.action.onClicked.addListener(function(tab) { - open(tab.url); -}); - -chrome.contextMenus.onClicked.addListener(function(info, tab) { - if (info.menuItemId == MENU_ITEM_OPEN_LINK) { - open(info.linkUrl); - } -}); - -chrome.runtime.onInstalled.addListener(function() { - chrome.declarativeContent.onPageChanged.removeRules(null, function() { - chrome.declarativeContent.onPageChanged.addRules([ - { - conditions: [ - new chrome.declarativeContent.PageStateMatcher( - {pageUrl: {schemes: ['ftp', 'http', 'https']}}), - ], - actions: [new chrome.declarativeContent.ShowPageAction()], - }, - ]); - }); - - chrome.contextMenus.create({ - 'id': MENU_ITEM_OPEN_LINK, - 'title': 'Open link in the Wayback Machine', - 'contexts': ['link'], - 'targetUrlPatterns': ['ftp://*/*', 'http://*/*', 'https://*/*'], - }); -}); diff --git a/build.ninja b/build.ninja index 1857870..c090032 100644 --- a/build.ninja +++ b/build.ninja @@ -15,6 +15,10 @@ name = wayback_machine_button +rule cp + command = cp $in $out + description = Saving $out + rule generate_png command = inkscape -w $width -h $width -o $out $in && optipng -o7 $out description = Generating $out @@ -32,22 +36,31 @@ rule minify_json description = Minifying $in rule zip - command = zip -qr $out $in + command = zip -jqr $out $in description = Zipping $out -build $name/background.js: minify_js background.js -build $name/manifest.json: minify_json manifest.json -build $name/options.html: minify_html options.html -build $name/options.js: minify_js options.js -build $name/icon128.png: generate_png third_party/icon.svg +build build/chrome/$name/background.js: minify_js chrome/background.js +build build/chrome/$name/manifest.json: minify_json chrome/manifest.json +build build/chrome/$name/options.html: minify_html common/options.html +build build/chrome/$name/options.js: minify_js chrome/options.js +build build/chrome/$name/icon128.png: generate_png third_party/icon.svg width = 128 -build $name/icon48.png: generate_png third_party/icon.svg +build build/chrome/$name/icon48.png: generate_png third_party/icon.svg width = 48 -build $name/icon16.png: generate_png third_party/icon.svg +build build/chrome/$name/icon16.png: generate_png third_party/icon.svg width = 16 -build icon_bordered.png: generate_png third_party/icon_bordered.svg - width = 128 -build $name.zip: zip $name/background.js $name/manifest.json $ - $name/options.html $name/options.js $name/icon128.png $name/icon48.png $ - $name/icon16.png +build build/chrome/$name.zip: zip build/chrome/$name/background.js $ + build/chrome/$name/manifest.json build/chrome/$name/options.html $ + build/chrome/$name/options.js build/chrome/$name/icon128.png $ + build/chrome/$name/icon48.png build/chrome/$name/icon16.png + +build build/firefox/$name/background.js: cp firefox/background.js +build build/firefox/$name/manifest.json: cp firefox/manifest.json +build build/firefox/$name/options.html: cp common/options.html +build build/firefox/$name/options.js: cp firefox/options.js +build build/firefox/$name/icon.svg: cp third_party/icon.svg + +build build/firefox/$name.zip: zip build/firefox/$name/background.js $ + build/firefox/$name/manifest.json build/firefox/$name/options.html $ + build/firefox/$name/options.js build/firefox/$name/icon.svg diff --git a/chrome/background.js b/chrome/background.js new file mode 100644 index 0000000..abe6442 --- /dev/null +++ b/chrome/background.js @@ -0,0 +1,56 @@ +// Copyright 2017 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +const MENU_ITEM_OPEN_LINK = 'openLink'; + +function open(url) { + chrome.storage.sync.get({clickBehavior: 'search'}, function(items) { + let waybackStem = 'https://web.archive.org/web/*/'; + if (items.clickBehavior == 'direct') { + waybackStem = 'https://web.archive.org/web/'; + } + chrome.tabs.update(null, {url: waybackStem + url}); + }); +} + +chrome.action.onClicked.addListener(function(tab) { + open(tab.url); +}); + +chrome.contextMenus.onClicked.addListener(function(info, tab) { + if (info.menuItemId == MENU_ITEM_OPEN_LINK) { + open(info.linkUrl); + } +}); + +chrome.runtime.onInstalled.addListener(function() { + chrome.declarativeContent.onPageChanged.removeRules(null, function() { + chrome.declarativeContent.onPageChanged.addRules([ + { + conditions: [ + new chrome.declarativeContent.PageStateMatcher( + {pageUrl: {schemes: ['ftp', 'http', 'https']}}), + ], + actions: [new chrome.declarativeContent.ShowPageAction()], + }, + ]); + }); + + chrome.contextMenus.create({ + 'id': MENU_ITEM_OPEN_LINK, + 'title': 'Open link in the Wayback Machine', + 'contexts': ['link'], + 'targetUrlPatterns': ['ftp://*/*', 'http://*/*', 'https://*/*'], + }); +}); diff --git a/chrome/manifest.json b/chrome/manifest.json new file mode 100644 index 0000000..fded481 --- /dev/null +++ b/chrome/manifest.json @@ -0,0 +1,28 @@ +{ + "manifest_version": 3, + "name": "Wayback Machine Lookup", + "version": "2.0.0", + "description": "Reopen the current tab in the Wayback Machine", + "icons": { + "16": "icon16.png", + "48": "icon48.png", + "128": "icon128.png" + }, + "action": { + "default_title": "Reopen the current tab in the Wayback Machine" + }, + "author": "Benjamin Barenblat ", + "background": { + "service_worker": "background.js" + }, + "minimum_chrome_version": "88", + "options_ui": { + "page": "options.html" + }, + "permissions": [ + "activeTab", + "contextMenus", + "declarativeContent", + "storage" + ] +} diff --git a/chrome/options.js b/chrome/options.js new file mode 100644 index 0000000..b456900 --- /dev/null +++ b/chrome/options.js @@ -0,0 +1,47 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +const DEFAULT_OPTIONS = { + clickBehavior: 'search', +}; + +document.addEventListener('DOMContentLoaded', function() { + chrome.storage.sync.get(DEFAULT_OPTIONS, function(items) { + for (let button of document.forms.clickBehavior) { + if (button.value == items.clickBehavior) { + button.checked = true; + break; + } + } + }); +}); + +function saveOptions() { + let clickBehavior = DEFAULT_OPTIONS.clickBehavior; + for (let button of document.forms.clickBehavior) { + if (button.checked) { + clickBehavior = button.value; + break; + } + } + chrome.storage.sync.set({ + clickBehavior: clickBehavior, + }); +} + +for (let button of document.forms.clickBehavior) { + button.addEventListener('change', function(event) { + saveOptions(); + }); +} diff --git a/chrome/screenshot.png b/chrome/screenshot.png new file mode 100644 index 0000000..804544e Binary files /dev/null and b/chrome/screenshot.png differ diff --git a/common/options.html b/common/options.html new file mode 100644 index 0000000..47042af --- /dev/null +++ b/common/options.html @@ -0,0 +1,21 @@ + + +Wayback Machine Lookup +
+ When searching the Wayback Machine:
+
+ +
+ diff --git a/firefox/background.js b/firefox/background.js new file mode 100644 index 0000000..30c82d9 --- /dev/null +++ b/firefox/background.js @@ -0,0 +1,44 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +const MENU_ITEM_OPEN_LINK = 'openLink'; + +function open(url) { + browser.storage.sync.get({clickBehavior: 'search'}).then(function(items) { + let waybackStem = 'https://web.archive.org/web/*/'; + if (items.clickBehavior == 'direct') { + waybackStem = 'https://web.archive.org/web/'; + } + browser.tabs.update(null, {url: waybackStem + url}); + }); +} + +browser.pageAction.onClicked.addListener(function(tab) { + open(tab.url); +}); + +browser.contextMenus.onClicked.addListener(function(info, tab) { + if (info.menuItemId == MENU_ITEM_OPEN_LINK) { + open(info.linkUrl); + } +}); + +browser.runtime.onInstalled.addListener(function() { + browser.contextMenus.create({ + 'id': MENU_ITEM_OPEN_LINK, + 'title': 'Open link in the Wayback Machine', + 'contexts': ['link'], + 'targetUrlPatterns': ['ftp://*/*', 'http://*/*', 'https://*/*'], + }); +}); diff --git a/firefox/manifest.json b/firefox/manifest.json new file mode 100644 index 0000000..e6fa3c4 --- /dev/null +++ b/firefox/manifest.json @@ -0,0 +1,33 @@ +{ + "manifest_version": 2, + "name": "Wayback Machine Lookup", + "version": "2.0.0", + "description": "Reopen the current tab in the Wayback Machine", + "icons": { + "48": "icon.svg", + "96": "icon.svg" + }, + "page_action": { + "default_icon": "icon.svg", + "default_title": "Open in the Wayback Machine", + "show_matches": ["ftp://*/*", "http://*/*", "https://*/*"] + }, + "author": "Benjamin Barenblat ", + "background": { + "scripts": ["background.js"] + }, + "browser_specific_settings": { + "gecko": { + "id": "{fbd65aac-1f67-49ca-93fd-77de0bbf9bea}", + "strict_min_version": "59.0" + } + }, + "options_ui": { + "page": "options.html" + }, + "permissions": [ + "activeTab", + "contextMenus", + "storage" + ] +} diff --git a/firefox/options.js b/firefox/options.js new file mode 100644 index 0000000..d80cbbb --- /dev/null +++ b/firefox/options.js @@ -0,0 +1,47 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +const DEFAULT_OPTIONS = { + clickBehavior: 'search', +}; + +document.addEventListener('DOMContentLoaded', function() { + browser.storage.sync.get(DEFAULT_OPTIONS).then(function(items) { + for (let button of document.forms.clickBehavior) { + if (button.value == items.clickBehavior) { + button.checked = true; + break; + } + } + }); +}); + +function saveOptions() { + let clickBehavior = DEFAULT_OPTIONS.clickBehavior; + for (let button of document.forms.clickBehavior) { + if (button.checked) { + clickBehavior = button.value; + break; + } + } + browser.storage.sync.set({ + clickBehavior: clickBehavior, + }); +} + +for (let button of document.forms.clickBehavior) { + button.addEventListener('change', function(event) { + saveOptions(); + }); +} diff --git a/manifest.json b/manifest.json deleted file mode 100644 index fded481..0000000 --- a/manifest.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "manifest_version": 3, - "name": "Wayback Machine Lookup", - "version": "2.0.0", - "description": "Reopen the current tab in the Wayback Machine", - "icons": { - "16": "icon16.png", - "48": "icon48.png", - "128": "icon128.png" - }, - "action": { - "default_title": "Reopen the current tab in the Wayback Machine" - }, - "author": "Benjamin Barenblat ", - "background": { - "service_worker": "background.js" - }, - "minimum_chrome_version": "88", - "options_ui": { - "page": "options.html" - }, - "permissions": [ - "activeTab", - "contextMenus", - "declarativeContent", - "storage" - ] -} diff --git a/options.html b/options.html deleted file mode 100644 index 47042af..0000000 --- a/options.html +++ /dev/null @@ -1,21 +0,0 @@ - - -Wayback Machine Lookup -
- When searching the Wayback Machine:
-
- -
- diff --git a/options.js b/options.js deleted file mode 100644 index b456900..0000000 --- a/options.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -const DEFAULT_OPTIONS = { - clickBehavior: 'search', -}; - -document.addEventListener('DOMContentLoaded', function() { - chrome.storage.sync.get(DEFAULT_OPTIONS, function(items) { - for (let button of document.forms.clickBehavior) { - if (button.value == items.clickBehavior) { - button.checked = true; - break; - } - } - }); -}); - -function saveOptions() { - let clickBehavior = DEFAULT_OPTIONS.clickBehavior; - for (let button of document.forms.clickBehavior) { - if (button.checked) { - clickBehavior = button.value; - break; - } - } - chrome.storage.sync.set({ - clickBehavior: clickBehavior, - }); -} - -for (let button of document.forms.clickBehavior) { - button.addEventListener('change', function(event) { - saveOptions(); - }); -} diff --git a/screenshot.png b/screenshot.png deleted file mode 100644 index 804544e..0000000 Binary files a/screenshot.png and /dev/null differ -- cgit v1.2.3