WebExtension: Added option to toggle archiving.

This commit is contained in:
tastytea 2019-05-24 13:05:40 +02:00
parent 052f67f372
commit cd5a4ecf31
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 61 additions and 7 deletions

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "remwharead", "name": "remwharead",
"version": "0.2.2", "version": "0.3.0",
"description": "Integrates remwharead into your Browser.", "description": "Integrates remwharead into your Browser.",
"homepage_url": "https://schlomp.space/tastytea/remwharead", "homepage_url": "https://schlomp.space/tastytea/remwharead",
@ -23,7 +23,8 @@
"permissions": "permissions":
[ [
"activeTab", "activeTab",
"nativeMessaging" "nativeMessaging",
"storage"
], ],
"browser_action": "browser_action":
@ -40,6 +41,12 @@
}] }]
}, },
"options_ui":
{
"page": "options.html",
"browser_style": true
},
"commands": "commands":
{ {
"open_popup": "open_popup":

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<form>
<label for="archive">Use archive.org to archive URIs:</label>
<input type="checkbox" id="archive" value="archive" checked/>
</form>
<script src="options.js"></script>
</body>
</html>

View File

@ -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);

View File

@ -1,5 +1,5 @@
var taburl; var taburl = "";
var port; var archive = "";
function set_taburl(tabs) // Set taburl to URL of current tab. function set_taburl(tabs) // Set taburl to URL of current tab.
{ {
@ -17,6 +17,18 @@ function get_tags() // get tags from text input.
return ""; return "";
} }
function read_options()
{
var item = browser.storage.sync.get('archive');
item.then((res) =>
{
if (res.archive === false)
{
archive = "--no-archive ";
}
});
}
function onResponse(response) { function onResponse(response) {
console.log("Received: " + response); console.log("Received: " + response);
document.getElementById("status").textContent = ""; 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("status").textContent = "Launching remwharead…";
document.getElementById("error").textContent = ""; document.getElementById("error").textContent = "";
var arguments = get_tags() + taburl; var arguments = get_tags() + archive + taburl;
console.log("Sending: " + arguments + " to remwharead"); console.log("Sending: " + arguments + " to remwharead");
var sending = browser.runtime.sendNativeMessage("remwharead", arguments); var sending = browser.runtime.sendNativeMessage("remwharead", arguments);
sending.then(onResponse, onError); sending.then(onResponse, onError);
} }
read_options();
// Call set_taburl() with current tab. // Call set_taburl() with current tab.
browser.tabs.query({currentWindow: true, active: true}).then(set_taburl); browser.tabs.query({currentWindow: true, active: true}).then(set_taburl);
button.addEventListener("click", launch); // Call launch() if button is clicked. 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( document.querySelector("#tags").addEventListener(
"keyup", event => "keyup", event =>
{ {
@ -62,6 +75,6 @@ document.querySelector("#tags").addEventListener(
{ {
return; return;
} }
document.querySelector("#button").click(); launch();
event.preventDefault(); event.preventDefault();
}); });