mirror of
https://github.com/SukkaW/Surge.git
synced 2026-07-29 15:51:46 +08:00
Chore: URL Transform support both uBO & AdGuard
This commit is contained in:
@@ -202,7 +202,7 @@ export const buildRedirectModule = task(require.main === module, __filename)(asy
|
|||||||
[
|
[
|
||||||
'#!name=[Sukka] URL Redirect (Minimum)',
|
'#!name=[Sukka] URL Redirect (Minimum)',
|
||||||
`#!desc=Last Updated: ${new Date().toISOString()} Size: ${minimumDomains.size}`,
|
`#!desc=Last Updated: ${new Date().toISOString()} Size: ${minimumDomains.size}`,
|
||||||
'# This module only contains rules that doesn\'t work with/hasn\'t migrated to uBlock Origin\'s "uritransform" filter syntax',
|
'# This module only contains rules that doesn\'t work with/hasn\'t migrated to AdGuard/uBlock Origin\'s "uritransform" filter syntax',
|
||||||
'# uBO/AdGuard filter can be found at https://ruleset.skk.moe/Internal/sukka_ubo_url_redirect_filters.txt',
|
'# uBO/AdGuard filter can be found at https://ruleset.skk.moe/Internal/sukka_ubo_url_redirect_filters.txt',
|
||||||
'# This reduces mitm-hostnames and improves performance, with the tradeoff of uBO/AdGuard filter only cover mostly in browser.',
|
'# This reduces mitm-hostnames and improves performance, with the tradeoff of uBO/AdGuard filter only cover mostly in browser.',
|
||||||
'',
|
'',
|
||||||
@@ -228,7 +228,7 @@ export const buildRedirectModule = task(require.main === module, __filename)(asy
|
|||||||
compareAndWriteFile(
|
compareAndWriteFile(
|
||||||
span,
|
span,
|
||||||
[
|
[
|
||||||
'! Title: [sukka] Sukka URL Redirect',
|
'! Title: [sukka] Sukka URL Redirect (SukkaW/Surge @ GitHub)',
|
||||||
`! Last modified: ${new Date().toUTCString()}`,
|
`! Last modified: ${new Date().toUTCString()}`,
|
||||||
'! Expires: 4 hours',
|
'! Expires: 4 hours',
|
||||||
'! Description: Redirect requests via uritransform network filter syntax.',
|
'! Description: Redirect requests via uritransform network filter syntax.',
|
||||||
@@ -245,6 +245,11 @@ export const buildRedirectModule = task(require.main === module, __filename)(asy
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const modifiers = [
|
||||||
|
'$urltransform', // AdGuard
|
||||||
|
'$uritransform' // uBlock Origin
|
||||||
|
];
|
||||||
|
|
||||||
function uBOUriTransformGenerator(acc: string[], [from, to, canUboUriTransform]: [from: string, to: string, canUboUriTransform?: boolean]): string[] {
|
function uBOUriTransformGenerator(acc: string[], [from, to, canUboUriTransform]: [from: string, to: string, canUboUriTransform?: boolean]): string[] {
|
||||||
if (!canUboUriTransform) {
|
if (!canUboUriTransform) {
|
||||||
return acc;
|
return acc;
|
||||||
@@ -254,13 +259,13 @@ function uBOUriTransformGenerator(acc: string[], [from, to, canUboUriTransform]:
|
|||||||
// so when doing uBO we need to prepend.
|
// so when doing uBO we need to prepend.
|
||||||
// eslint-disable-next-line sukka/unicorn/no-array-front-mutation -- Given the the rules count is small, the performance impact is negligible.
|
// eslint-disable-next-line sukka/unicorn/no-array-front-mutation -- Given the the rules count is small, the performance impact is negligible.
|
||||||
acc.unshift(
|
acc.unshift(
|
||||||
'||'
|
...modifiers.map((modifier) => '||'
|
||||||
+ from
|
+ from
|
||||||
+ '$all,uritransform=/'
|
+ '$all,' + modifier + '=/'
|
||||||
+ escapeRegexp(from).replaceAll('/', String.raw`\/`)
|
+ escapeRegexp(from).replaceAll('/', String.raw`\/`)
|
||||||
+ '/'
|
+ '/'
|
||||||
+ to.replace('https://', '').replaceAll('/', String.raw`\/`)
|
+ to.replace('https://', '').replaceAll('/', String.raw`\/`)
|
||||||
+ '/'
|
+ '/')
|
||||||
);
|
);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
@@ -268,11 +273,12 @@ function uBOUriTransformGenerator(acc: string[], [from, to, canUboUriTransform]:
|
|||||||
|
|
||||||
function uBOUriTransformGeneratorForFakeWebsites(acc: string[], [from, to]: [from: string, to: string]): string[] {
|
function uBOUriTransformGeneratorForFakeWebsites(acc: string[], [from, to]: [from: string, to: string]): string[] {
|
||||||
// unlike Surge, which processes rules form top to bottom, uBO treats later rules with higher priority (overriden-like behavior),
|
// unlike Surge, which processes rules form top to bottom, uBO treats later rules with higher priority (overriden-like behavior),
|
||||||
// so when doing uBO we need to prepend. Given the the rules count is small, the performance impact is negligible.
|
// so when doing uBO we need to prepend.
|
||||||
|
// eslint-disable-next-line sukka/unicorn/no-array-front-mutation -- Given the the rules count is small, the performance impact is negligible.
|
||||||
acc.unshift(
|
acc.unshift(
|
||||||
'||'
|
...modifiers.map((modifier) => '||'
|
||||||
+ from
|
+ from
|
||||||
+ '$all,uritransform=/'
|
+ '$all,' + modifier + '=/'
|
||||||
// \/.*formysql\.com\/.*
|
// \/.*formysql\.com\/.*
|
||||||
//
|
//
|
||||||
// By adding \/.* at the beginning and the end, we can avoid replace the protocol (https:// or http://),
|
// By adding \/.* at the beginning and the end, we can avoid replace the protocol (https:// or http://),
|
||||||
@@ -284,7 +290,7 @@ function uBOUriTransformGeneratorForFakeWebsites(acc: string[], [from, to]: [fro
|
|||||||
+ String.raw`\/.*` + escapeRegexp(from).replaceAll('/', String.raw`\/`) + '.*'
|
+ String.raw`\/.*` + escapeRegexp(from).replaceAll('/', String.raw`\/`) + '.*'
|
||||||
+ '/'
|
+ '/'
|
||||||
+ to.replace('https://', '').replaceAll('/', String.raw`\/`)
|
+ to.replace('https://', '').replaceAll('/', String.raw`\/`)
|
||||||
+ '/'
|
+ '/')
|
||||||
);
|
);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
|
|||||||
Reference in New Issue
Block a user