@@ -15,6 +15,8 @@ declare const unsafeWindow: unsafeWindow
1515const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
1616
1717export function RunNamuLinkUserscript ( BrowserWindow : typeof window , UserscriptName : string = 'NamuLink' ) : void {
18+ const ProtectedFunctionPrototypeToString = BrowserWindow . Function . prototype . toString
19+
1820 function GetParents ( Ele : HTMLElement ) {
1921 let Parents : HTMLElement [ ] = [ ]
2022 while ( Ele . parentElement ) {
@@ -68,7 +70,7 @@ export function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptNa
6870 BrowserWindow . Function . prototype . bind = new Proxy ( BrowserWindow . Function . prototype . bind , {
6971 // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
7072 apply ( Target : typeof Function . prototype . bind , ThisArg : Function , Args : Parameters < typeof Function . prototype . bind > ) {
71- let StringifiedFunc = ThisArg . toString ( )
73+ let StringifiedFunc = Reflect . apply ( ProtectedFunctionPrototypeToString , ThisArg , Args ) as string
7274 if ( PowerLinkGenerationPositiveRegExps . filter ( PowerLinkGenerationPositiveRegExp => PowerLinkGenerationPositiveRegExp . filter ( Index => Index . test ( StringifiedFunc ) ) . length >= 3 ) . length === 1 ) {
7375 console . debug ( `[${ UserscriptName } ]: Function.prototype.bind:` , ThisArg )
7476 return Reflect . apply ( Target , ( ) => { } , [ ] )
@@ -87,7 +89,7 @@ export function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptNa
8789
8890 BrowserWindow . setTimeout = new Proxy ( BrowserWindow . setTimeout , {
8991 apply ( Target : typeof setTimeout , ThisArg : undefined , Args : Parameters < typeof setTimeout > ) {
90- let StringifiedFunc = Args [ 0 ] . toString ( )
92+ let StringifiedFunc = Reflect . apply ( ProtectedFunctionPrototypeToString , Args [ 0 ] , Args ) as string
9193 if ( PowerLinkGenerationSkeletionPositiveRegExps . filter ( PowerLinkGenerationSkeletionPositiveRegExp => PowerLinkGenerationSkeletionPositiveRegExp . filter ( Index => Index . test ( StringifiedFunc ) ) . length >= 1 ) . length === 1 ) {
9294 console . debug ( `[${ UserscriptName } ]: setTimeout:` , Args [ 0 ] )
9395 return
0 commit comments