Files
tab-park/options.js
T
2026-11-11 20:24:24 +01:00

36 lines
1.1 KiB
JavaScript

// Tab Park - preferences. The only thing here is the keyboard shortcuts,
// which live in Firefox's own shortcuts page. This page shows what is bound
// right now and opens that page.
const $ = id => document.getElementById(id);
function tuKeys(shortcut) {
const fragment = document.createDocumentFragment();
if (!shortcut) {
fragment.append('Not set');
return fragment;
}
shortcut.split('+').forEach((key, index) => {
if (index) fragment.append('+');
const kbd = document.createElement('kbd');
kbd.textContent = key;
fragment.append(kbd);
});
return fragment;
}
async function tuLoadShortcuts() {
const commands = await browser.commands.getAll();
const byName = Object.fromEntries(commands.map(command => [command.name, command.shortcut]));
$('shortcut-current').replaceChildren(tuKeys(byName['unload-current']));
$('shortcut-all').replaceChildren(tuKeys(byName['unload-others']));
}
$('shortcuts').addEventListener('click', () => {
browser.commands.openShortcutSettings();
});
browser.commands.onChanged.addListener(tuLoadShortcuts);
tuLoadShortcuts();