Skip to content

Commit c966cf4

Browse files
committed
chore: remove exporting of interface
1 parent e0bba25 commit c966cf4

2 files changed

Lines changed: 84 additions & 96 deletions

File tree

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
"description": "",
55
"type": "module",
66
"scripts": {
7-
"build:interface": "tsc -p userscript/tsconfig.json",
87
"build:userscript": "npm run build -w builder -- --minify true --build-type production --SubscriptionUrl https://cdn.jsdelivr.net/npm/@filteringdev/tinyshield@latest/dist/tinyShield.user.js",
9-
"build": "npm run build:interface && npm run build:userscript",
8+
"build": "npm run build:userscript",
109
"debug": "npm run debug -w builder",
1110
"lint": "npm run lint -w builder && npm run lint -w userscript"
1211
},
@@ -16,12 +15,6 @@
1615
"files": [
1716
"dist/**/*"
1817
],
19-
"exports": {
20-
".": {
21-
"import": "./dist/index.js",
22-
"types": "./dist/index.d.ts"
23-
}
24-
},
2518
"repository": {
2619
"type": "git",
2720
"url": "git+https://github.com/FilteringDev/tinyShield.git"

userscript/source/index.ts

Lines changed: 83 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -12,109 +12,104 @@ type unsafeWindow = typeof window
1212
// eslint-disable-next-line @typescript-eslint/naming-convention
1313
declare const unsafeWindow: unsafeWindow
1414

15-
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
15+
const BrowserWindow = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
16+
const UserscriptName = 'tinyShield'
1617

1718
import { CheckDepthInASWeakMap } from './as-weakmap.js'
1819
import { SafeArrayToString } from './safe-ArrayToString.js'
1920

20-
export const OriginalRegExpTest = Win.RegExp.prototype.test
21+
const OriginalRegExpTest = BrowserWindow.RegExp.prototype.test
22+
const OriginalArrayMap = BrowserWindow.Array.prototype.map
23+
const OriginalString = BrowserWindow.String
24+
const OriginalArrayJoin = BrowserWindow.Array.prototype.join
25+
const OriginalObjectGetPrototypeOf = BrowserWindow.Object.getPrototypeOf
2126

22-
export function RunTinyShieldUserscript(BrowserWindow: typeof window, UserscriptName: string = 'tinyShield'): void {
23-
const OriginalRegExpTest = BrowserWindow.RegExp.prototype.test
24-
const OriginalArrayMap = BrowserWindow.Array.prototype.map
25-
const OriginalString = BrowserWindow.String
26-
const OriginalArrayJoin = BrowserWindow.Array.prototype.join
27-
const OriginalObjectGetPrototypeOf = BrowserWindow.Object.getPrototypeOf
27+
const ProtectedFunctionStrings = ['toString', 'get', 'set']
2828

29-
const ProtectedFunctionStrings = ['toString', 'get', 'set']
30-
31-
BrowserWindow.Function.prototype.toString = new Proxy(BrowserWindow.Function.prototype.toString, {
32-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
33-
apply(Target: () => string, ThisArg: Function, Args: []) {
34-
if (ProtectedFunctionStrings.includes(ThisArg.name)) {
35-
return `function ${ThisArg.name}() { [native code] }`
36-
} else {
37-
return Reflect.apply(Target, ThisArg, Args)
38-
}
29+
BrowserWindow.Function.prototype.toString = new Proxy(BrowserWindow.Function.prototype.toString, {
30+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
31+
apply(Target: () => string, ThisArg: Function, Args: []) {
32+
if (ProtectedFunctionStrings.includes(ThisArg.name)) {
33+
return `function ${ThisArg.name}() { [native code] }`
34+
} else {
35+
return Reflect.apply(Target, ThisArg, Args)
3936
}
40-
})
41-
42-
const ASInitPositiveRegExps: RegExp[][] = [[
43-
/[a-zA-Z0-9]+ *=> *{ *const *[a-zA-Z0-9]+ *= *[a-zA-Z0-9]+ *; *if/,
44-
/===? *[a-zA-Z0-9]+ *\[ *[a-zA-Z0-9]+\( *[0-9a-z]+ *\) *\] *\) *return *[a-zA-Z0-9]+ *\( *{ *('|")?inventoryId('|")? *:/,
45-
/{ *('|")?inventoryId('|")? *: *this *\[[a-zA-Z0-9]+ *\( *[0-9a-z]+ *\) *\] *, *\.\.\. *[a-zA-Z0-9]+ *\[ *[a-zA-Z0-9]+ *\( *[0-9a-z]+ * *\) *\] *} *\)/
46-
]]
47-
BrowserWindow.Map.prototype.get = new Proxy(BrowserWindow.Map.prototype.get, {
48-
apply(Target: (key: unknown) => unknown, ThisArg: Map<unknown, unknown>, Args: [unknown]) {
49-
if (Args.length > 0 && typeof Args[0] !== 'function') {
50-
return Reflect.apply(Target, ThisArg, Args)
51-
}
52-
53-
let ArgText = SafeArrayToString(Args, { OriginalArrayMap, OriginalString, OriginalArrayJoin, OriginalObjectGetPrototypeOf })
54-
if (ASInitPositiveRegExps.filter(ASInitPositiveRegExp => ASInitPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 2).length === 1) {
55-
console.debug(`[${UserscriptName}]: Map.prototype.get:`, ThisArg, Args)
56-
throw new Error()
57-
}
37+
}
38+
})
5839

40+
const ASInitPositiveRegExps: RegExp[][] = [[
41+
/[a-zA-Z0-9]+ *=> *{ *const *[a-zA-Z0-9]+ *= *[a-zA-Z0-9]+ *; *if/,
42+
/===? *[a-zA-Z0-9]+ *\[ *[a-zA-Z0-9]+\( *[0-9a-z]+ *\) *\] *\) *return *[a-zA-Z0-9]+ *\( *{ *('|")?inventoryId('|")? *:/,
43+
/{ *('|")?inventoryId('|")? *: *this *\[[a-zA-Z0-9]+ *\( *[0-9a-z]+ *\) *\] *, *\.\.\. *[a-zA-Z0-9]+ *\[ *[a-zA-Z0-9]+ *\( *[0-9a-z]+ * *\) *\] *} *\)/
44+
]]
45+
BrowserWindow.Map.prototype.get = new Proxy(BrowserWindow.Map.prototype.get, {
46+
apply(Target: (key: unknown) => unknown, ThisArg: Map<unknown, unknown>, Args: [unknown]) {
47+
if (Args.length > 0 && typeof Args[0] !== 'function') {
5948
return Reflect.apply(Target, ThisArg, Args)
6049
}
61-
})
6250

63-
const ASReinsertedAdvInvenPositiveRegExps: RegExp[][] = [[
64-
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/,
65-
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/,
66-
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/
67-
], [
68-
/[a-z0-9A-Z]+\.setAttribute\( *('|")onload('|") *, *('|")! *async *function\( *\) *\{ *let */,
69-
/confirm\( *[A-Za-z0-9]+ *\) *\) *{ *const *[A-Za-z0-9]+ *= *new *[A-Za-z0-9]+\.URL\(('|")https:\/\/report\.error-report\.com\//,
70-
/\.forEach *\( *\( *[A-Za-z0-9]+ *=> *[A-Za-z0-9]+\.remove *\( *\) *\) *\) *\) *, *[0-9a-f]+ *\) *; *const *[A-Za-z0-9]+ *= *await *\( *await *fetch *\(/
71-
]]
72-
BrowserWindow.Map.prototype.set = new Proxy(BrowserWindow.Map.prototype.set, {
73-
apply(Target: (key: unknown, value: unknown) => Map<unknown, unknown>, ThisArg: Map<unknown, unknown>, Args: [unknown, unknown]) {
74-
let ArgText = ''
75-
ArgText = SafeArrayToString(Args, { OriginalArrayMap, OriginalString, OriginalArrayJoin, OriginalObjectGetPrototypeOf })
76-
if (ASReinsertedAdvInvenPositiveRegExps.filter(ASReinsertedAdvInvenPositiveRegExp => ASReinsertedAdvInvenPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 3).length === 1) {
77-
console.debug(`[${UserscriptName}]: Map.prototype.set:`, ThisArg, Args)
78-
throw new Error()
79-
}
80-
return Reflect.apply(Target, ThisArg, Args)
51+
let ArgText = SafeArrayToString(Args, { OriginalArrayMap, OriginalString, OriginalArrayJoin, OriginalObjectGetPrototypeOf })
52+
if (ASInitPositiveRegExps.filter(ASInitPositiveRegExp => ASInitPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 2).length === 1) {
53+
console.debug(`[${UserscriptName}]: Map.prototype.get:`, ThisArg, Args)
54+
throw new Error()
8155
}
82-
})
8356

84-
BrowserWindow.WeakMap.prototype.set = new Proxy(BrowserWindow.WeakMap.prototype.set, {
85-
apply(Target: (key: object, value: unknown) => WeakMap<object, unknown>, ThisArg: WeakMap<object, unknown>, Args: [object, unknown]) {
86-
if (CheckDepthInASWeakMap(Args)) {
87-
console.debug(`[${UserscriptName}]: WeakMap.prototype.set:`, ThisArg, Args)
88-
throw new Error()
89-
}
57+
return Reflect.apply(Target, ThisArg, Args)
58+
}
59+
})
9060

91-
return Reflect.apply(Target, ThisArg, Args)
61+
const ASReinsertedAdvInvenPositiveRegExps: RegExp[][] = [[
62+
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/,
63+
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/,
64+
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/
65+
], [
66+
/[a-z0-9A-Z]+\.setAttribute\( *('|")onload('|") *, *('|")! *async *function\( *\) *\{ *let */,
67+
/confirm\( *[A-Za-z0-9]+ *\) *\) *{ *const *[A-Za-z0-9]+ *= *new *[A-Za-z0-9]+\.URL\(('|")https:\/\/report\.error-report\.com\//,
68+
/\.forEach *\( *\( *[A-Za-z0-9]+ *=> *[A-Za-z0-9]+\.remove *\( *\) *\) *\) *\) *, *[0-9a-f]+ *\) *; *const *[A-Za-z0-9]+ *= *await *\( *await *fetch *\(/
69+
]]
70+
BrowserWindow.Map.prototype.set = new Proxy(BrowserWindow.Map.prototype.set, {
71+
apply(Target: (key: unknown, value: unknown) => Map<unknown, unknown>, ThisArg: Map<unknown, unknown>, Args: [unknown, unknown]) {
72+
let ArgText = ''
73+
ArgText = SafeArrayToString(Args, { OriginalArrayMap, OriginalString, OriginalArrayJoin, OriginalObjectGetPrototypeOf })
74+
if (ASReinsertedAdvInvenPositiveRegExps.filter(ASReinsertedAdvInvenPositiveRegExp => ASReinsertedAdvInvenPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 3).length === 1) {
75+
console.debug(`[${UserscriptName}]: Map.prototype.set:`, ThisArg, Args)
76+
throw new Error()
9277
}
93-
})
78+
return Reflect.apply(Target, ThisArg, Args)
79+
}
80+
})
9481

95-
let ASTimerRegExps: RegExp[][] = [[
96-
/async *\( *\) *=> *{ *const *[A-Za-z0-9]+ *= *[A-Za-z0-9]+ *; *await *[A-Za-z0-9]+ *\( *\)/,
97-
/; *await *[A-Za-z0-9]+ *\( *\) *, *[A-Za-z0-9]+ *\( *! *1 *, *new *Error *\( *[A-Za-z0-9]+ *\( *[0-9a-f]+ *\) *\) *\) *}/,
98-
/ *\) *\) *\) *}/
99-
]]
100-
BrowserWindow.setTimeout = new Proxy(BrowserWindow.setTimeout, {
101-
apply(Target: typeof BrowserWindow.setTimeout, ThisArg: undefined, Args: Parameters<typeof setTimeout>) {
102-
if (ASTimerRegExps.filter(ASTimerRegExp => ASTimerRegExp.filter(Index => Index.test(Args[0].toString())).length >= 3).length === 1) {
103-
console.debug(`[${UserscriptName}]: setTimeout:`, Args)
104-
return
105-
}
106-
return Reflect.apply(Target, ThisArg, Args)
107-
}
108-
})
109-
BrowserWindow.setInterval = new Proxy(BrowserWindow.setInterval, {
110-
apply(Target: typeof BrowserWindow.setInterval, ThisArg: undefined, Args: Parameters<typeof setInterval>) {
111-
if (ASTimerRegExps.filter(ASTimerRegExp => ASTimerRegExp.filter(Index => Index.test(Args[0].toString())).length >= 3).length === 1) {
112-
console.debug(`[${UserscriptName}]: setInterval:`, Args)
113-
return
114-
}
115-
return Reflect.apply(Target, ThisArg, Args)
82+
BrowserWindow.WeakMap.prototype.set = new Proxy(BrowserWindow.WeakMap.prototype.set, {
83+
apply(Target: (key: object, value: unknown) => WeakMap<object, unknown>, ThisArg: WeakMap<object, unknown>, Args: [object, unknown]) {
84+
if (CheckDepthInASWeakMap(Args)) {
85+
console.debug(`[${UserscriptName}]: WeakMap.prototype.set:`, ThisArg, Args)
86+
throw new Error()
11687
}
117-
})
118-
}
11988

120-
RunTinyShieldUserscript(Win)
89+
return Reflect.apply(Target, ThisArg, Args)
90+
}
91+
})
92+
93+
let ASTimerRegExps: RegExp[][] = [[
94+
/async *\( *\) *=> *{ *const *[A-Za-z0-9]+ *= *[A-Za-z0-9]+ *; *await *[A-Za-z0-9]+ *\( *\)/,
95+
/; *await *[A-Za-z0-9]+ *\( *\) *, *[A-Za-z0-9]+ *\( *! *1 *, *new *Error *\( *[A-Za-z0-9]+ *\( *[0-9a-f]+ *\) *\) *\) *}/,
96+
/ *\) *\) *\) *}/
97+
]]
98+
BrowserWindow.setTimeout = new Proxy(BrowserWindow.setTimeout, {
99+
apply(Target: typeof BrowserWindow.setTimeout, ThisArg: undefined, Args: Parameters<typeof setTimeout>) {
100+
if (ASTimerRegExps.filter(ASTimerRegExp => ASTimerRegExp.filter(Index => Index.test(Args[0].toString())).length >= 3).length === 1) {
101+
console.debug(`[${UserscriptName}]: setTimeout:`, Args)
102+
return
103+
}
104+
return Reflect.apply(Target, ThisArg, Args)
105+
}
106+
})
107+
BrowserWindow.setInterval = new Proxy(BrowserWindow.setInterval, {
108+
apply(Target: typeof BrowserWindow.setInterval, ThisArg: undefined, Args: Parameters<typeof setInterval>) {
109+
if (ASTimerRegExps.filter(ASTimerRegExp => ASTimerRegExp.filter(Index => Index.test(Args[0].toString())).length >= 3).length === 1) {
110+
console.debug(`[${UserscriptName}]: setInterval:`, Args)
111+
return
112+
}
113+
return Reflect.apply(Target, ThisArg, Args)
114+
}
115+
})

0 commit comments

Comments
 (0)