From 18ce95698a4c3c409b73dded15dfdc8008367ab2 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Tue, 19 Mar 2024 09:45:27 +0800 Subject: [PATCH] updated code --- gui/scripts/compat.js | 57 ++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/gui/scripts/compat.js b/gui/scripts/compat.js index 36b34b9..16048b6 100644 --- a/gui/scripts/compat.js +++ b/gui/scripts/compat.js @@ -1,26 +1,37 @@ -/* compat.js -You shouldn't be opening the HTMLs elsewhere. */ +/* compat.js +You shouldn't be opening the HTMLs elsewhere. */ - let browser_data = {}; -export function refresh() { - /* Update variable containing the browser data. - - Returns: (dict) the updated browser data */ - browser_data['URL'] = window.location.href; - return (browser_data['URL']); -}; +// Import modules. +import texts from "./read.JS"; -export function restrict() { - /* Restrict pages containing this function from being loaded outside the extension. +// Initialize browser data. +let browser_data = {}; - Returns: (bool) page open is correct */ - - refresh(); - const browser_extension_URL_contents = new RegExp(`^(?!file:\/\/|http:\/\/|https:\/\/)(.*-extension:\/\/.*)`); - const browser_condition_met = browser_extension_URL_contents.test(browser_data.URL); - if (!browser_condition_met) { - alert("This page can not be opened. \r此网页无法打开。"); - }; - console.log(browser_data.URL); - return (browser_condition_met); -}; +function refresh() { + /* Update variable containing the browser data. + + Returns: (dict) the updated browser data + */ + + browser_data.URL = window.location.href; + return (browser_data.URL); +} + +export default class compat { + static restrict() { + /* Restrict pages containing this function from being loaded outside the extension. + + Returns: (bool) page open is correct + */ + + refresh(); + + const browser_extension_URL_contents = new RegExp(`^(?!file:\/\/|http:\/\/|https:\/\/)(.*-extension:\/\/.*)`); + const browser_condition_met = browser_extension_URL_contents.test(browser_data.URL); + if (!browser_condition_met) { + alert(texts.universal(`invalid_open`)); + } + + return (browser_condition_met); + } +}