From 0ff2a26969ba6ab9f4badab5f6fd3e40f9616c30 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sun, 5 May 2024 23:00:31 +0800 Subject: [PATCH] use seperated URL cleaning module --- scripts/data/pointer.js | 9 ++------- scripts/data/product.js | 9 ++------- scripts/external/processor.js | 8 ++------ 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/scripts/data/pointer.js b/scripts/data/pointer.js index c1fb537..1d31102 100644 --- a/scripts/data/pointer.js +++ b/scripts/data/pointer.js @@ -4,20 +4,15 @@ Change the currently selected data to be viewed by the popup. */ import {global} from "/scripts/secretariat.js"; +import {URLs} from "/scripts/utils/URLs.js"; class pointer { /* Select a URL to view. */ static select(URL) { - const clean = (URL) => { - - // Remove the protocol from the URL. - return((URL.replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]); - } - 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) {} // Get the last edited site. diff --git a/scripts/data/product.js b/scripts/data/product.js index 2d01033..fd569c4 100644 --- a/scripts/data/product.js +++ b/scripts/data/product.js @@ -6,6 +6,7 @@ import {global, session, compare} from "/scripts/secretariat.js"; import hash from "/scripts/utils/hash.js"; import texts from "/scripts/mapping/read.js"; import logging from "/scripts/logging.js"; +import {URLs} from "/scripts/utils/URLs.js"; // Don't forget to set the class as export default. export default class product { @@ -24,14 +25,8 @@ export default class product { 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. - this.URL = clean(URL); + this.URL = URLs.clean(URL); this.details = details; // Set private variables. diff --git a/scripts/external/processor.js b/scripts/external/processor.js index 4d86b06..e2ca942 100644 --- a/scripts/external/processor.js +++ b/scripts/external/processor.js @@ -6,6 +6,7 @@ import scraper from "/scripts/external/scraper.js"; import product from "/scripts/data/product.js"; import {global} from "/scripts/secretariat.js"; import logging from "/scripts/logging.js"; +import {URLs} from "/scripts/utils/URLs.js"; export default class processor { #filter; @@ -42,12 +43,7 @@ export default class processor { } constructor (filter, URL = window.location.href) { - const clean = (URL) => { - // Remove the protocol from the URL. - return((URL.replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]); - } - - this.URL = clean(URL); + this.URL = URLs.clean(URL); this.#filter = filter; this.targets = this.#filter[`data`];