diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 0000000..72004e5 --- /dev/null +++ b/assets/README.md @@ -0,0 +1,14 @@ +# Assets + +## Generating images + +- Open `icon.svg` in Inkscape +- File - Export... +- **Batch Export** tab +- Make sure all layers are checked, **Directory** is set to `.` +- Click **Export** +- To place the images in `icons` directory run: + +```sh +bash build.sh +``` diff --git a/assets/build.sh b/assets/build.sh new file mode 100644 index 0000000..3bceecc --- /dev/null +++ b/assets/build.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +main () { + cd "$(realpath $(dirname "$0"))" + + # Find ffmpeg binary + local ffmpeg_binary; + ffmpeg_binary="ffmpeg" + if command -v ffmpeg7 >/dev/null 2>&1; then + ffmpeg_binary="ffmpeg7" + elif command -v ffmpeg6 >/dev/null 2>&1; then + ffmpeg_binary="ffmpeg6" + elif command -v ffmpeg5 >/dev/null 2>&1; then + ffmpeg_binary="ffmpeg5" + fi + + # Don't want any errors for dir not existing + [ -f ../icons ] || mkdir -p ../icons + + # Create icon files + "$ffmpeg_binary" -i ./batch_Normal.png -vf scale=48:48 -y ../icons/icon-48.png + "$ffmpeg_binary" -i ./batch_Enabled.png -vf scale=19:19 -y ../icons/icon-enabled-19.png + "$ffmpeg_binary" -i ./batch_Enabled.png -vf scale=38:38 -y ../icons/icon-enabled-38.png + "$ffmpeg_binary" -i ./batch_Disabled.png -vf scale=19:19 -y ../icons/icon-disabled-19.png + "$ffmpeg_binary" -i ./batch_Disabled.png -vf scale=38:38 -y ../icons/icon-disabled-38.png + + # Strip metadata + exiftool -all= -overwrite_original ../icons/icon-*.png +} + +main diff --git a/assets/icon.svg b/assets/icon.svg new file mode 100644 index 0000000..d2b1e57 --- /dev/null +++ b/assets/icon.svg @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + https://publicdomainvectors.org/en/free-clipart/Onion-vector-symbol/69402.html + Icons for addon + + + License: Public domain + + + + + + diff --git a/icons/icon-48.png b/icons/icon-48.png new file mode 100644 index 0000000..bb10d9d Binary files /dev/null and b/icons/icon-48.png differ diff --git a/icons/icon-disabled-19.png b/icons/icon-disabled-19.png new file mode 100644 index 0000000..a695244 Binary files /dev/null and b/icons/icon-disabled-19.png differ diff --git a/icons/icon-disabled-38.png b/icons/icon-disabled-38.png new file mode 100644 index 0000000..1040721 Binary files /dev/null and b/icons/icon-disabled-38.png differ diff --git a/icons/icon-enabled-19.png b/icons/icon-enabled-19.png new file mode 100644 index 0000000..8f46e2f Binary files /dev/null and b/icons/icon-enabled-19.png differ diff --git a/icons/icon-enabled-38.png b/icons/icon-enabled-38.png new file mode 100644 index 0000000..2b099ef Binary files /dev/null and b/icons/icon-enabled-38.png differ diff --git a/index.js b/index.js index 641d97a..956681a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ 'use strict'; var browser = typeof browser !== "undefined" ? browser : chrome; +var enableRedirect = true; function validate_onion_host(hostname) { if (!hostname.endsWith("onion")) { @@ -24,6 +25,9 @@ function validate_onion_host(hostname) { } function tor_redirect(details) { + // If disabled, don't care to redirect + if (!enableRedirect) return; + var onion_location_header = details.responseHeaders.find(function (header) { return header['name'].toLowerCase() == 'onion-location'; }); @@ -82,3 +86,29 @@ browser.runtime.onMessage.addListener(function (message, sender, sendResponse) { } } }); + +// Make sure correct icon and title (toolbar button tooltip) is shown +function updateIcon() { + browser.browserAction.setIcon({ + path: enableRedirect ? { + 19: "icons/icon-enabled-19.png", + 38: "icons/icon-enabled-38.png" + } : { + 19: "icons/icon-disabled-19.png", + 38: "icons/icon-disabled-38.png" + } + }); + browser.browserAction.setTitle({ + // Screen readers can see the title + title: enableRedirect ? 'Onion Everywhere\n(Enabled - Click to toggle)' : 'Onion Everywhere\n(Disabled - Click to toggle)' + }); +} +// Show proper icon and title on load +updateIcon(); + +// On toolbar button click +browser.browserAction.onClicked.addListener(function (tab) { + // Toggle + enableRedirect = ! enableRedirect; + updateIcon(); +}); diff --git a/manifest.json b/manifest.json index f003bc8..e7b46e1 100644 --- a/manifest.json +++ b/manifest.json @@ -7,13 +7,20 @@ "browser_specific_settings": { "gecko": { "id": "parsa@yazdani.au", - "strict_min_version": "54.0" + "strict_min_version": "79.0" } }, "background": { "scripts": ["index.js"] }, "permissions": ["webRequest", "webRequestBlocking", "tabs", ""], + "browser_action": { + "default_icon": "icons/icon-48.png", + "default_title": "Onion Everywhere" + }, + "icons": { + "48": "icons/icon-48.png" + }, "content_scripts": [ { "matches": [""],