From e53cef75b639d25df2c09386b47800887fac57ff Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz_lightsnack_2007@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:15:35 +0800 Subject: [PATCH] updated settings --- gui/scripts/pages/settings.js | 119 +++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 52 deletions(-) diff --git a/gui/scripts/pages/settings.js b/gui/scripts/pages/settings.js index 1e17ab4..3d92f30 100644 --- a/gui/scripts/pages/settings.js +++ b/gui/scripts/pages/settings.js @@ -1,82 +1,97 @@ /* Settings.js - Build the interface for the settings + Build the interface for the settings */ // Import modules. //import { windowman } from "../windowman.js"; async function build() { - let secretariat = ( - await import(chrome.runtime.getURL("scripts/secretariat.js")) - ).secretariat; - let windowman = ( - await import(chrome.runtime.getURL("gui/scripts/windowman.js")) - ).windowman; + let secretariat = ( + await import(chrome.runtime.getURL("scripts/secretariat.js")) + ); + let windowman = ( + await import(chrome.runtime.getURL("gui/scripts/windowman.js")) + ).default; - let window = new windowman(); + let window = new windowman(); } /* - Arrange the interface. - */ + Arrange the interface. + */ /*function arrange() { - async function openLast() { - let last_opened = ( - await Promise.all([secretariat.read([`view`, window.location.href], 1)]) - )[0]; - if (!last_opened || typeof last_opened !== `number`) { - last_opened = 0; - } + async function openLast() { + let last_opened = ( + await Promise.all([secretariat.read([`view`, window.location.href], 1)]) + )[0]; + if (!last_opened || typeof last_opened !== `number`) { + last_opened = 0; + } - if (document.querySelector(`[role="tab"][tab="${last_opened}"]`)) { - document.querySelector(`[role="tab"][tab="${last_opened}"]`).click(); - } - } + if (document.querySelector(`[role="tab"][tab="${last_opened}"]`)) { + document.querySelector(`[role="tab"][tab="${last_opened}"]`).click(); + } + } - openLast(); + openLast(); } function main() { - windowman.fill(); - events(); - arrange(); + windowman.fill(); + events(); + arrange(); }*/ /* - Define the mapping of each button. - */ + Define the mapping of each button. + */ function events() { - if (document.querySelector(`[data-action="filters,update"]`)) { - document - .querySelector(`[data-action="filters,update"]`) - .addEventListener(`click`, async () => { - let filters = ( - await import(chrome.runtime.getURL(`scripts/filters.js`)) - ).default; - filters.update(); - }); - } - if (document.querySelector(`[data-action="storage,clear"]`)) { - document - .querySelector(`[data-action="storage,clear"]`) - .addEventListener(`click`, async () => { - let storage = ( - await import(chrome.runtime.getURL(`scripts/secretariat.js`)) - )["secretariat"]; - storage.forget(`sites`); - }); - } + if (document.querySelector(`[data-action="filters,update"]`)) { + document.querySelector(`[data-action="filters,update"]`).addEventListener(`click`, async () => { + let filters = new (( + await import(chrome.runtime.getURL(`scripts/filters.js`)) + ).default); + await filters.update(); + }); + } + + if (document.querySelector(`[data-action="filters,add,one"]`)) { + document.querySelector(`[data-action="filters,add,one"]`).addEventListener(`click`, async () => { + (async () => { + // Import the filters module. + let texts = (await import(chrome.runtime.getURL(`gui/scripts/read.js`))).default; + let filters = new ((await import(chrome.runtime.getURL(`scripts/filters.js`))).default); + + // Open text input window for adding a filter. + let filter_source = prompt(texts.localized(`settings_filters_add_prompt`)); + if (filter_source.trim) { + filters.update(filter_source.trim); + }; + })(); + }); + } + + if (document.querySelector(`[data-action="storage,clear"]`)) { + document + .querySelector(`[data-action="storage,clear"]`) + .addEventListener(`click`, async () => { + let storage = ( + await import(chrome.runtime.getURL(`scripts/secretariat.js`)) + )["secretariat"]; + storage.forget(`sites`); + }); + } } //main(); function load() { - document.addEventListener("DOMContentLoaded", function () { - M.AutoInit(); - }); + document.addEventListener("DOMContentLoaded", function () { + M.AutoInit(); + events(); + }); - build(); - events(); + build(); } load();