Skip to content

Commit 8685067

Browse files
committed
build: make tinyShield exportable
1 parent 23b5ed8 commit 8685067

File tree

6 files changed

+89
-78
lines changed

6 files changed

+89
-78
lines changed

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"name": "@filteringdev/namulink",
3-
"version": "17.4.3",
3+
"version": "17.4.4",
44
"description": "",
55
"type": "module",
66
"scripts": {
7-
"build": "esbuild sources/src/index.ts --bundle --minify --define:global=window --inject:./sources/esbuild.inject.ts --banner:js=\"$(cat ./sources/banner.txt)\" --target=es2024,chrome119,safari17,firefox121 --outfile=./dist/NamuLink.user.js",
7+
"build:interface": "esbuild sources/interface.ts --bundle --format=esm --splitting --sourcemap --target=es2024 --external:/node_modules --outdir=dist && tsc --outDir dist/types --declaration --emitDeclarationOnly",
8+
"build:userscript": "esbuild sources/src/index.ts --bundle --minify --define:global=window --inject:./sources/esbuild.inject.ts --banner:js=\"$(cat ./sources/banner.txt)\" --target=es2024,chrome119,safari17,firefox121 --outfile=./dist/NamuLink.user.js",
9+
"build": "npm run build:interface && npm run build:userscript",
810
"debug": "esbuild sources/src/index.ts --bundle --define:global=window --inject:./sources/esbuild.inject.ts --banner:js=\"$(cat ./sources/banner.txt)\" --target=es2024,chrome119,safari17,firefox121 --outfile=./dist/NamuLink-debug.user.js",
911
"lint": "tsc && eslint sources --ext .ts"
1012
},
@@ -15,8 +17,15 @@
1517
"url": "https://github.com/PiQuark6046"
1618
},
1719
"files": [
18-
"dist"
20+
"dist/**/*"
1921
],
22+
"exports": {
23+
".": {
24+
"import": "./dist/interface.js",
25+
"types": "./dist/types/interface.d.ts"
26+
}
27+
},
28+
"types": "./dist/types/interface.d.ts",
2029
"repository": {
2130
"type": "git",
2231
"url": "git+https://github.com/FilteringDev/NamuLink.git"
@@ -41,8 +50,8 @@
4150
},
4251
"devDependencies": {
4352
"esbuild": "^0.25.10",
44-
"eslint": "^9.35.0",
53+
"eslint": "^9.36.0",
4554
"typescript": "^5.9.2",
46-
"typescript-eslint": "^8.44.0"
55+
"typescript-eslint": "^8.44.1"
4756
}
4857
}

pnpm-workspace.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

sources/banner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// @downloadURL https://cdn.jsdelivr.net/npm/@filteringdev/namulink@latest/dist/NamuLink.user.js
99
// @license MIT
1010
//
11-
// @version 17.4.3
11+
// @version 17.4.4
1212
// @author PiQuark6046 and contributors
1313
//
1414
// @match https://namu.wiki/*

sources/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { RunNamuLinkUserscript } from './src/index.js'

sources/src/index.ts

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,88 @@ declare const unsafeWindow: unsafeWindow
44

55
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
66

7-
function GetParents(Ele: HTMLElement) {
8-
let Parents: HTMLElement[] = []
9-
while (Ele.parentElement) {
10-
Parents.push(Ele.parentElement)
11-
Ele = Ele.parentElement
7+
export function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptName: string = 'NamuLink'): void {
8+
function GetParents(Ele: HTMLElement) {
9+
let Parents: HTMLElement[] = []
10+
while (Ele.parentElement) {
11+
Parents.push(Ele.parentElement)
12+
Ele = Ele.parentElement
13+
}
14+
return Parents
1215
}
13-
return Parents
14-
}
1516

16-
setInterval(() => {
17-
if (location.href.startsWith('https://namu.wiki/w/')) {
18-
let AdContainers = Array.from(document.querySelectorAll('div[class*=" "] div[class]')).filter(AdContainer => AdContainer instanceof HTMLElement)
17+
setInterval(() => {
18+
if (location.href.startsWith('https://namu.wiki/w/')) {
19+
let AdContainers = Array.from(document.querySelectorAll('div[class*=" "] div[class]')).filter(AdContainer => AdContainer instanceof HTMLElement)
1920

20-
AdContainers = AdContainers.filter((AdContainer) => {
21-
let AdContainerPaddingLeft = Number(getComputedStyle(AdContainer).getPropertyValue('padding-left').replaceAll('px', ''))
22-
let AdContainerPaddingRight = Number(getComputedStyle(AdContainer).getPropertyValue('padding-right').replaceAll('px', ''))
23-
let AdContainerPaddingTop = Number(getComputedStyle(AdContainer).getPropertyValue('padding-top').replaceAll('px', ''))
24-
let AdContainerPaddingBottom = Number(getComputedStyle(AdContainer).getPropertyValue('padding-bottom').replaceAll('px', ''))
25-
return AdContainerPaddingLeft > 5 && AdContainerPaddingRight > 5 && AdContainerPaddingTop > 5 && AdContainerPaddingBottom > 5
26-
})
21+
AdContainers = AdContainers.filter((AdContainer) => {
22+
let AdContainerPaddingLeft = Number(getComputedStyle(AdContainer).getPropertyValue('padding-left').replaceAll('px', ''))
23+
let AdContainerPaddingRight = Number(getComputedStyle(AdContainer).getPropertyValue('padding-right').replaceAll('px', ''))
24+
let AdContainerPaddingTop = Number(getComputedStyle(AdContainer).getPropertyValue('padding-top').replaceAll('px', ''))
25+
let AdContainerPaddingBottom = Number(getComputedStyle(AdContainer).getPropertyValue('padding-bottom').replaceAll('px', ''))
26+
return AdContainerPaddingLeft > 5 && AdContainerPaddingRight > 5 && AdContainerPaddingTop > 5 && AdContainerPaddingBottom > 5
27+
})
2728

28-
AdContainers = AdContainers.filter(AdContainer => {
29-
return Array.from(AdContainer.querySelectorAll('*')).filter(Ele => Ele instanceof HTMLElement &&
30-
getComputedStyle(Ele).getPropertyValue('animation-timing-function') === 'ease-in-out').length >= 3
31-
})
29+
AdContainers = AdContainers.filter(AdContainer => {
30+
return Array.from(AdContainer.querySelectorAll('*')).filter(Ele => Ele instanceof HTMLElement &&
31+
getComputedStyle(Ele).getPropertyValue('animation-timing-function') === 'ease-in-out').length >= 3
32+
})
3233

33-
AdContainers = AdContainers.filter(AdContainer => GetParents(AdContainer).some(Parent => Number(getComputedStyle(Parent).getPropertyValue('margin-top').replaceAll('px', '')) > 10 ))
34+
AdContainers = AdContainers.filter(AdContainer => GetParents(AdContainer).some(Parent => Number(getComputedStyle(Parent).getPropertyValue('margin-top').replaceAll('px', '')) > 10 ))
3435

35-
AdContainers = AdContainers.filter(AdContainer => AdContainer.innerText.length < 1000)
36+
AdContainers = AdContainers.filter(AdContainer => AdContainer.innerText.length < 1000)
3637

37-
AdContainers = AdContainers.filter(AdContainer => Array.from(AdContainer.querySelectorAll('*[href="/RecentChanges"]')).filter(Ele => Ele instanceof HTMLElement && getComputedStyle(Ele).getPropertyValue('display') !== 'none').length === 0)
38+
AdContainers = AdContainers.filter(AdContainer => Array.from(AdContainer.querySelectorAll('*[href="/RecentChanges"]')).filter(Ele => Ele instanceof HTMLElement && getComputedStyle(Ele).getPropertyValue('display') !== 'none').length === 0)
3839

39-
AdContainers = AdContainers.filter(AdContainer => !AdContainer.innerText.includes((new URL(location.href).searchParams.get('from') || '') + '에서 넘어옴'))
40+
AdContainers = AdContainers.filter(AdContainer => !AdContainer.innerText.includes((new URL(location.href).searchParams.get('from') || '') + '에서 넘어옴'))
4041

41-
AdContainers = AdContainers.filter(AdContainer => !/\[[0-9]+\] .+/.test(AdContainer.innerText))
42+
AdContainers = AdContainers.filter(AdContainer => !/\[[0-9]+\] .+/.test(AdContainer.innerText))
4243

43-
AdContainers.forEach(Ele => Ele.remove())
44-
}
45-
}, 1000)
46-
47-
let PowerLinkGenerationPositiveRegExps: RegExp[][] = [[
48-
/for *\( *; *; *\) *switch *\( *_[a-z0-9]+\[_[a-z0-9]+\([a-z0-9]+\)\] *=_[a-z0-9]+/,
49-
/_[a-z0-9]+\[('|")[A-Z]+('|")\]\)\(\[ *\]\)/,
50-
/0x[a-z0-9]+ *\) *; *case/
51-
], [
52-
/; *return *this\[_0x[a-z0-9]+\( *0x[0-9a-z]+ *\)/,
53-
/; *if *\( *_0x[a-z0-9]+ *&& *\( *_0x[a-z0-9]+ *= *_0x[a-z0-9]+/,
54-
/\) *, *void *\( *this *\[ *_0x[a-z0-9]+\( *0x[0-9a-z]+ *\) *\] *= *_0x[a-z0-9]+ *\[/
55-
]]
56-
57-
Win.Function.prototype.bind = new Proxy(Win.Function.prototype.bind, {
58-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
59-
apply(Target: typeof Function.prototype.bind, ThisArg: Function, Args: Parameters<typeof Function.prototype.bind>) {
60-
let StringifiedFunc = ThisArg.toString()
61-
if (PowerLinkGenerationPositiveRegExps.filter(PowerLinkGenerationPositiveRegExp => PowerLinkGenerationPositiveRegExp.filter(Index => Index.test(StringifiedFunc)).length >= 3).length === 1) {
62-
console.debug('[NamuLink] Function.prototype.bind:', ThisArg)
63-
return Reflect.apply(Target, () => {}, [])
44+
AdContainers.forEach(Ele => Ele.remove())
6445
}
65-
return Reflect.apply(Target, ThisArg, Args)
66-
}
67-
})
68-
69-
let PowerLinkGenerationSkeletionPositiveRegExps: RegExp[][] = [[
70-
/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/,
71-
/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/
72-
], [
73-
/\( *\) *=> *{ *var _0x[a-z0-9]+ *= *_0x[a-z0-9]+ *; *if *\( *this\[ *_0x[a-z0-9]+ *\( *0x[0-9a-f]+ *\) *\] *\) *return *clearTimeout/,
74-
/\( *0x[0-9a-f]+ *\) *\] *\) *, *void *\( *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *= *void *\([x0-9a-f*+-]+ *\) *\) *; *this\[_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *\(\) *;/
75-
]]
76-
77-
Win.setTimeout = new Proxy(Win.setTimeout, {
78-
apply(Target: typeof setTimeout, ThisArg: undefined, Args: Parameters<typeof setTimeout>) {
79-
let StringifiedFunc = Args[0].toString()
80-
if (PowerLinkGenerationSkeletionPositiveRegExps.filter(PowerLinkGenerationSkeletionPositiveRegExp => PowerLinkGenerationSkeletionPositiveRegExp.filter(Index => Index.test(StringifiedFunc)).length >= 1).length === 1) {
81-
console.debug('[NamuLink] setTimeout:', Args[0])
82-
return
46+
}, 1000)
47+
48+
let PowerLinkGenerationPositiveRegExps: RegExp[][] = [[
49+
/for *\( *; *; *\) *switch *\( *_[a-z0-9]+\[_[a-z0-9]+\([a-z0-9]+\)\] *=_[a-z0-9]+/,
50+
/_[a-z0-9]+\[('|")[A-Z]+('|")\]\)\(\[ *\]\)/,
51+
/0x[a-z0-9]+ *\) *; *case/
52+
], [
53+
/; *return *this\[_0x[a-z0-9]+\( *0x[0-9a-z]+ *\)/,
54+
/; *if *\( *_0x[a-z0-9]+ *&& *\( *_0x[a-z0-9]+ *= *_0x[a-z0-9]+/,
55+
/\) *, *void *\( *this *\[ *_0x[a-z0-9]+\( *0x[0-9a-z]+ *\) *\] *= *_0x[a-z0-9]+ *\[/
56+
]]
57+
58+
BrowserWindow.Function.prototype.bind = new Proxy(BrowserWindow.Function.prototype.bind, {
59+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
60+
apply(Target: typeof Function.prototype.bind, ThisArg: Function, Args: Parameters<typeof Function.prototype.bind>) {
61+
let StringifiedFunc = ThisArg.toString()
62+
if (PowerLinkGenerationPositiveRegExps.filter(PowerLinkGenerationPositiveRegExp => PowerLinkGenerationPositiveRegExp.filter(Index => Index.test(StringifiedFunc)).length >= 3).length === 1) {
63+
console.debug(`[${UserscriptName}]: Function.prototype.bind:`, ThisArg)
64+
return Reflect.apply(Target, () => {}, [])
65+
}
66+
return Reflect.apply(Target, ThisArg, Args)
8367
}
68+
})
69+
70+
let PowerLinkGenerationSkeletionPositiveRegExps: RegExp[][] = [[
71+
/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/,
72+
/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/
73+
], [
74+
/\( *\) *=> *{ *var _0x[a-z0-9]+ *= *_0x[a-z0-9]+ *; *if *\( *this\[ *_0x[a-z0-9]+ *\( *0x[0-9a-f]+ *\) *\] *\) *return *clearTimeout/,
75+
/\( *0x[0-9a-f]+ *\) *\] *\) *, *void *\( *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *= *void *\([x0-9a-f*+-]+ *\) *\) *; *this\[_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *\(\) *;/
76+
]]
77+
78+
BrowserWindow.setTimeout = new Proxy(BrowserWindow.setTimeout, {
79+
apply(Target: typeof setTimeout, ThisArg: undefined, Args: Parameters<typeof setTimeout>) {
80+
let StringifiedFunc = Args[0].toString()
81+
if (PowerLinkGenerationSkeletionPositiveRegExps.filter(PowerLinkGenerationSkeletionPositiveRegExp => PowerLinkGenerationSkeletionPositiveRegExp.filter(Index => Index.test(StringifiedFunc)).length >= 1).length === 1) {
82+
console.debug(`[${UserscriptName}]: setTimeout:`, Args[0])
83+
return
84+
}
85+
86+
return Reflect.apply(Target, ThisArg, Args)
87+
}
88+
})
89+
}
8490

85-
return Reflect.apply(Target, ThisArg, Args)
86-
}
87-
})
91+
RunNamuLinkUserscript(Win)

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"module": "NodeNext",
4-
"target": "ES2022",
4+
"target": "ES2024",
55
"moduleResolution": "NodeNext",
66
"removeComments": false,
77
"alwaysStrict": false,

0 commit comments

Comments
 (0)