remwharead/browser-plugins/webextension/options.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

/* globals browser */
function save_options(e)
{
browser.storage.sync.set(
{
archive: document.querySelector("#archive").checked
});
e.preventDefault();
}
function restore_options()
{
const item = browser.storage.sync.get('archive');
item.then((res) =>
{
if (res.archive === false)
{
document.querySelector("#archive").checked = false;
}
});
}
2019-05-24 13:43:15 +02:00
function info_commands(commands)
{
commands.forEach(
function(command)
{
const element = document.querySelector("#shortcuts");
const para = document.createElement("p");
2019-05-24 13:43:15 +02:00
const text = document.createElement("strong");
2019-05-24 13:43:15 +02:00
text.appendChild(document.createTextNode(command.shortcut + ": "));
para.appendChild(text);
para.appendChild(document.createTextNode(command.description));
element.appendChild(para);
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.querySelector("#archive").addEventListener("change", save_options);
2019-05-24 13:43:15 +02:00
const get_commands = browser.commands.getAll();
2019-05-24 13:43:15 +02:00
get_commands.then(info_commands);