diff --git a/.gitignore b/.gitignore index af84b01..55194c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules src/content-script.js +src/popup.js dist diff --git a/package-lock.json b/package-lock.json index 51e37c8..e52a2ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "english-verbs-helper": "3.3.1", "english-verbs-irregular": "3.3.1", "rollup": "^4.27.3", - "web-ext": "^8.3.0" + "web-ext": "^8.3.0", + "webextension-polyfill": "^0.12.0" } }, "node_modules/@babel/code-frame": { @@ -5277,6 +5278,13 @@ "npm": ">=8.0.0" } }, + "node_modules/webextension-polyfill": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/webextension-polyfill/-/webextension-polyfill-0.12.0.tgz", + "integrity": "sha512-97TBmpoWJEE+3nFBQ4VocyCdLKfw54rFaJ6EVQYLBCXqCIpLSZkwGgASpv4oPt9gdKCJ80RJlcmNzNn008Ag6Q==", + "dev": true, + "license": "MPL-2.0" + }, "node_modules/when": { "version": "3.7.7", "resolved": "https://registry.npmjs.org/when/-/when-3.7.7.tgz", diff --git a/package.json b/package.json index 000bdb8..03f73b4 100644 --- a/package.json +++ b/package.json @@ -12,16 +12,17 @@ "license": "GPL-3.0-or-later", "scripts": { "test": "npx rollup -c && npx web-ext run -s src", - "build": "npx rollup -c && npx web-ext build -s src -a dist --ignore-files replace-words.js -o" + "build": "npx rollup -c && npx web-ext build -s src -a dist --ignore-files replace-words.js save-load-options.js icons/metamorpov.svg icons/svg-to-png.sh -o" }, "devDependencies": { "@rollup/plugin-commonjs": "28.0.2", + "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "15.3.0", "english-verbs-gerunds": "3.3.1", "english-verbs-helper": "3.3.1", "english-verbs-irregular": "3.3.1", "rollup": "^4.27.3", "web-ext": "^8.3.0", - "@rollup/plugin-json": "^6.1.0" + "webextension-polyfill": "^0.12.0" } } diff --git a/rollup.config.js b/rollup.config.js index b255b22..008a17d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,12 +2,24 @@ import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; -export default { - input: 'src/replace-words.js', - output: { - file: 'src/content-script.js', - format: 'iife', - name: 'contentScript' +export default [ + { + input: 'src/save-load-options.js', + output: { + file: 'src/popup.js', + format: 'iife', + name: 'popup' + }, + plugins: [resolve(), commonjs(), json()] }, - plugins: [resolve(), commonjs(), json()] -}; + + { + input: 'src/replace-words.js', + output: { + file: 'src/content-script.js', + format: 'iife', + name: 'contentScript' + }, + plugins: [resolve(), commonjs(), json()] + } +]; diff --git a/src/icons/128x.png b/src/icons/128x.png new file mode 100644 index 0000000..d31e6a4 Binary files /dev/null and b/src/icons/128x.png differ diff --git a/src/icons/16x.png b/src/icons/16x.png new file mode 100644 index 0000000..b605dc8 Binary files /dev/null and b/src/icons/16x.png differ diff --git a/src/icons/32x.png b/src/icons/32x.png new file mode 100644 index 0000000..b358673 Binary files /dev/null and b/src/icons/32x.png differ diff --git a/src/icons/48x.png b/src/icons/48x.png new file mode 100644 index 0000000..9c15ada Binary files /dev/null and b/src/icons/48x.png differ diff --git a/src/icons/64x.png b/src/icons/64x.png new file mode 100644 index 0000000..946add9 Binary files /dev/null and b/src/icons/64x.png differ diff --git a/src/icons/96x.png b/src/icons/96x.png new file mode 100644 index 0000000..34cefea Binary files /dev/null and b/src/icons/96x.png differ diff --git a/src/metamorpov.svg b/src/icons/metamorpov.svg similarity index 100% rename from src/metamorpov.svg rename to src/icons/metamorpov.svg diff --git a/src/icons/svg-to-png.sh b/src/icons/svg-to-png.sh new file mode 100755 index 0000000..dda839b --- /dev/null +++ b/src/icons/svg-to-png.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p inkscape +# Uses Inkscape to generate .png files from the provided input + +inkscape -o 16x.png -w 16 $1 +inkscape -o 32x.png -w 32 $1 +inkscape -o 48x.png -w 48 $1 +inkscape -o 64x.png -w 64 $1 +inkscape -o 96x.png -w 96 $1 +inkscape -o 128x.png -w 128 $1 diff --git a/src/manifest.json b/src/manifest.json index 3ff5641..7a586af 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -17,12 +17,12 @@ "action": { "default_title": "MetamorPOV", "default_icon": { - "16": "metamorpov.svg", - "32": "metamorpov.svg", - "48": "metamorpov.svg", - "64": "metamorpov.svg", - "96": "metamorpov.svg", - "128": "metamorpov.svg" + "16": "icons/16x.png", + "32": "icons/32x.png", + "48": "icons/48x.png", + "64": "icons/64x.png", + "96": "icons/96x.png", + "128": "icons/128x.png" }, "default_popup": "popup.html" }, @@ -38,12 +38,12 @@ ], "icons": { - "16": "metamorpov.svg", - "32": "metamorpov.svg", - "48": "metamorpov.svg", - "64": "metamorpov.svg", - "96": "metamorpov.svg", - "128": "metamorpov.svg" + "16": "icons/16x.png", + "32": "icons/32x.png", + "48": "icons/48x.png", + "64": "icons/64x.png", + "96": "icons/96x.png", + "128": "icons/128x.png" }, "content_scripts": [ @@ -58,9 +58,5 @@ } ], - "background": { - "page": "popup.html" - }, - "homepage_url": "https://git.viscogliosi-pate.com/jean/metamorpov" } diff --git a/src/replace-words.js b/src/replace-words.js index c76233e..90ed64a 100644 --- a/src/replace-words.js +++ b/src/replace-words.js @@ -1,3 +1,4 @@ +var browser = require("webextension-polyfill"); const verbsHelper = require("english-verbs-helper"); const verbsIrregular = require("english-verbs-irregular/dist/verbs.json"); const verbsGerunds = require("english-verbs-gerunds/dist/gerunds.json"); @@ -5,7 +6,8 @@ const verbsData = verbsHelper.mergeVerbsData(verbsIrregular, verbsGerunds); /* Replaces verbs, point-of-view, name, pronouns, and "also" terms */ function replaceAll() { - browser.storage.local.get(null, (options) => { + let options = browser.storage.local.get(); + options.then((options) => { const hostname = window.location.hostname; const isEnabled = !(options.domains === undefined) && options.domains.includes(hostname); if (!isEnabled) { return; } diff --git a/src/popup.js b/src/save-load-options.js similarity index 97% rename from src/popup.js rename to src/save-load-options.js index 9be1280..e9bb07c 100644 --- a/src/popup.js +++ b/src/save-load-options.js @@ -1,3 +1,5 @@ +var browser = require("webextension-polyfill"); + document.addEventListener("DOMContentLoaded", init); function init() { @@ -14,14 +16,15 @@ function init() { function loadDomain() { let tabs = browser.tabs.query({ active: true, currentWindow: true }); tabs.then((tabs) => { - const hostname = new URL(tabs[0].url).hostname; - document.querySelector("#domain").textContent = hostname; + const url = new URL(tabs[0].url); + const isAllowedProtocol = url.protocol == "https:" || url.protocol == "http:"; - if (!hostname) { + if (!isAllowedProtocol) { disableToggle(); return; } + document.querySelector("#domain").textContent = url.hostname; let storage = browser.storage.local.get("domains"); storage.then((storage) => { const hostname = document.querySelector("#domain").innerHTML;