Skip to content

Commit

Permalink
feat: update new version of espejo (#72)
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 May 1, 2024
1 parent 152f8a4 commit 29eb4ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 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.7.1",
"version": "3.8.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.7.1
// @version 3.8.0
// @author PiQuark6046 and contributors
//
// @match https://namu.wiki/*
Expand Down
28 changes: 17 additions & 11 deletions sources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
const NagivationAdvertEvent = new Event('namuwikinavigationwithadvert')
const NagivationEvent = new Event('namuwikinavigation')

Win.Function.prototype.apply = new Proxy(Win.Function.prototype.apply, {
apply(Target, ThisArg, Args) {
// eslint-disable-next-line @typescript-eslint/ban-types
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(NagivationAdvertEvent)
throw new Error()
Win.fetch = new Proxy(Win.fetch, {
async apply(Target, ThisArg, Args) {
const Result = Reflect.apply(Target, ThisArg, Args)
if (typeof Args[0] === 'string' && /^\/i\/[a-zA-Z0-9_-]{200,}/.test(Args[0]) && (Args[1] as RequestInit).method === 'GET') {
const ResultCloned = await (Result as Promise<Response>).then(Response => Response.clone())
if ((await ResultCloned.arrayBuffer()).byteLength > 1000) {
Win.dispatchEvent(NagivationAdvertEvent)
}
}
if (IsUint16Array && new TextDecoder().decode(Args[1]).replaceAll('\x00', '').startsWith('wiki/i')) {
return Result
}
})

Win.Array.prototype.join = new Proxy(Win.Array.prototype.join, {
apply(Target, ThisArg, Args) {
const Result = Reflect.apply(Target, ThisArg, Args)
if ((Result as string).startsWith('noscript[data-n-head="]')) {
Win.dispatchEvent(NagivationEvent)
}
return Reflect.apply(Target, ThisArg, Args)
return Result
}
})

Expand Down

0 comments on commit 29eb4ab

Please sign in to comment.