Skip to content

Commit

Permalink
feat: handling Object type
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Dec 26, 2024
1 parent e61461c commit ed85e6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@list-kr/namulink",
"version": "5.0.3",
"version": "5.1.0",
"description": "",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion sources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// @downloadURL https://cdn.jsdelivr.net/npm/@list-kr/namulink@latest/dist/NamuLink.user.js
// @license MIT
//
// @version 5.0.3
// @version 5.1.0
// @author PiQuark6046 and contributors
//
// @match https://namu.wiki/*
Expand Down
31 changes: 21 additions & 10 deletions sources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ 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 TargetEle.innerText === '' && Number(getComputedStyle(TargetEle).getPropertyValue('margin-top').replace('px', '')) > 15
}).forEach((TargetEle: HTMLElement) => {
TargetEle.setAttribute('style', 'visibility: hidden !important; width: 1px !important; height: 1px !important;')
})
}, 5000)
}

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' && /^[A-Za-z0-9-+]+\/\/\/.+=?/.test(Args[0][0][1])) {
setTimeout(() => {
Array.from(document.querySelectorAll('div[class*=" "] div[class]')).filter((TargetEle: HTMLElement) => {
return TargetEle.innerText === '' && Array.from(TargetEle.querySelectorAll('*')).filter((ChildEle: HTMLElement) => {
return getComputedStyle(ChildEle).getPropertyValue('animation').includes('infinite')
}).length >= 6
}).forEach((TargetEle: HTMLElement) => {
TargetEle.setAttribute('style', 'visibility: hidden !important; width: 1px !important; height: 1px !important;')
})
}, 5000)
&& typeof Args[0][0][1] === 'string' && RegExPatterns.some((Pattern: RegExp) => Pattern.test(Args[0][0][1]))) {
HideLeftover()
return
}
if (typeof Args[0] === 'object' && Object.keys(Args[0]).some((Key: string) => RegExPatterns.some((Pattern: RegExp) => Pattern.test(Args[0][Key])))) {
HideLeftover()
return
}
return Reflect.construct(Target, Args, NewTarget)
Expand Down

0 comments on commit ed85e6c

Please sign in to comment.