Skip to content

Commit

Permalink
feat: update new version of espejo (#69)
Browse files Browse the repository at this point in the history
* feat: update new version of espejo

* chore: update version

* build userscript
  • Loading branch information
piquark6046 authored Apr 30, 2024
1 parent 1b5c891 commit 2983e6e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 53 deletions.
4 changes: 2 additions & 2 deletions NamuLink.user.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "namulink",
"version": "3.6.0",
"version": "3.7.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/gh/List-KR/NamuLink@latest/NamuLink.user.js
// @license MIT
//
// @version 3.6.0
// @version 3.7.0
// @author PiQuark6046 and contributors
//
// @match https://namu.wiki/*
Expand Down
55 changes: 6 additions & 49 deletions sources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,22 @@ const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window

const NagivationAdvertEvent = new Event('namuwikinavigationwithadvert')
const NagivationEvent = new Event('namuwikinavigation')
const FristVisitEvent = new Event('namuwikifristvisit')

Win.Function.prototype.apply = new Proxy(Win.Function.prototype.apply, {
apply(Target, ThisArg, Args) {
// eslint-disable-next-line @typescript-eslint/ban-types
if (typeof ThisArg === 'function' && (ThisArg as Function).toString().includes('fromCharCode') && Args[0] === null
&& Args[1] instanceof Uint16Array && new TextDecoder().decode(Args[1]).replaceAll('\x00', '').includes('adcr.naver.com')) {
const IsUint16Array = typeof ThisArg === 'function' && (ThisArg as Function).toString().includes('fromCharCode')
&& Args[0] === null && Args[1] instanceof Uint16Array
if (IsUint16Array && new TextDecoder().decode(Args[1]).replaceAll('\x00', '').includes('adcr?x=')) {
console.debug('[NamuLink:index]: Function.prototype.apply:', ThisArg, Args)
Win.dispatchEvent(FristVisitEvent)
Win.dispatchEvent(NagivationAdvertEvent)
return
throw new Error()
}
return Reflect.apply(Target, ThisArg, Args)
}
})

Win.Array.prototype.join = new Proxy(Win.Array.prototype.join, {
apply(Target, ThisArg, Args) {
if (typeof ThisArg === 'undefined' || typeof Args === 'undefined') {
return
}
const Result = Reflect.apply(Target, ThisArg, Args)
if (Result.includes('adcr.naver.com')) {
Win.dispatchEvent(FristVisitEvent)
Win.dispatchEvent(NagivationAdvertEvent)
return
}
return Result
},
})
const ConvertObjToStringSafe = (ObjectParam: object) => {
var Result = ''
try {
Result = JSON.stringify(ObjectParam, (Key, Value) => {
if (typeof Value === 'function') {
return Value.toString()
}
return Value
})
} catch { /* empty */ }
return Result
}

Win.Object.defineProperty = new Proxy(Win.Object.defineProperty, {
apply(Target, ThisArg, Args) {
const Result = ConvertObjToStringSafe(Args)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
if (Result.includes('adcr.naver.com')) {
return
}

if (Array.isArray(Args) && Args.every(Subvalue => Array.isArray(Subvalue) && Subvalue.some(SubSubvalue => {
return typeof SubSubvalue == 'string' && SubSubvalue === 'div'
}))) {
if (IsUint16Array && new TextDecoder().decode(Args[1]).replaceAll('\x00', '').includes('wiki.')) {
Win.dispatchEvent(NagivationEvent)
}

return Reflect.apply(Target, ThisArg, Args)
},
}
})

var HiddenElements: HTMLElement[] = []
Expand Down

0 comments on commit 2983e6e

Please sign in to comment.