make it possible to enabled/disable multiple extensions

This commit is contained in:
dragonwocky 2020-08-15 22:44:31 +10:00
parent 3c14f1e85d
commit 94830b5da5

View File

@ -373,7 +373,8 @@ window['__start'] = async () => {
? 1 ? 1
: a.name.localeCompare(b.name) : a.name.localeCompare(b.name)
)) { )) {
const menuStore = store('mods', { [mod.id]: { enabled: false } }), const enabled = store('mods', { [mod.id]: { enabled: false } })[mod.id]
.enabled,
author = author =
typeof mod.author === 'object' typeof mod.author === 'object'
? mod.author ? mod.author
@ -384,9 +385,7 @@ window['__start'] = async () => {
}; };
mod.elem = createElement(` mod.elem = createElement(`
<section class="${ <section class="${
mod.tags.includes('core') || menuStore[mod.id].enabled mod.tags.includes('core') || enabled ? 'enabled' : 'disabled'
? 'enabled'
: 'disabled'
}" id="${mod.id}"> }" id="${mod.id}">
<div class="meta"> <div class="meta">
<h3 ${ <h3 ${
@ -394,7 +393,7 @@ window['__start'] = async () => {
? `>${mod.name}` ? `>${mod.name}`
: `class="toggle"> : `class="toggle">
<input type="checkbox" id="enable_${mod.id}" <input type="checkbox" id="enable_${mod.id}"
${menuStore[mod.id].enabled ? 'checked' : ''} /> ${enabled ? 'checked' : ''} />
<label for="enable_${mod.id}"> <label for="enable_${mod.id}">
<span class="name">${mod.name}</span> <span class="name">${mod.name}</span>
<span class="switch"><span class="dot"></span></span> <span class="switch"><span class="dot"></span></span>
@ -420,8 +419,13 @@ window['__start'] = async () => {
const $enable = mod.elem.querySelector(`#enable_${mod.id}`); const $enable = mod.elem.querySelector(`#enable_${mod.id}`);
if ($enable) if ($enable)
$enable.addEventListener('click', (event) => { $enable.addEventListener('click', (event) => {
menuStore[mod.id].enabled = $enable.checked; store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled =
mod.elem.className = menuStore[mod.id].enabled ? 'enabled' : 'disabled'; $enable.checked;
mod.elem.className = store('mods', { [mod.id]: { enabled: false } })[
mod.id
].enabled
? 'enabled'
: 'disabled';
search(); search();
modified(); modified();
}); });