improve import method
This commit is contained in:
parent
16e57f45fc
commit
be0f4334f7
1 changed files with 35 additions and 37 deletions
|
@ -3,13 +3,15 @@
|
|||
*/
|
||||
|
||||
// Import modules.
|
||||
//import { windowman } from "../windowman.js";
|
||||
|
||||
import {global} from "/scripts/secretariat.js";
|
||||
import Page from "/scripts/pages/page.js";
|
||||
import texts from "/scripts/mapping/read.js";
|
||||
import filters from "/scripts/filters.js";
|
||||
import logging from "/scripts/logging.js";
|
||||
|
||||
class Page_Settings extends Page {
|
||||
data = {};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
(this.events) ? this.events() : false;
|
||||
|
@ -37,51 +39,47 @@ class Page_Settings extends Page {
|
|||
.querySelector(`[data-action="filters,add,one"]`)
|
||||
.addEventListener(`click`, async () => {
|
||||
// Import the filters module.
|
||||
let filters = new (
|
||||
await import(chrome.runtime.getURL(`scripts/filters.js`))
|
||||
).default();
|
||||
|
||||
let filter_source = prompt(
|
||||
texts.localized(`settings_filters_add_prompt`),
|
||||
);
|
||||
if (filter_source ? filter_source.trim() : false) {
|
||||
filters.update(filter_source.trim());
|
||||
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
||||
|
||||
// Update all of the filters.
|
||||
filters.update(`*`);
|
||||
})
|
||||
: false;
|
||||
|
||||
(document.querySelector(`[data-action="filters,add,one"]`))
|
||||
? document.querySelector(`[data-action="filters,add,one"]`).addEventListener(`click`, async () => {
|
||||
// Import the filters module.
|
||||
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
||||
// Request for the filter URL.
|
||||
let FILTER_SOURCE = prompt(texts.localized(`settings_filters_add_prompt`));
|
||||
|
||||
// Update the filter if the source is not empty.
|
||||
if (FILTER_SOURCE ? FILTER_SOURCE.trim() : false) {
|
||||
this.data.filters.update(FILTER_SOURCE.trim());
|
||||
};
|
||||
});
|
||||
}
|
||||
if (document.querySelector(`[data-action="filters,update,one"]`)) {
|
||||
document
|
||||
.querySelector(`[data-action="filters,update,one"]`)
|
||||
.addEventListener(`click`, async () => {
|
||||
// Import the filters module.
|
||||
const texts = (
|
||||
await import(chrome.runtime.getURL(`/scripts/mapping/read.js`))
|
||||
).default;
|
||||
let filters = new (
|
||||
await import(chrome.runtime.getURL(`scripts/filters.js`))
|
||||
).default();
|
||||
})
|
||||
: false;
|
||||
|
||||
(document.querySelector(`[data-action="filters,update,one"]`))
|
||||
? document.querySelector(`[data-action="filters,update,one"]`).addEventListener(`click`, async () => {
|
||||
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
||||
|
||||
// Open text input window for adding a filter.
|
||||
let filter_source = (document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`)) ? document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`).innerText : prompt(texts.localized(`settings_filters_add_prompt`));
|
||||
if (filter_source ? filter_source.trim() : false) {
|
||||
filters.update(filter_source.trim());
|
||||
this.data.filters.update(filter_source.trim());
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
: false;
|
||||
|
||||
if (document.querySelector(`[data-action="filters,delete,one"]`)) {
|
||||
document
|
||||
.querySelector(`[data-action="filters,delete,one"]`)
|
||||
.addEventListener(`click`, async () => {
|
||||
// Import the filters module.
|
||||
let filters = new (
|
||||
await import(chrome.runtime.getURL(`scripts/filters.js`))
|
||||
).default();
|
||||
document.querySelector(`[data-action="filters,delete,one"]`).addEventListener(`click`, async () => {
|
||||
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
||||
|
||||
// Open text input window for adding a filter.
|
||||
let filter_source = (document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`)) ? document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`).innerText : prompt(texts.localized(`settings_filters_remove_prompt`));
|
||||
if (filter_source ? filter_source.trim() : false) {
|
||||
filters.remove(filter_source.trim());
|
||||
this.data.filters.remove(filter_source.trim());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -101,8 +99,8 @@ class Page_Settings extends Page {
|
|||
? document.querySelector(`[data-action="storage,clear"]`).addEventListener(`click`, async () => {
|
||||
await global.forget(`sites`);
|
||||
console.log(await global.read(null, 1), await global.read(null, -1));
|
||||
});
|
||||
}
|
||||
})
|
||||
: false;
|
||||
|
||||
(document.querySelectorAll(`[data-action]`)).forEach((ELEMENT) => {
|
||||
ELEMENT.removeAttribute(`data-action`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue