aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2024-05-20 15:45:42 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2024-05-20 15:45:42 -0400
commit9d7b827c914f1d0ffaef41d93b4539885399862a (patch)
tree25715201f7e00f7d8f3971ea64de4371dab68019
parent6207f3fef1363cbde4e9b886e05c97ac6439d469 (diff)
Create Firefox version
Continue to use manifest v2 for the Firefox version to avoid https://bugzil.la/1851083.
-rw-r--r--.gitignore3
-rw-r--r--build.ninja39
-rw-r--r--chrome/background.js (renamed from background.js)4
-rw-r--r--chrome/manifest.json (renamed from manifest.json)0
-rw-r--r--chrome/options.js (renamed from options.js)0
-rw-r--r--chrome/screenshot.png (renamed from screenshot.png)bin171326 -> 171326 bytes
-rw-r--r--common/options.html (renamed from options.html)0
-rw-r--r--firefox/background.js44
-rw-r--r--firefox/manifest.json33
-rw-r--r--firefox/options.js47
10 files changed, 152 insertions, 18 deletions
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/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/background.js b/chrome/background.js
index 922b57f..abe6442 100644
--- a/background.js
+++ b/chrome/background.js
@@ -15,9 +15,7 @@
const MENU_ITEM_OPEN_LINK = 'openLink';
function open(url) {
- chrome.storage.sync.get({
- clickBehavior: 'search',
- }, function(items) {
+ 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/';
diff --git a/manifest.json b/chrome/manifest.json
index fded481..fded481 100644
--- a/manifest.json
+++ b/chrome/manifest.json
diff --git a/options.js b/chrome/options.js
index b456900..b456900 100644
--- a/options.js
+++ b/chrome/options.js
diff --git a/screenshot.png b/chrome/screenshot.png
index 804544e..804544e 100644
--- a/screenshot.png
+++ b/chrome/screenshot.png
Binary files differ
diff --git a/options.html b/common/options.html
index 47042af..47042af 100644
--- a/options.html
+++ b/common/options.html
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 <bbaren@google.com>",
+ "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();
+ });
+}