56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import { actions, downloads } from '/js/api.js'
|
|
|
|
export async function enable() {
|
|
const actions_container = document.getElementById('actions');
|
|
const tab2 = document.querySelector("input[type=radio]#tab-2");
|
|
console.log(tab2);
|
|
actions_container.innerHTML = "";
|
|
|
|
|
|
async function get_current_tab_url() {
|
|
return (await browser.tabs.query({ currentWindow: true, active: true }))[0].url
|
|
}
|
|
|
|
const groups = {};
|
|
|
|
function get_group(name) {
|
|
if (!name) name = "Ungrouped";
|
|
if (name in groups) return groups[name];
|
|
const fieldset = document.createElement('fieldset');
|
|
// fieldset.style.background = get_color();
|
|
const legend = document.createElement('legend');
|
|
legend.innerText = name;
|
|
fieldset.className = "actionset";
|
|
|
|
fieldset.appendChild(legend);
|
|
actions_container.appendChild(fieldset);
|
|
|
|
groups[name] = fieldset;
|
|
return groups[name];
|
|
}
|
|
|
|
for (const preset of await actions.get_all()) {
|
|
const button = document.createElement('button');
|
|
const fieldset = get_group(preset.folder);
|
|
fieldset.appendChild(button);
|
|
|
|
button.innerText = preset.name;
|
|
button.addEventListener('click', async function() {
|
|
const tab_url = await get_current_tab_url()
|
|
console.log(tab_url, preset.id);
|
|
downloads.create(tab_url, preset.id);
|
|
tab2.checked = true;
|
|
});
|
|
}
|
|
|
|
const hr = document.createElement('hr');
|
|
actions_container.appendChild(hr);
|
|
|
|
const reload_button = document.createElement('button');
|
|
reload_button.innerText = "Reload";
|
|
reload_button.addEventListener('click', enable);
|
|
actions_container.appendChild(reload_button);
|
|
|
|
|
|
}
|