-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mock namuwiki internal function
- Loading branch information
1 parent
187a85f
commit de156b8
Showing
2 changed files
with
53 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,22 @@ | ||
import type { TPowerLinkContent } from './powerlinkcontent.js' | ||
|
||
type unsafeWindow = typeof window | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
declare const unsafeWindow: unsafeWindow | ||
|
||
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window | ||
|
||
let HideLeftover = () => { | ||
setInterval(() => { | ||
Array.from(document.querySelectorAll('div[class*=" "] div[class]')).filter((TargetEle: HTMLElement) => { | ||
return (Array.from(TargetEle.querySelectorAll('*')).filter((ChildEle: HTMLElement) => { | ||
return getComputedStyle(ChildEle).getPropertyValue('animation').includes('infinite') | ||
}).length >= 6 || TargetEle.innerText === '' || TargetEle.innerText.includes('파워링크')) && | ||
(Number(getComputedStyle(TargetEle).getPropertyValue('margin-top').replace('px', '')) > 10 || Number(getComputedStyle(TargetEle).getPropertyValue('margin-bottom').replace('px', '')) > 10) && | ||
Number(getComputedStyle(TargetEle).getPropertyValue('height').replace('px', '')) < 350 | ||
}).forEach((TargetEle: HTMLElement) => { | ||
TargetEle.setAttribute('style', 'visibility: hidden !important; width: 1px !important; height: 1px !important;') | ||
}) | ||
}, 2500) | ||
} | ||
|
||
let RegExPatterns: RegExp[] = [ | ||
/^#x=[A-Za-z0-9-+]+\/\/\/.+=?$/, | ||
/^[A-Za-z0-9+\/]+\/{3,}w=+/ | ||
] | ||
|
||
Win.Proxy = new Proxy(Win.Proxy, { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type | ||
construct<T extends object>(Target: ProxyConstructor, Args: [T, ProxyHandler<T>], NewTarget: Function): object { | ||
if (typeof Args[0] === 'object' && Array.isArray(Args[0]) && typeof Args[0][0] === 'object' && Array.isArray(Args[0][0]) | ||
&& typeof Args[0][0][1] === 'string' && RegExPatterns.some((Pattern: RegExp) => Pattern.test(Args[0][0][1]))) { | ||
HideLeftover() | ||
return Reflect.construct(Target, [Args[0], ['파워링크']], NewTarget) | ||
} | ||
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])))) { | ||
HideLeftover() | ||
let ArgsObj = Args[0] | ||
Object.keys(ArgsObj).map((Key: string) => { | ||
if (typeof ArgsObj[Key] === 'string') { | ||
ArgsObj[Key] = '파워링크' | ||
} | ||
}) | ||
return Reflect.construct(Target, [Args[0], ArgsObj], NewTarget) | ||
} | ||
if (typeof Args[0] === 'object' && Object.keys(Args[0]).some((Key: string) => typeof Args[0][Key] === 'string' && | ||
(Args[0][Key].includes('searchad.naver.com') || Args[0][Key].includes('saedu.naver.com/adbiz/')))) { | ||
HideLeftover() | ||
return | ||
} | ||
|
||
// Object inner section analysis | ||
let TensorResult: Array<number> = [0, 0, 0] // string, number, boolean | ||
if (typeof Args[0] === 'object') { | ||
Object.keys(Args[0]).forEach((Key: string) => { | ||
switch (typeof Args[0][Key]) { | ||
case 'string': | ||
if (Args[0][Key].length > 5) { | ||
TensorResult[0]++ | ||
} | ||
break | ||
case 'number': | ||
TensorResult[1]++ | ||
break | ||
case 'boolean': | ||
TensorResult[2]++ | ||
break | ||
} | ||
}) | ||
} | ||
if (TensorResult.every((Result) => Result >= 3) && typeof Args[0]['content'] !== 'object') { | ||
HideLeftover() | ||
return Reflect.construct(Target, [Args[0], ['파워링크']], NewTarget) | ||
} | ||
// | ||
if (typeof Args[0] === 'object' && Object.keys(Args[0]).some((Key: string) => Key.startsWith('Content')) | ||
&& Object.keys(Args[0]).filter((Key: string) => Key.startsWith('Content')).some((Key: string) => { | ||
return typeof Args[0][Key].render === 'function' && Args[0][Key].render.toString().includes('powerlink') | ||
})) { | ||
let Contents = Object.keys(Args[0]).filter((Key: string) => Key.startsWith('Content')).map((Key: string) => Args[0][Key]) as TPowerLinkContent[] | ||
Contents.map((Content: TPowerLinkContent) => Content.render = () => {}) | ||
return Reflect.construct(Target, [Contents, Args[1]], NewTarget) | ||
} | ||
return Reflect.construct(Target, Args, NewTarget) | ||
} | ||
}) | ||
|
||
Win.Object.prototype.toString = new Proxy(Win.Object.prototype.toString, { | ||
apply(Target: typeof Object.prototype.toString, ThisArg: unknown, Args: []) { | ||
let TensorResult: Array<number> = [0, 0, 0] // string, number, boolean | ||
if (typeof ThisArg === 'object') { | ||
Object.keys(ThisArg).forEach((Key: string) => { | ||
switch (typeof ThisArg[Key]) { | ||
case 'string': | ||
if (ThisArg[Key].length > 5) { | ||
TensorResult[0]++ | ||
} | ||
break | ||
case 'number': | ||
TensorResult[1]++ | ||
break | ||
case 'boolean': | ||
TensorResult[2]++ | ||
break | ||
} | ||
}) | ||
} | ||
if (TensorResult.every((Result) => Result >= 3) && typeof ThisArg['content'] !== 'object') { | ||
HideLeftover() | ||
return [] | ||
} | ||
return Reflect.apply(Target, ThisArg, Args) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-function-type */ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
type TPowerLinkMixin = { | ||
methods: Record<'contribution_link' | 'contribution_link_discuss' | 'doc_action_link' | 'doc_fulltitle' | 'onDynamicContentClick' | 'openQuickACLGroup' | 'to_duration' | 'url_encode' | 'user_doc' | string, Function> | ||
} | ||
|
||
export type TPowerLinkContent = { | ||
emits: string[] | ||
components: Record<string, { | ||
components: { | ||
FakeImg: { | ||
computed: Record<string, Function> | ||
props: Record<string, { type: Function }> | ||
render: Function | ||
__cssModules: { | ||
'$style': { | ||
'wiki-image': string, | ||
'wiki-image-wrapper': string, | ||
}, | ||
__scopeId: string | ||
}, | ||
NaverLoginImage: string, | ||
NaverPayImage: string, | ||
NaverPayPlusImage: string, | ||
NaverTalkTalkImage: string | ||
}, | ||
mixins: TPowerLinkMixin[], | ||
props: Record<string, Function>, | ||
render: Function, | ||
__cssModules: { | ||
'$style': Record<string, string> | ||
__scopeId: string | ||
} | ||
} | ||
}> | ||
props: Record<string, Function>, | ||
render: Function, | ||
__cssModules: { | ||
'$style': Record<string, string> | ||
}, | ||
__scopeId: string | ||
__v_skip: boolean | ||
} |