diff --git a/browser-plugins/webextension/manifest.json b/browser-plugins/webextension/manifest.json index 8166083..4181ef4 100644 --- a/browser-plugins/webextension/manifest.json +++ b/browser-plugins/webextension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "remwharead", - "version": "0.2.2", + "version": "0.3.0", "description": "Integrates remwharead into your Browser.", "homepage_url": "https://schlomp.space/tastytea/remwharead", @@ -23,7 +23,8 @@ "permissions": [ "activeTab", - "nativeMessaging" + "nativeMessaging", + "storage" ], "browser_action": @@ -40,6 +41,12 @@ }] }, + "options_ui": + { + "page": "options.html", + "browser_style": true + }, + "commands": { "open_popup": diff --git a/browser-plugins/webextension/options.html b/browser-plugins/webextension/options.html new file mode 100644 index 0000000..d07ede7 --- /dev/null +++ b/browser-plugins/webextension/options.html @@ -0,0 +1,14 @@ + + + + + + +
+ + +
+ + + + diff --git a/browser-plugins/webextension/options.js b/browser-plugins/webextension/options.js new file mode 100644 index 0000000..5150fa8 --- /dev/null +++ b/browser-plugins/webextension/options.js @@ -0,0 +1,20 @@ +function save_options(e) +{ + browser.storage.sync.set( + { + archive: document.querySelector("#archive").checked + }); + e.preventDefault(); +} + +function restore_options() +{ + var item = browser.storage.sync.get('archive'); + item.then((res) => + { + document.querySelector("#archive").checked = res.archive; + }); +} + +document.addEventListener('DOMContentLoaded', restore_options); +document.querySelector("#archive").addEventListener("change", save_options); diff --git a/browser-plugins/webextension/popup.js b/browser-plugins/webextension/popup.js index 0b3e704..8afc213 100644 --- a/browser-plugins/webextension/popup.js +++ b/browser-plugins/webextension/popup.js @@ -1,5 +1,5 @@ -var taburl; -var port; +var taburl = ""; +var archive = ""; function set_taburl(tabs) // Set taburl to URL of current tab. { @@ -17,6 +17,18 @@ function get_tags() // get tags from text input. return ""; } +function read_options() +{ + var item = browser.storage.sync.get('archive'); + item.then((res) => + { + if (res.archive === false) + { + archive = "--no-archive "; + } + }); +} + function onResponse(response) { console.log("Received: " + response); document.getElementById("status").textContent = ""; @@ -42,19 +54,20 @@ function launch() // Launch wrapper and send tags + URL to stdin. { document.getElementById("status").textContent = "Launching remwharead…"; document.getElementById("error").textContent = ""; - var arguments = get_tags() + taburl; + var arguments = get_tags() + archive + taburl; console.log("Sending: " + arguments + " to remwharead"); var sending = browser.runtime.sendNativeMessage("remwharead", arguments); sending.then(onResponse, onError); } +read_options(); // Call set_taburl() with current tab. browser.tabs.query({currentWindow: true, active: true}).then(set_taburl); button.addEventListener("click", launch); // Call launch() if button is clicked. -// Click button if enter is hit in text input. +// Call launch if enter is hit in text input. document.querySelector("#tags").addEventListener( "keyup", event => { @@ -62,6 +75,6 @@ document.querySelector("#tags").addEventListener( { return; } - document.querySelector("#button").click(); + launch(); event.preventDefault(); });