support adding multiple filters in one go

This commit is contained in:
buzz-lightsnack-2007 2024-05-12 19:59:10 +08:00
parent fb3d016b5f
commit 81da15d6a8
2 changed files with 16 additions and 7 deletions

View file

@ -5,6 +5,7 @@ Manage filters.
import {global} from "./secretariat.js"; import {global} from "./secretariat.js";
import net from "/scripts/utils/net.js"; import net from "/scripts/utils/net.js";
import texts from "/scripts/mapping/read.js"; import texts from "/scripts/mapping/read.js";
import {URLs} from "/scripts/utils/URLs.js";
import {Queue} from "/scripts/utils/common.js"; import {Queue} from "/scripts/utils/common.js";
import logging from "/scripts/logging.js" import logging from "/scripts/logging.js"
// const logging = (await import(chrome.runtime.getURL("/scripts/logging.js"))).default; // const logging = (await import(chrome.runtime.getURL("/scripts/logging.js"))).default;
@ -51,12 +52,19 @@ export default class filters {
// Create a queue of the filters. // Create a queue of the filters.
let filters = new Queue(); let filters = new Queue();
if (location) { if (location && location != `*`) {
// Check if the URL is in a valid protocol let LOCATIONS = [];
if (location.includes(`://`)) { (Array.isArray(location))
// Append that to the queue. ? location.forEach((LOCATION) => {
filters.enqueue(new URL(location)); URLs.test(LOCATION) ? LOCATIONS.push(LOCATION) : false;
} })
: (URLs.test(location)) ? LOCATIONS.push(location) : false;
(LOCATIONS.length)
? LOCATIONS.forEach((LOCATION) => {
filters.enqueue(LOCATION);
})
: false;
} else { } else {
// Add every item to the queue based on what was loaded first. // Add every item to the queue based on what was loaded first.
let FILTERS_ALL = await global.read(["settings", `filters`]); let FILTERS_ALL = await global.read(["settings", `filters`]);

View file

@ -42,7 +42,8 @@ class Page_Settings extends Page {
// Update the filter if the source is not empty. // Update the filter if the source is not empty.
if (FILTER_SOURCE ? FILTER_SOURCE.trim() : false) { if (FILTER_SOURCE ? FILTER_SOURCE.trim() : false) {
this.data.filters.update(FILTER_SOURCE.trim()); FILTER_SOURCE = FILTER_SOURCE.trim().split(`, `);
this.data.filters.update(FILTER_SOURCE);
}; };
}) })
: false; : false;