|
28 | 28 | ) |
29 | 29 | SCRIPT+=$'\n' |
30 | 30 |
|
31 | | - |
32 | 31 | # Loop to add @include entries |
33 | 32 | while IFS= read -r europress_single_url; do |
34 | 33 | SCRIPT+="// @include $europress_single_url"$'\n' |
@@ -70,8 +69,18 @@ SCRIPT+=$'// |
70 | 69 | const hostname = window.location.hostname; |
71 | 70 |
|
72 | 71 | function match(str, rule) { |
73 | | - var escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); |
74 | | - return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$").test(str); |
| 72 | + // Extract domain pattern from the rule (ignore https:// and /*) |
| 73 | + var domainRule = rule.replace(/^https?:\/\//, '\'''\'').replace(/\/\*$/, '\'''\''); |
| 74 | + |
| 75 | + // Convert the wildcard pattern to a proper regex |
| 76 | + var regexPattern = "^" + domainRule.split('\''*'\'').map(function(part) { |
| 77 | + // Escape special regex characters in each part |
| 78 | + return part.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); |
| 79 | + }).join('\''.*'\'') + "$"; |
| 80 | + |
| 81 | + // Create and test the regex against the input string |
| 82 | + var regex = new RegExp(regexPattern); |
| 83 | + return regex.test(str); |
75 | 84 | } |
76 | 85 |
|
77 | 86 | function pasteStyle(str) { |
@@ -171,10 +180,10 @@ while IFS= read -r europress_single_url; do |
171 | 180 | if [[ "$counter" -eq "$europress_urls_count" ]]; then |
172 | 181 | # last element, close the parenthesis. |
173 | 182 | SCRIPT+=$' |
174 | | - "'"$europress_single_url"'".includes(hostname)) {' |
| 183 | + match(hostname, "'"$europress_single_url"'")) {' |
175 | 184 | else |
176 | 185 | SCRIPT+=$' |
177 | | - "'"$europress_single_url"'".includes(hostname) ||' |
| 186 | + match(hostname, "'"$europress_single_url"'") ||' |
178 | 187 | fi |
179 | 188 | ((counter++)) |
180 | 189 | done <<< "$europress_urls" |
@@ -370,7 +379,7 @@ while IFS= read -r line; do |
370 | 379 | fi |
371 | 380 |
|
372 | 381 | SCRIPT+=$' |
373 | | - if ("'"$matches"'".includes(hostname)) { |
| 382 | + if (match(hostname, "'"$matches"'")) { |
374 | 383 |
|
375 | 384 | window.addEventListener("load", function(event) { |
376 | 385 | '"$js_str"' |
|
0 commit comments