use seperated URL cleaning module

This commit is contained in:
buzz-lightsnack-2007 2024-05-05 23:00:31 +08:00
parent 42cea844a8
commit 0ff2a26969
3 changed files with 6 additions and 20 deletions

View file

@ -4,20 +4,15 @@ Change the currently selected data to be viewed by the popup.
*/ */
import {global} from "/scripts/secretariat.js"; import {global} from "/scripts/secretariat.js";
import {URLs} from "/scripts/utils/URLs.js";
class pointer { class pointer {
/* /*
Select a URL to view. Select a URL to view.
*/ */
static select(URL) { static select(URL) {
const clean = (URL) => {
// Remove the protocol from the URL.
return((URL.replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]);
}
try { try {
URL = (!URL) ? window.location.href : ((URL && (typeof URL).includes(`str`)) ? clean(URL) : null); URL = (!URL) ? window.location.href : ((URL && (typeof URL).includes(`str`)) ? URLs.clean(URL) : null);
} catch(err) {} } catch(err) {}
// Get the last edited site. // Get the last edited site.

View file

@ -6,6 +6,7 @@ import {global, session, compare} from "/scripts/secretariat.js";
import hash from "/scripts/utils/hash.js"; import hash from "/scripts/utils/hash.js";
import texts from "/scripts/mapping/read.js"; import texts from "/scripts/mapping/read.js";
import logging from "/scripts/logging.js"; import logging from "/scripts/logging.js";
import {URLs} from "/scripts/utils/URLs.js";
// Don't forget to set the class as export default. // Don't forget to set the class as export default.
export default class product { export default class product {
@ -24,14 +25,8 @@ export default class product {
options = {}; options = {};
} }
/* Remove uneeded data or formatting from the URL and the data. */
let clean = (URL) => {
// Remove the protocol from the URL.
return((URL.replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]);
}
// Set this product's details as part of the object's properties. // Set this product's details as part of the object's properties.
this.URL = clean(URL); this.URL = URLs.clean(URL);
this.details = details; this.details = details;
// Set private variables. // Set private variables.

View file

@ -6,6 +6,7 @@ import scraper from "/scripts/external/scraper.js";
import product from "/scripts/data/product.js"; import product from "/scripts/data/product.js";
import {global} from "/scripts/secretariat.js"; import {global} from "/scripts/secretariat.js";
import logging from "/scripts/logging.js"; import logging from "/scripts/logging.js";
import {URLs} from "/scripts/utils/URLs.js";
export default class processor { export default class processor {
#filter; #filter;
@ -42,12 +43,7 @@ export default class processor {
} }
constructor (filter, URL = window.location.href) { constructor (filter, URL = window.location.href) {
const clean = (URL) => { this.URL = URLs.clean(URL);
// Remove the protocol from the URL.
return((URL.replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]);
}
this.URL = clean(URL);
this.#filter = filter; this.#filter = filter;
this.targets = this.#filter[`data`]; this.targets = this.#filter[`data`];