mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-14 02:00:37 +08:00
Feat: salvage $document from filters
This commit is contained in:
parent
e8346d0d0f
commit
289a3ef40e
@ -142,7 +142,7 @@ export async function processFilterRules(
|
|||||||
ttl: number | null = null,
|
ttl: number | null = null,
|
||||||
allowThirdParty = false
|
allowThirdParty = false
|
||||||
): Promise<{ white: string[], black: string[], foundDebugDomain: boolean }> {
|
): Promise<{ white: string[], black: string[], foundDebugDomain: boolean }> {
|
||||||
const [white, black, warningMessages] = await parentSpan.traceChild(`process filter rules: ${filterRulesUrl}`).traceAsyncFn((span) => fsFetchCache.applyWithHttp304AndMirrors<Readonly<[ white: string[], black: string[], warningMessages: string[] ]>>(
|
const [white, black, warningMessages] = await parentSpan.traceChild(`process filter rules: ${filterRulesUrl}`).traceAsyncFn((span) => fsFetchCache.applyWithHttp304AndMirrors<Readonly<[white: string[], black: string[], warningMessages: string[]]>>(
|
||||||
filterRulesUrl,
|
filterRulesUrl,
|
||||||
fallbackUrls ?? [],
|
fallbackUrls ?? [],
|
||||||
getFileContentHash(__filename),
|
getFileContentHash(__filename),
|
||||||
@ -334,13 +334,23 @@ export function parse($line: string, result: [string, ParseType], allowThirdPart
|
|||||||
|| filter.isRedirectRule()
|
|| filter.isRedirectRule()
|
||||||
|| filter.hasDomains()
|
|| filter.hasDomains()
|
||||||
|| filter.isCSP() // must not be csp rule
|
|| filter.isCSP() // must not be csp rule
|
||||||
|| (!filter.fromAny() && !filter.fromDocument())
|
|| (!filter.fromHttp() && !filter.fromHttps())
|
||||||
) {
|
) {
|
||||||
// not supported type
|
// not supported type
|
||||||
result[1] = ParseType.Null;
|
result[1] = ParseType.Null;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!filter.fromAny()
|
||||||
|
// $image, $websocket, $xhr this are all non-any
|
||||||
|
&& !filter.fromDocument() // $document, $doc
|
||||||
|
// && !filter.fromSubdocument() // $subdocument, $subdoc
|
||||||
|
) {
|
||||||
|
result[1] = ParseType.Null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
filter.hostname // filter.hasHostname() // must have
|
filter.hostname // filter.hasHostname() // must have
|
||||||
&& filter.isPlain() // isPlain() === !isRegex()
|
&& filter.isPlain() // isPlain() === !isRegex()
|
||||||
@ -366,10 +376,11 @@ export function parse($line: string, result: [string, ParseType], allowThirdPart
|
|||||||
const _1p = filter.firstParty();
|
const _1p = filter.firstParty();
|
||||||
const _3p = filter.thirdParty();
|
const _3p = filter.thirdParty();
|
||||||
|
|
||||||
if (_1p) {
|
if (_1p) { // first party is true
|
||||||
if (_1p === _3p) {
|
if (_3p) { // third party is also true
|
||||||
result[0] = hostname;
|
result[0] = hostname;
|
||||||
result[1] = isIncludeAllSubDomain ? ParseType.BlackIncludeSubdomain : ParseType.BlackAbsolute;
|
result[1] = isIncludeAllSubDomain ? ParseType.BlackIncludeSubdomain : ParseType.BlackAbsolute;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result[1] = ParseType.Null;
|
result[1] = ParseType.Null;
|
||||||
@ -549,6 +560,16 @@ export function parse($line: string, result: [string, ParseType], allowThirdPart
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (line.endsWith('$image')) {
|
||||||
|
// /**
|
||||||
|
// * Some $image filters are not NetworkFilter:
|
||||||
|
// *
|
||||||
|
// * `app.site123.com$image`
|
||||||
|
// * `t.signaux$image`
|
||||||
|
// * `track.customer.io$image`
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
const lineStartsWithSingleDot = firstCharCode === 46; // 46 `.`
|
const lineStartsWithSingleDot = firstCharCode === 46; // 46 `.`
|
||||||
if (
|
if (
|
||||||
lineStartsWithSingleDot
|
lineStartsWithSingleDot
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user