use updated search interface data to perform actions
This commit is contained in:
parent
e25dad36f9
commit
d3520d1c54
1 changed files with 74 additions and 69 deletions
|
@ -8,14 +8,15 @@ import Page from "/scripts/pages/page.js";
|
||||||
import texts from "/scripts/mapping/read.js";
|
import texts from "/scripts/mapping/read.js";
|
||||||
import filters from "/scripts/filters.js";
|
import filters from "/scripts/filters.js";
|
||||||
import logging from "/scripts/logging.js";
|
import logging from "/scripts/logging.js";
|
||||||
|
import {URLs} from "/scripts/utils/URLs.js";
|
||||||
|
|
||||||
class Page_Settings extends Page {
|
class Page_Settings extends Page {
|
||||||
data = {};
|
data = {};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
(this.events) ? this.events() : false;
|
this.events();
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Define the mapping of each button.
|
Define the mapping of each button.
|
||||||
|
@ -23,77 +24,81 @@ class Page_Settings extends Page {
|
||||||
@param {object} window the window
|
@param {object} window the window
|
||||||
*/
|
*/
|
||||||
events() {
|
events() {
|
||||||
(document.querySelector(`[data-action="filters,update"]`))
|
if ((Object.keys(this.window.elements[`interactive`][`action`])).length) {
|
||||||
? document.querySelector(`[data-action="filters,update"]`).addEventListener(`click`, async () => {
|
// Instantiate the filters module, since it's needed for some of the actions below.
|
||||||
// Import the filters module.
|
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
||||||
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
|
||||||
|
|
||||||
// Update all of the filters.
|
|
||||||
this.data.filters.update(`*`);
|
// Set the actions.
|
||||||
})
|
let ACTIONS = {};
|
||||||
: false;
|
ACTIONS[`filters,update`] = async () => {this.data.filters.update(`*`);};
|
||||||
|
ACTIONS[`filters,add,one`] = () => {
|
||||||
(document.querySelector(`[data-action="filters,add,one"]`))
|
let SOURCE = ``;
|
||||||
? 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.
|
while (true) {
|
||||||
if (FILTER_SOURCE ? FILTER_SOURCE.trim() : false) {
|
SOURCE = prompt(texts.localized(`settings_filters_add_prompt`), SOURCE);
|
||||||
FILTER_SOURCE = FILTER_SOURCE.trim().split(`, `);
|
|
||||||
this.data.filters.update(FILTER_SOURCE);
|
// Update the filter if the source is not empty.
|
||||||
};
|
if (SOURCE ? SOURCE.trim() : false) {
|
||||||
})
|
SOURCE = SOURCE.trim().split(`, `);
|
||||||
: false;
|
|
||||||
|
// Verify user inputs are valid.
|
||||||
(document.querySelector(`[data-action="filters,update,one"]`))
|
let VALID = true;
|
||||||
? document.querySelector(`[data-action="filters,update,one"]`).addEventListener(`click`, async () => {
|
|
||||||
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
// Check if the URL is valid.
|
||||||
|
SOURCE.forEach((LOCATION) => {
|
||||||
// Open text input window for adding a filter.
|
VALID = (URLs.test(LOCATION));
|
||||||
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) {
|
|
||||||
this.data.filters.update(filter_source.trim());
|
// Update the filter if the source is valid.
|
||||||
|
if (VALID) {
|
||||||
|
return(this.data.filters.update(SOURCE));
|
||||||
|
} else {
|
||||||
|
if (!confirm(texts.localized(`error_msg_notURL_syntax`))) {
|
||||||
|
return (false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return (false);
|
||||||
};
|
};
|
||||||
})
|
}
|
||||||
: false;
|
};
|
||||||
|
ACTIONS[`filters,update,one`] = () => {
|
||||||
if (document.querySelector(`[data-action="filters,delete,one"]`)) {
|
// Update the selected filter.
|
||||||
document.querySelector(`[data-action="filters,delete,one"]`).addEventListener(`click`, async () => {
|
return((this.window.search.filters.selected) ? this.data.filters.update(this.window.search.filters.selected) : false)
|
||||||
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
|
};
|
||||||
|
ACTIONS[`filters,delete,one`] = () => {
|
||||||
// Open text input window for adding a filter.
|
// Remove the selected 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`));
|
return((this.window.search.filters.selected) ? this.data.filters.remove(this.window.search.filters.selected) : false)
|
||||||
if (filter_source ? filter_source.trim() : false) {
|
}
|
||||||
this.data.filters.remove(filter_source.trim());
|
ACTIONS[`storage,clear`] = () => {
|
||||||
}
|
return(global.forget(`sites`));
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
// Add the event listeners.
|
||||||
// The extension icon cache doesn't clear by itself.
|
(Object.keys(ACTIONS)).forEach((NAME) => {
|
||||||
(document.querySelector(`[data-store="settings,general,showApplicable"]`))
|
(this.window.elements[`interactive`][`action`][NAME] ? this.window.elements[`interactive`][`action`][NAME].length : false)
|
||||||
? document.querySelectorAll(`[data-store="settings,general,showApplicable"]`).forEach((ELEMENT) => {
|
? this.window.elements[`interactive`][`action`][NAME].forEach((ELEMENT) => {
|
||||||
ELEMENT.addEventListener(`change`, () => {
|
ELEMENT.addEventListener(`click`, ACTIONS[NAME]);
|
||||||
!(ELEMENT.checked)
|
})
|
||||||
? new logging(texts.localized(`settings_restartToApply`), texts.localized(`settings_restartToApply_iconChange`), true)
|
: false;
|
||||||
: false;
|
|
||||||
})
|
|
||||||
})
|
|
||||||
: false;
|
|
||||||
|
|
||||||
(document.querySelector(`[data-action="storage,clear"]`))
|
|
||||||
? document.querySelector(`[data-action="storage,clear"]`).addEventListener(`click`, async () => {
|
|
||||||
await global.forget(`sites`);
|
|
||||||
})
|
|
||||||
: false;
|
|
||||||
|
|
||||||
(document.querySelectorAll(`[data-action]`))
|
|
||||||
? (document.querySelectorAll(`[data-action]`)).forEach((ELEMENT) => {
|
|
||||||
ELEMENT.removeAttribute(`data-action`);
|
|
||||||
})
|
})
|
||||||
: false;
|
};
|
||||||
|
|
||||||
|
if (this.window.elements[`linked`] ? (this.window.elements[`linked`][`show`] ? Object.keys(this.window.elements[`linked`][`show`]).length : false) : false) {
|
||||||
|
(this.window.elements[`linked`][`show`][`settings,general,showApplicable`] ? this.window.elements[`linked`][`show`][`settings,general,showApplicable`].length : false)
|
||||||
|
? (this.window.elements[`linked`][`show`][`settings,general,showApplicable`]).forEach((ELEMENT) => {
|
||||||
|
ELEMENT.addEventListener(`change`, () => {
|
||||||
|
// The extension icon cache doesn't clear by itself.
|
||||||
|
ELEMENT.addEventListener(`change`, () => {
|
||||||
|
!(ELEMENT.checked)
|
||||||
|
? new logging(texts.localized(`settings_restartToApply`), texts.localized(`settings_restartToApply_iconChange`), true)
|
||||||
|
: false;
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})
|
||||||
|
: false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue