Skip to content

Commit de156b8

Browse files
committed
feat: mock namuwiki internal function
1 parent 187a85f commit de156b8

File tree

2 files changed

+53
-92
lines changed

2 files changed

+53
-92
lines changed

sources/src/index.ts

Lines changed: 10 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,22 @@
1+
import type { TPowerLinkContent } from './powerlinkcontent.js'
2+
13
type unsafeWindow = typeof window
24
// eslint-disable-next-line @typescript-eslint/naming-convention
35
declare const unsafeWindow: unsafeWindow
46

57
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
68

7-
let HideLeftover = () => {
8-
setInterval(() => {
9-
Array.from(document.querySelectorAll('div[class*=" "] div[class]')).filter((TargetEle: HTMLElement) => {
10-
return (Array.from(TargetEle.querySelectorAll('*')).filter((ChildEle: HTMLElement) => {
11-
return getComputedStyle(ChildEle).getPropertyValue('animation').includes('infinite')
12-
}).length >= 6 || TargetEle.innerText === '' || TargetEle.innerText.includes('파워링크')) &&
13-
(Number(getComputedStyle(TargetEle).getPropertyValue('margin-top').replace('px', '')) > 10 || Number(getComputedStyle(TargetEle).getPropertyValue('margin-bottom').replace('px', '')) > 10) &&
14-
Number(getComputedStyle(TargetEle).getPropertyValue('height').replace('px', '')) < 350
15-
}).forEach((TargetEle: HTMLElement) => {
16-
TargetEle.setAttribute('style', 'visibility: hidden !important; width: 1px !important; height: 1px !important;')
17-
})
18-
}, 2500)
19-
}
20-
21-
let RegExPatterns: RegExp[] = [
22-
/^#x=[A-Za-z0-9-+]+\/\/\/.+=?$/,
23-
/^[A-Za-z0-9+\/]+\/{3,}w=+/
24-
]
25-
269
Win.Proxy = new Proxy(Win.Proxy, {
2710
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
2811
construct<T extends object>(Target: ProxyConstructor, Args: [T, ProxyHandler<T>], NewTarget: Function): object {
29-
if (typeof Args[0] === 'object' && Array.isArray(Args[0]) && typeof Args[0][0] === 'object' && Array.isArray(Args[0][0])
30-
&& typeof Args[0][0][1] === 'string' && RegExPatterns.some((Pattern: RegExp) => Pattern.test(Args[0][0][1]))) {
31-
HideLeftover()
32-
return Reflect.construct(Target, [Args[0], ['파워링크']], NewTarget)
33-
}
34-
if (typeof Args[0] === 'object' && Object.keys(Args[0]).some((Key: string) => RegExPatterns.some((Pattern: RegExp) => typeof Args[0][Key] === 'string' && Pattern.test(Args[0][Key])))) {
35-
HideLeftover()
36-
let ArgsObj = Args[0]
37-
Object.keys(ArgsObj).map((Key: string) => {
38-
if (typeof ArgsObj[Key] === 'string') {
39-
ArgsObj[Key] = '파워링크'
40-
}
41-
})
42-
return Reflect.construct(Target, [Args[0], ArgsObj], NewTarget)
43-
}
44-
if (typeof Args[0] === 'object' && Object.keys(Args[0]).some((Key: string) => typeof Args[0][Key] === 'string' &&
45-
(Args[0][Key].includes('searchad.naver.com') || Args[0][Key].includes('saedu.naver.com/adbiz/')))) {
46-
HideLeftover()
47-
return
48-
}
49-
50-
// Object inner section analysis
51-
let TensorResult: Array<number> = [0, 0, 0] // string, number, boolean
52-
if (typeof Args[0] === 'object') {
53-
Object.keys(Args[0]).forEach((Key: string) => {
54-
switch (typeof Args[0][Key]) {
55-
case 'string':
56-
if (Args[0][Key].length > 5) {
57-
TensorResult[0]++
58-
}
59-
break
60-
case 'number':
61-
TensorResult[1]++
62-
break
63-
case 'boolean':
64-
TensorResult[2]++
65-
break
66-
}
67-
})
68-
}
69-
if (TensorResult.every((Result) => Result >= 3) && typeof Args[0]['content'] !== 'object') {
70-
HideLeftover()
71-
return Reflect.construct(Target, [Args[0], ['파워링크']], NewTarget)
72-
}
73-
//
12+
if (typeof Args[0] === 'object' && Object.keys(Args[0]).some((Key: string) => Key.startsWith('Content'))
13+
&& Object.keys(Args[0]).filter((Key: string) => Key.startsWith('Content')).some((Key: string) => {
14+
return typeof Args[0][Key].render === 'function' && Args[0][Key].render.toString().includes('powerlink')
15+
})) {
16+
let Contents = Object.keys(Args[0]).filter((Key: string) => Key.startsWith('Content')).map((Key: string) => Args[0][Key]) as TPowerLinkContent[]
17+
Contents.map((Content: TPowerLinkContent) => Content.render = () => {})
18+
return Reflect.construct(Target, [Contents, Args[1]], NewTarget)
19+
}
7420
return Reflect.construct(Target, Args, NewTarget)
7521
}
76-
})
77-
78-
Win.Object.prototype.toString = new Proxy(Win.Object.prototype.toString, {
79-
apply(Target: typeof Object.prototype.toString, ThisArg: unknown, Args: []) {
80-
let TensorResult: Array<number> = [0, 0, 0] // string, number, boolean
81-
if (typeof ThisArg === 'object') {
82-
Object.keys(ThisArg).forEach((Key: string) => {
83-
switch (typeof ThisArg[Key]) {
84-
case 'string':
85-
if (ThisArg[Key].length > 5) {
86-
TensorResult[0]++
87-
}
88-
break
89-
case 'number':
90-
TensorResult[1]++
91-
break
92-
case 'boolean':
93-
TensorResult[2]++
94-
break
95-
}
96-
})
97-
}
98-
if (TensorResult.every((Result) => Result >= 3) && typeof ThisArg['content'] !== 'object') {
99-
HideLeftover()
100-
return []
101-
}
102-
return Reflect.apply(Target, ThisArg, Args)
103-
}
10422
})

sources/src/powerlinkcontent.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
2+
/* eslint-disable @typescript-eslint/naming-convention */
3+
type TPowerLinkMixin = {
4+
methods: Record<'contribution_link' | 'contribution_link_discuss' | 'doc_action_link' | 'doc_fulltitle' | 'onDynamicContentClick' | 'openQuickACLGroup' | 'to_duration' | 'url_encode' | 'user_doc' | string, Function>
5+
}
6+
7+
export type TPowerLinkContent = {
8+
emits: string[]
9+
components: Record<string, {
10+
components: {
11+
FakeImg: {
12+
computed: Record<string, Function>
13+
props: Record<string, { type: Function }>
14+
render: Function
15+
__cssModules: {
16+
'$style': {
17+
'wiki-image': string,
18+
'wiki-image-wrapper': string,
19+
},
20+
__scopeId: string
21+
},
22+
NaverLoginImage: string,
23+
NaverPayImage: string,
24+
NaverPayPlusImage: string,
25+
NaverTalkTalkImage: string
26+
},
27+
mixins: TPowerLinkMixin[],
28+
props: Record<string, Function>,
29+
render: Function,
30+
__cssModules: {
31+
'$style': Record<string, string>
32+
__scopeId: string
33+
}
34+
}
35+
}>
36+
props: Record<string, Function>,
37+
render: Function,
38+
__cssModules: {
39+
'$style': Record<string, string>
40+
},
41+
__scopeId: string
42+
__v_skip: boolean
43+
}

0 commit comments

Comments
 (0)