Skip to content

Commit c9907e2

Browse files
committed
ci: quoid/userscripts cannot read userscript metadata header because there are too many @match fields
1 parent 7d7409b commit c9907e2

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
dist
2+
dist
3+
sources/src/#generated-*.ts

builder.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import * as ESBuild from 'esbuild'
66
import * as Zod from 'zod'
77
import PackageJson from '@npmcli/package-json'
88
import * as Semver from 'semver'
9+
import * as TsMorph from 'ts-morph'
910
import * as Fs from 'node:fs'
1011
import * as NodeHttps from 'node:https'
1112
import * as Process from 'node:process'
1213

13-
let BuildType: 'production' | 'development' = Zod.string().refine(BT => BT === 'production' || BT === 'development').default('production').parse(Process.argv[4] ?? 'production')
14+
let BuildType: 'production' | 'development' = Zod.string().refine(BT => BT === 'production' || BT === 'development').default('production').parse(Process.argv[3] ?? 'production')
1415
console.log('Build type set to:', BuildType)
1516

1617
let Version: string = (await PackageJson.load('./')).content.version
@@ -78,40 +79,48 @@ for (const SellerEntry of IABSellersJsonData.sellers) {
7879
}
7980
console.log('Collected', DomainsList.size, 'unique domains from IAB Sellers.json')
8081

82+
const IndexFilePath = `./sources/src/#generated-${crypto.randomUUID()}.ts`
83+
Fs.copyFileSync('./sources/src/index.ts', IndexFilePath)
84+
const Project = new TsMorph.Project({ tsConfigFilePath: './tsconfig.json' })
85+
const IndexFile = Project.getSourceFileOrThrow(IndexFilePath)
86+
const TargetedDomainsArray = IndexFile.getVariableDeclaration('TargetedDomains').getInitializerIfKindOrThrow(TsMorph.SyntaxKind.ArrayLiteralExpression)
87+
for (const Domain of DomainsList) {
88+
TargetedDomainsArray.addElement(`'${Domain}'`)
89+
}
90+
await Project.save()
91+
console.log('Updated targeted domains in', IndexFilePath, '; total domains:', DomainsList.size)
92+
8193
const HeaderLocation = './sources/banner.txt'
8294
let ConvertedHeader: string = ''
8395
for (const Line of Fs.readFileSync(HeaderLocation, 'utf-8').split('\n')) {
8496
if (Line.includes('%%VERSION_VALUE%%')) {
8597
ConvertedHeader += Line.replaceAll('%%VERSION_VALUE%%', Version) + '\n'
8698
} else if (Line.includes('%%NAME%%')) {
8799
ConvertedHeader += Line.replaceAll('%%NAME%%', BuildType === 'production' ? 'tinyShield' : 'tinyShield (Development)') + '\n'
88-
} else if (Line === '%%DOMAIN_INJECTION%%') {
89-
for (const DomainEntry of DomainsList) {
90-
ConvertedHeader += `// @match *://${DomainEntry}/*\n`
91-
ConvertedHeader += `// @match *://*.${DomainEntry}/*\n`
92-
}
93100
} else {
94101
ConvertedHeader += Line + '\n'
95102
}
96103
}
97-
console.log('Generated header with domain injections and processing')
104+
console.log('Generated header with userscript name and version')
98105
let AttachHeaderPath = `/tmp/${crypto.randomUUID()}`
99106
Fs.writeFileSync(AttachHeaderPath, ConvertedHeader, 'utf-8')
100107
console.log('Written temporary header file to:', AttachHeaderPath)
101108
await ESBuild.build({
102-
entryPoints: ['./sources/src/index.ts'],
109+
entryPoints: [IndexFilePath],
103110
bundle: true,
104-
minify: true,
111+
minify: BuildType === 'production',
105112
define: {
106113
global: 'window'
107114
},
108115
inject: ['./sources/esbuild.inject.ts'],
109116
banner: {
110117
js: Fs.readFileSync(AttachHeaderPath, 'utf-8')
111118
},
112-
target: ['es2024', 'chrome119', 'firefox117', 'safari121'],
119+
target: ['es2024', 'chrome119', 'firefox142', 'safari26'],
113120
outfile: BuildType === 'production' ? './dist/tinyShield.user.js' : './dist/tinyShield.dev.user.js',
114121
})
115122
console.log('Build completed')
116123
Fs.rmSync(AttachHeaderPath)
117-
console.log('Temporary header file removed')
124+
console.log('Temporary header file removed')
125+
Fs.rmSync(IndexFilePath)
126+
console.log('Temporary source file removed')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"esbuild": "^0.27.0",
3939
"eslint": "^9.38.0",
4040
"semver": "^7.7.3",
41+
"ts-morph": "^27.0.2",
4142
"tsx": "^4.21.0",
4243
"typescript": "^5.9.3",
4344
"typescript-eslint": "^8.46.2",

sources/banner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// @version %%VERSION_VALUE%%
1212
// @author PiQuark6046 and contributors
1313
//
14-
%%DOMAIN_INJECTION%%
14+
// @match *://*.*/*
1515
//
1616
// @description tinyShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield quickly.
1717
// @description:ko tinyShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 빠르게 저항할 수 있도록 합니다.

sources/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,8 @@ export function RunTinyShieldUserscript(BrowserWindow: typeof window, Userscript
117117
})
118118
}
119119

120-
RunTinyShieldUserscript(Win)
120+
const TargetedDomains: string[] = []
121+
if (TargetedDomains.some(Domain => new URLPattern(`*://${Domain}/*`).test(window.location.href) || new URLPattern(`*://*.${Domain}/*`).test(window.location.href))) {
122+
console.debug('[tinyShield]: Targeted domain matched, running userscript')
123+
RunTinyShieldUserscript(Win)
124+
}

0 commit comments

Comments
 (0)