diff --git a/builder.ts b/builder.ts index 9284edd..478665b 100644 --- a/builder.ts +++ b/builder.ts @@ -6,7 +6,6 @@ import * as ESBuild from 'esbuild' import * as Zod from 'zod' import PackageJson from '@npmcli/package-json' import * as Semver from 'semver' -import * as TsMorph from 'ts-morph' import * as Fs from 'node:fs' import * as NodeHttps from 'node:https' import * as Process from 'node:process' @@ -79,18 +78,6 @@ for (const SellerEntry of IABSellersJsonData.sellers) { } console.log('Collected', DomainsList.size, 'unique domains from IAB Sellers.json') -const IndexFilePath = `./sources/src/#generated-${crypto.randomUUID()}.ts` -Fs.copyFileSync('./sources/src/index.ts', IndexFilePath) -Fs.chmodSync(IndexFilePath, 0o700) -const Project = new TsMorph.Project({ tsConfigFilePath: './tsconfig.json' }) -const IndexFile = Project.getSourceFileOrThrow(IndexFilePath) -const TargetedDomainsArray = IndexFile.getVariableDeclaration('TargetedDomains').getInitializerIfKindOrThrow(TsMorph.SyntaxKind.ArrayLiteralExpression) -for (const Domain of DomainsList) { - TargetedDomainsArray.addElement(`'${Domain}'`) -} -await Project.save() -console.log('Updated targeted domains in', IndexFilePath, '; total domains:', DomainsList.size) - const HeaderLocation = './sources/banner.txt' let ConvertedHeader: string = '' for (const Line of Fs.readFileSync(HeaderLocation, 'utf-8').split('\n')) { @@ -98,16 +85,21 @@ for (const Line of Fs.readFileSync(HeaderLocation, 'utf-8').split('\n')) { ConvertedHeader += Line.replaceAll('%%VERSION_VALUE%%', Version) + '\n' } else if (Line.includes('%%NAME%%')) { ConvertedHeader += Line.replaceAll('%%NAME%%', BuildType === 'production' ? 'tinyShield' : 'tinyShield (Development)') + '\n' + } else if (Line === '%%DOMAIN_INJECTION%%') { + for (const DomainEntry of DomainsList) { + ConvertedHeader += `// @match *://${DomainEntry}/*\n` + ConvertedHeader += `// @match *://*.${DomainEntry}/*\n` + } } else { ConvertedHeader += Line + '\n' } } -console.log('Generated header with userscript name and version') +console.log('Generated header with domain injections and processing') let AttachHeaderPath = `/tmp/${crypto.randomUUID()}` Fs.writeFileSync(AttachHeaderPath, ConvertedHeader, { encoding: 'utf-8', mode: 0o700 }) console.log('Written temporary header file to:', AttachHeaderPath) await ESBuild.build({ - entryPoints: [IndexFilePath], + entryPoints: ['./sources/src/index.ts'], bundle: true, minify: BuildType === 'production', define: { @@ -122,6 +114,4 @@ await ESBuild.build({ }) console.log('Build completed') Fs.rmSync(AttachHeaderPath) -console.log('Temporary header file removed') -Fs.rmSync(IndexFilePath) -console.log('Temporary source file removed') \ No newline at end of file +console.log('Temporary header file removed') \ No newline at end of file diff --git a/package.json b/package.json index ed0a785..170f47a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "esbuild": "^0.27.0", "eslint": "^9.38.0", "semver": "^7.7.3", - "ts-morph": "^27.0.2", "tsx": "^4.21.0", "typescript": "^5.9.3", "typescript-eslint": "^8.46.2", diff --git a/sources/banner.txt b/sources/banner.txt index b760810..ebafe48 100644 --- a/sources/banner.txt +++ b/sources/banner.txt @@ -11,8 +11,7 @@ // @version %%VERSION_VALUE%% // @author PiQuark6046 and contributors // -// @match https://*/* -// @match http://*/* +%%DOMAIN_INJECTION%% // // @description tinyShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield quickly. // @description:ko tinyShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 빠르게 저항할 수 있도록 합니다.