remwharead/browser-plugins/webextension/options.js
tastytea 81d4a7f396
All checks were successful
continuous-integration/drone/push Build is passing
webextension: Added browser to list of globals.
2019-06-15 02:48:38 +02:00

46 lines
1.2 KiB
JavaScript

/* 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;
}
});
}
function info_commands(commands)
{
commands.forEach(
function(command)
{
const element = document.querySelector("#shortcuts");
const para = document.createElement("p");
const text = document.createElement("strong");
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);
const get_commands = browser.commands.getAll();
get_commands.then(info_commands);