@@ -167,55 +167,16 @@ export function checkBlackWhiteList(script, url) {
167167 return willRun ;
168168}
169169
170- // Source: https://github.com/fregante/webext-patterns/blob/main/index.ts
171170function matchPatterns ( url , patterns ) {
172- const patternValidationRegex =
173- / ^ ( h t t p s ? | w s s ? | f i l e | f t p | \* ) : \/ \/ ( \* | \* \. [ ^ * / ] + | [ ^ * / ] + ) \/ .* $ | ^ f i l e : \/ \/ \/ .* $ | ^ r e s o u r c e : \/ \/ ( \* | \* \. [ ^ * / ] + | [ ^ * / ] + ) \/ .* $ | ^ a b o u t : / ;
174- const isFirefox =
175- typeof navigator === "object" && navigator . userAgent . includes ( "Firefox/" ) ;
176- const allStarsRegex = isFirefox
177- ? / ^ ( h t t p s ? | w s s ? ) : [ / ] [ / ] [ ^ / ] + ( [ / ] .* ) ? $ /
178- : / ^ h t t p s ? : [ / ] [ / ] [ ^ / ] + ( [ / ] .* ) ? $ / ;
179- const allUrlsRegex = / ^ ( h t t p s ? | f i l e | f t p ) : [ / ] + / ;
180-
181- function getRawPatternRegex ( pattern ) {
182- if ( ! patternValidationRegex . test ( pattern ) )
183- throw new Error (
184- pattern +
185- " is an invalid pattern, it must match " +
186- String ( patternValidationRegex )
187- ) ;
188- let [ , protocol , host , pathname ] = pattern . split ( / ( ^ [ ^ : ] + : [ / ] [ / ] ) ( [ ^ / ] + ) ? / ) ;
189- protocol = protocol
190- . replace ( "*" , isFirefox ? "(https?|wss?)" : "https?" )
191- . replace ( / [ / ] / g, "[/]" ) ;
192- host = ( host ?? "" )
193- . replace ( / ^ [ * ] [ . ] / , "([^/]+.)*" )
194- . replace ( / ^ [ * ] $ / , "[^/]+" )
195- . replace ( / [ . ] / g, "[.]" )
196- . replace ( / [ * ] $ / g, "[^.]+" ) ;
197- pathname = pathname
198- . replace ( / [ / ] / g, "[/]" )
199- . replace ( / [ . ] / g, "[.]" )
200- . replace ( / [ * ] / g, ".*" ) ;
201- return "^" + protocol + host + "(" + pathname + ")?$" ;
202- }
203-
204- function patternToRegex ( matchPatterns ) {
205- if ( matchPatterns . length === 0 ) return / $ ./ ;
206- if ( matchPatterns . includes ( "<all_urls>" ) ) return allUrlsRegex ;
207- if ( matchPatterns . includes ( "*://*/*" ) ) return allStarsRegex ;
208- return new RegExp (
209- matchPatterns . map ( ( x ) => getRawPatternRegex ( x ) ) . join ( "|" )
210- ) ;
211- }
212-
213- try {
214- return patternToRegex ( patterns ) . test ( url ) ;
215- } catch ( e ) {
216- console . log ( "ERROR matchPatterns" , e ) ;
217- return false ;
171+ for ( let pattern of patterns ) {
172+ // Replace wildcard characters * with regex wildcard .*
173+ const regexRule = pattern . replace ( / \* / g, ".*" ) ;
174+ // Create a regex pattern from the rule
175+ const reg = new RegExp ( "^" + regexRule + "$" ) ;
176+ // Check if the URL matches the pattern
177+ if ( ! reg . test ( url ) ) return false ;
218178 }
179+ return true ;
219180}
220181
221182// https://stackoverflow.com/a/68634884/11898496
@@ -272,11 +233,11 @@ export async function captureVisibleTab(options = {}, willDownload = true) {
272233
273234// https://gist.github.com/bluzky/b8c205c98ff3318907b30c3e0da4bf3f
274235export function removeAccents ( str ) {
275- var from =
236+ let from =
276237 "àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñçýỳỹỵỷ" ,
277238 to =
278239 "aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouuncyyyyy" ;
279- for ( var i = 0 , l = from . length ; i < l ; i ++ ) {
240+ for ( let i = 0 , l = from . length ; i < l ; i ++ ) {
280241 str = str . replace ( RegExp ( from [ i ] , "gi" ) , to [ i ] ) ;
281242 }
282243
@@ -380,8 +341,8 @@ export const JSONUtils = {
380341
381342// https://stackoverflow.com/a/4068385/11898496
382343export function popupCenter ( { url, title, w, h } ) {
383- var left = screen . width / 2 - w / 2 ;
384- var top = screen . height / 2 - h / 2 ;
344+ let left = screen . width / 2 - w / 2 ;
345+ let top = screen . height / 2 - h / 2 ;
385346 const newWindow = window . open (
386347 url ,
387348 title ,
@@ -476,19 +437,19 @@ export function waitForKeyElements(
476437 actionFunction /* Required: The code to run when elements are found. It is passed a jNode to the matched element.*/ ,
477438 bWaitOnce /* Optional: If false, will continue to scan for new elements even after the first match is found.*/
478439) {
479- var targetNodes , btargetsFound ;
440+ let targetNodes , btargetsFound ;
480441 targetNodes = document . querySelectorAll ( selectorTxt ) ;
481442
482443 if ( targetNodes && targetNodes . length > 0 ) {
483444 btargetsFound = true ;
484445 /*--- Found target node(s). Go through each and act if they are new. */
485446 targetNodes . forEach ( function ( element ) {
486- var alreadyFound =
447+ let alreadyFound =
487448 element . dataset . found == "alreadyFound" ? "alreadyFound" : false ;
488449
489450 if ( ! alreadyFound ) {
490451 //--- Call the payload function.
491- var cancelFound = actionFunction ( element ) ;
452+ let cancelFound = actionFunction ( element ) ;
492453 if ( cancelFound ) btargetsFound = false ;
493454 else element . dataset . found = "alreadyFound" ;
494455 }
@@ -497,10 +458,10 @@ export function waitForKeyElements(
497458 btargetsFound = false ;
498459 }
499460
500- //--- Get the timer-control variable for this selector.
501- var controlObj = waitForKeyElements . controlObj || { } ;
502- var controlKey = selectorTxt . replace ( / [ ^ \w ] / g, "_" ) ;
503- var timeControl = controlObj [ controlKey ] ;
461+ //--- Get the timer-control letiable for this selector.
462+ let controlObj = waitForKeyElements . controlObj || { } ;
463+ let controlKey = selectorTxt . replace ( / [ ^ \w ] / g, "_" ) ;
464+ let timeControl = controlObj [ controlKey ] ;
504465
505466 //--- Now set or clear the timer as appropriate.
506467 if ( btargetsFound && bWaitOnce && timeControl ) {
0 commit comments