Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"eslint": "^10.2.1",
"piscina": "^5.1.4",
"tldts": "^7.0.28",
"ts-morph": "^28.0.0",
"tsx": "^4.21.0",
"typescript": "^6.0.3",
"typescript-eslint": "^8.58.2",
Expand Down
4 changes: 3 additions & 1 deletion builder/source/buildci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { StandardBuild } from './build.js'
import { GroupedBuild } from './build-grouped.js'
import { Build } from './build-core.js'
import type { BuildOptions } from './build-core.js'
import { GlobalMatchBuild } from './globalmtach-test.js'

let ParsedArgv = (await ParseArgumentsAndOptions<BuildOptions>(FilterArgumentsForOptions(Process.argv))).Options
let Options = await Zod.strictObject({
Expand All @@ -21,4 +22,5 @@ const GroupedBuildInstance = new GroupedBuild(CoreBuildInstance, Options)
await GroupedBuildInstance.Build()
console.log('GroupedBuild completed successfully.')
await GroupedBuildInstance.MakeGroupMetadata()
console.log('Group metadata creation completed successfully.')
console.log('Group metadata creation completed successfully.')
await new GlobalMatchBuild(CoreBuildInstance, Options).Build()
75 changes: 75 additions & 0 deletions builder/source/globalmtach-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import * as Fs from 'node:fs'
import * as ESBuild from 'esbuild'
import PackageJson from '@npmcli/package-json'
import { CreateBanner } from './banner/index.js'
import { Build, type BuildOptions } from './build-core.js'

export class GlobalMatchBuild extends Build {
constructor(FromOrOption: Build | BuildOptions, Option?: BuildOptions) {
if (FromOrOption instanceof Build) {
super(Option!)
this.CopyStateFrom(FromOrOption)
return
}

super(FromOrOption)
}

async Build() {
let MatchingDomains: Set<string> = new Set<string>(this.FetchedDomains.get('Full'))
let SubscriptionURL = new URL(`https://cdn.jsdelivr.net/npm/@filteringdev/tinyshield@${this.Options?.Version ?? (await PackageJson.load(this.ProjectRoot)).content.version ?? '0.0.0'}/dist/tinyShield-GlobalMatch.user.js`)
const Banner = CreateBanner({
Version: this.Options?.Version ?? (await PackageJson.load(this.ProjectRoot)).content.version ?? '0.0.0',
BuildType: this.Options!.BuildType ?? 'production',
Domains: new Set<string>(['*']),
Name: 'tinyShield GlobalMatch',
Namespace: 'https://github.com/FilteringDev/tinyShield',
DownloadURL: SubscriptionURL,
UpdateURL: SubscriptionURL,
HomepageURL: new URL('https://github.com/FilteringDev/tinyShield'),
SupportURL: new URL('https://github.com/FilteringDev/tinyShield/issues'),
License: 'MPL-2.0',
Author: 'PiQuark6046 and contributors',
Description: {
en: 'tinyShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield quickly.',
ko: 'tinyShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 빠르게 저항할 수 있도록 합니다.',
ja: 'tinyShieldを使うと、AdGuard, uBlock Origin, Brave, およびABPがAd-Shieldに素早く対抗できます。'
}
})

Fs.copyFileSync(this.ProjectRoot + '/userscript/source/index.ts', this.ProjectRoot + '/userscript/source/index-globalmatch.ts')
const GlobalMatchIndexPath = this.ProjectRoot + '/userscript/source/index-globalmatch.ts'
const SourceText = Fs.readFileSync(GlobalMatchIndexPath, 'utf8')
const Anchor = 'export const OriginalRegExpTest = BrowserWindow.RegExp.prototype.test'
const AnchorIndex = SourceText.indexOf(Anchor)
if (AnchorIndex === -1) {
throw new Error('[globalmatch] Failed to find OriginalRegExpTest anchor in index-globalmatch.ts')
}

const AnchorLineEndIndex = SourceText.indexOf('\n', AnchorIndex)
if (AnchorLineEndIndex === -1) {
throw new Error('[globalmatch] Failed to determine insertion point in index-globalmatch.ts')
}

const DomainListElements = Array.from(MatchingDomains).map(Domain => JSON.stringify(Domain)).join(', ')
const ExecutionCondition = `;(() => {\n const DomainList: string[] = [${DomainListElements}]\n const CurrentURL = new URL(BrowserWindow.location.href)\n if (!DomainList.some(Domain => BrowserWindow.location.href.includes(\`://\${Domain}/\`) || CurrentURL.hostname.endsWith(\`.\${Domain}\`))) {\n return\n }\n\n`

const Head = SourceText.slice(0, AnchorLineEndIndex + 1)
const Tail = SourceText.slice(AnchorLineEndIndex + 1)
const TransformedSource = `${Head}\n${ExecutionCondition}${Tail}\n})()\n`
Fs.writeFileSync(GlobalMatchIndexPath, TransformedSource)

await ESBuild.build({
entryPoints: [this.ProjectRoot + '/userscript/source/index-globalmatch.ts'],
bundle: true,
minify: this.Options!.Minify,
outfile: `${this.ProjectRoot}/dist/tinyShield-GlobalMatch${this.Options!.BuildType === 'development' ? '.dev' : ''}.user.js`,
banner: {
js: Banner
},
target: ['es2024', 'chrome119', 'firefox142', 'safari26']
})

Fs.rmSync(this.ProjectRoot + '/userscript/source/index-globalmatch.ts')
}
}
Loading