From 57f32a269a06ec5102b08824d251afa5456d4195 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 13 May 2021 09:27:56 +0200 Subject: only allow a single injection payload for page, rely on script bags for complex payloads --- TODOS.org | 5 + background/main.js | 10 +- background/page_actions_server.js | 3 +- background/reverse_use_info.js | 6 + html/options.html | 68 +++++---- html/options_main.js | 288 +++++++++++++++++++++++++++----------- 6 files changed, 266 insertions(+), 114 deletions(-) diff --git a/TODOS.org b/TODOS.org index 0abef25..c06616a 100644 --- a/TODOS.org +++ b/TODOS.org @@ -1,5 +1,7 @@ TODO: - parallelize fetching of remote scripts +- allow specifying whether a script occurring mutiple times directly + or indirectly in a bag should be included multiple times or once - make it possible to provide backup urls for remote scripts - make it possible to cache remote scripts - make it possible to use wildcards or something similar to be able to assign a script set to -- CRUCIAL @@ -17,6 +19,7 @@ TODO: settings and settings for pages that currently happen to live in iframes - add some nice styling to settings page +- make script bag components re-orderable (via drag&drop in options page) -- CRUCIAL - find some way not to require each chrome user to modify manifest.json - rename the extension to something good - port to gecko-based browsers -- CRUCIAL @@ -37,8 +40,10 @@ TODO: - rearrange files in extension, add some mechanism to build the extension - all solutions to modularize js code SUCK; come up with own simple DSL to manage imports/exports +- perform never-ending refactoring of already-written code DONE: +- only allow a single injection payload for page -- DONE 2021-05-13 - rename "bundles" to "bags" to avoid confusion with Web Bundles -- DONE 2021-05-12 - use non-predictable value in place of "myext-allow", utilizing hashes -- DONE 2021-05-12 - stop using modules (not available on all browsers) -- DONE 2021-05-12 diff --git a/background/main.js b/background/main.js index 6b636c4..6656284 100644 --- a/background/main.js +++ b/background/main.js @@ -110,7 +110,11 @@ components.push([TYPE_PREFIX.SCRIPT, name]); } - await storage.set(TYPE_PREFIX.PAGE, "https://my.fsf.org/join", {components}); + await storage.set(TYPE_PREFIX.BAG, "myfsf_join", components); + + await storage.set(TYPE_PREFIX.PAGE, "https://my.fsf.org/join", { + components: [TYPE_PREFIX.BAG, "myfsf_join"] + }); let hello_script = { text: "console.log(\"hello, every1!\");\n" @@ -119,7 +123,7 @@ await storage.set(TYPE_PREFIX.BAG, "hello", [[TYPE_PREFIX.SCRIPT, "hello"]]); await storage.set(TYPE_PREFIX.PAGE, "https://my.fsf.org/", { - components: [[TYPE_PREFIX.BAG, "hello"]], + components: [TYPE_PREFIX.BAG, "hello"], allow: true }); @@ -157,7 +161,7 @@ for (let prop of data.props.pageProps.list) { await storage.set(TYPE_PREFIX.SCRIPT, "opencores", opencores_script); await storage.set(TYPE_PREFIX.PAGE, "https://opencores.org/projects", { - components: [[TYPE_PREFIX.SCRIPT, "opencores"]], + components: [TYPE_PREFIX.SCRIPT, "opencores"], allow: false }); } diff --git a/background/page_actions_server.js b/background/page_actions_server.js index 2a0b858..2dfcf9a 100644 --- a/background/page_actions_server.js +++ b/background/page_actions_server.js @@ -31,7 +31,8 @@ let components = settings.components; let processed_bags = new Set(); - send_scripts_rec(components, port, processed_bags); + if (components !== undefined) + send_scripts_rec([components], port, processed_bags); } // TODO: parallelize script fetching diff --git a/background/reverse_use_info.js b/background/reverse_use_info.js index 688cd64..c51d06b 100644 --- a/background/reverse_use_info.js +++ b/background/reverse_use_info.js @@ -10,6 +10,12 @@ "use strict"; +/* + * Warning! + * This script file has not been used for some time and underlying storage + * model has changed since then! Fix required! + */ + /* * We want to count referenes to scripts and bags in order to know, * for example, whether one can be safely deleted. diff --git a/html/options.html b/html/options.html index cb39090..ac6c736 100644 --- a/html/options.html +++ b/html/options.html @@ -4,8 +4,7 @@ Myext options