Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update new version of espejo #72

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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