@@ -4,84 +4,88 @@ declare const unsafeWindow: unsafeWindow
44
55const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
66
7- function GetParents ( Ele : HTMLElement ) {
8- let Parents : HTMLElement [ ] = [ ]
9- while ( Ele . parentElement ) {
10- Parents . push ( Ele . parentElement )
11- Ele = Ele . parentElement
7+ export function RunNamuLinkUserscript ( BrowserWindow : typeof window , UserscriptName : string = 'NamuLink' ) : void {
8+ function GetParents ( Ele : HTMLElement ) {
9+ let Parents : HTMLElement [ ] = [ ]
10+ while ( Ele . parentElement ) {
11+ Parents . push ( Ele . parentElement )
12+ Ele = Ele . parentElement
13+ }
14+ return Parents
1215 }
13- return Parents
14- }
1516
16- setInterval ( ( ) => {
17- if ( location . href . startsWith ( 'https://namu.wiki/w/' ) ) {
18- let AdContainers = Array . from ( document . querySelectorAll ( 'div[class*=" "] div[class]' ) ) . filter ( AdContainer => AdContainer instanceof HTMLElement )
17+ setInterval ( ( ) => {
18+ if ( location . href . startsWith ( 'https://namu.wiki/w/' ) ) {
19+ let AdContainers = Array . from ( document . querySelectorAll ( 'div[class*=" "] div[class]' ) ) . filter ( AdContainer => AdContainer instanceof HTMLElement )
1920
20- AdContainers = AdContainers . filter ( ( AdContainer ) => {
21- let AdContainerPaddingLeft = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-left' ) . replaceAll ( 'px' , '' ) )
22- let AdContainerPaddingRight = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-right' ) . replaceAll ( 'px' , '' ) )
23- let AdContainerPaddingTop = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-top' ) . replaceAll ( 'px' , '' ) )
24- let AdContainerPaddingBottom = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-bottom' ) . replaceAll ( 'px' , '' ) )
25- return AdContainerPaddingLeft > 5 && AdContainerPaddingRight > 5 && AdContainerPaddingTop > 5 && AdContainerPaddingBottom > 5
26- } )
21+ AdContainers = AdContainers . filter ( ( AdContainer ) => {
22+ let AdContainerPaddingLeft = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-left' ) . replaceAll ( 'px' , '' ) )
23+ let AdContainerPaddingRight = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-right' ) . replaceAll ( 'px' , '' ) )
24+ let AdContainerPaddingTop = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-top' ) . replaceAll ( 'px' , '' ) )
25+ let AdContainerPaddingBottom = Number ( getComputedStyle ( AdContainer ) . getPropertyValue ( 'padding-bottom' ) . replaceAll ( 'px' , '' ) )
26+ return AdContainerPaddingLeft > 5 && AdContainerPaddingRight > 5 && AdContainerPaddingTop > 5 && AdContainerPaddingBottom > 5
27+ } )
2728
28- AdContainers = AdContainers . filter ( AdContainer => {
29- return Array . from ( AdContainer . querySelectorAll ( '*' ) ) . filter ( Ele => Ele instanceof HTMLElement &&
30- getComputedStyle ( Ele ) . getPropertyValue ( 'animation-timing-function' ) === 'ease-in-out' ) . length >= 3
31- } )
29+ AdContainers = AdContainers . filter ( AdContainer => {
30+ return Array . from ( AdContainer . querySelectorAll ( '*' ) ) . filter ( Ele => Ele instanceof HTMLElement &&
31+ getComputedStyle ( Ele ) . getPropertyValue ( 'animation-timing-function' ) === 'ease-in-out' ) . length >= 3
32+ } )
3233
33- AdContainers = AdContainers . filter ( AdContainer => GetParents ( AdContainer ) . some ( Parent => Number ( getComputedStyle ( Parent ) . getPropertyValue ( 'margin-top' ) . replaceAll ( 'px' , '' ) ) > 10 ) )
34+ AdContainers = AdContainers . filter ( AdContainer => GetParents ( AdContainer ) . some ( Parent => Number ( getComputedStyle ( Parent ) . getPropertyValue ( 'margin-top' ) . replaceAll ( 'px' , '' ) ) > 10 ) )
3435
35- AdContainers = AdContainers . filter ( AdContainer => AdContainer . innerText . length < 1000 )
36+ AdContainers = AdContainers . filter ( AdContainer => AdContainer . innerText . length < 1000 )
3637
37- AdContainers = AdContainers . filter ( AdContainer => Array . from ( AdContainer . querySelectorAll ( '*[href="/RecentChanges"]' ) ) . filter ( Ele => Ele instanceof HTMLElement && getComputedStyle ( Ele ) . getPropertyValue ( 'display' ) !== 'none' ) . length === 0 )
38+ AdContainers = AdContainers . filter ( AdContainer => Array . from ( AdContainer . querySelectorAll ( '*[href="/RecentChanges"]' ) ) . filter ( Ele => Ele instanceof HTMLElement && getComputedStyle ( Ele ) . getPropertyValue ( 'display' ) !== 'none' ) . length === 0 )
3839
39- AdContainers = AdContainers . filter ( AdContainer => ! AdContainer . innerText . includes ( ( new URL ( location . href ) . searchParams . get ( 'from' ) || '' ) + '에서 넘어옴' ) )
40+ AdContainers = AdContainers . filter ( AdContainer => ! AdContainer . innerText . includes ( ( new URL ( location . href ) . searchParams . get ( 'from' ) || '' ) + '에서 넘어옴' ) )
4041
41- AdContainers = AdContainers . filter ( AdContainer => ! / \[ [ 0 - 9 ] + \] .+ / . test ( AdContainer . innerText ) )
42+ AdContainers = AdContainers . filter ( AdContainer => ! / \[ [ 0 - 9 ] + \] .+ / . test ( AdContainer . innerText ) )
4243
43- AdContainers . forEach ( Ele => Ele . remove ( ) )
44- }
45- } , 1000 )
46-
47- let PowerLinkGenerationPositiveRegExps : RegExp [ ] [ ] = [ [
48- / f o r * \( * ; * ; * \) * s w i t c h * \( * _ [ a - z 0 - 9 ] + \[ _ [ a - z 0 - 9 ] + \( [ a - z 0 - 9 ] + \) \] * = _ [ a - z 0 - 9 ] + / ,
49- / _ [ a - z 0 - 9 ] + \[ ( ' | " ) [ A - Z ] + ( ' | " ) \] \) \( \[ * \] \) / ,
50- / 0 x [ a - z 0 - 9 ] + * \) * ; * c a s e /
51- ] , [
52- / ; * r e t u r n * t h i s \[ _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - z ] + * \) / ,
53- / ; * i f * \( * _ 0 x [ a - z 0 - 9 ] + * & & * \( * _ 0 x [ a - z 0 - 9 ] + * = * _ 0 x [ a - z 0 - 9 ] + / ,
54- / \) * , * v o i d * \( * t h i s * \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - z ] + * \) * \] * = * _ 0 x [ a - z 0 - 9 ] + * \[ /
55- ] ]
56-
57- Win . Function . prototype . bind = new Proxy ( Win . Function . prototype . bind , {
58- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
59- apply ( Target : typeof Function . prototype . bind , ThisArg : Function , Args : Parameters < typeof Function . prototype . bind > ) {
60- let StringifiedFunc = ThisArg . toString ( )
61- if ( PowerLinkGenerationPositiveRegExps . filter ( PowerLinkGenerationPositiveRegExp => PowerLinkGenerationPositiveRegExp . filter ( Index => Index . test ( StringifiedFunc ) ) . length >= 3 ) . length === 1 ) {
62- console . debug ( '[NamuLink] Function.prototype.bind:' , ThisArg )
63- return Reflect . apply ( Target , ( ) => { } , [ ] )
44+ AdContainers . forEach ( Ele => Ele . remove ( ) )
6445 }
65- return Reflect . apply ( Target , ThisArg , Args )
66- }
67- } )
68-
69- let PowerLinkGenerationSkeletionPositiveRegExps : RegExp [ ] [ ] = [ [
70- / \( * \) * = > * { * v a r * _ 0 x [ 0 - 9 a - z ] + * = * a 0 _ 0 x [ 0 - 9 a - f ] + * ; * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] \( \) ; * } / ,
71- / \( * \) * = > * { * v a r * _ 0 x [ 0 - 9 a - z ] + * = * a 0 _ 0 x [ 0 - 9 a - f ] + * ; * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] \( \) ; * } /
72- ] , [
73- / \( * \) * = > * { * v a r _ 0 x [ a - z 0 - 9 ] + * = * _ 0 x [ a - z 0 - 9 ] + * ; * i f * \( * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + * \( * 0 x [ 0 - 9 a - f ] + * \) * \] * \) * r e t u r n * c l e a r T i m e o u t / ,
74- / \( * 0 x [ 0 - 9 a - f ] + * \) * \] * \) * , * v o i d * \( * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] * = * v o i d * \( [ x 0 - 9 a - f * + - ] + * \) * \) * ; * t h i s \[ _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] * \( \) * ; /
75- ] ]
76-
77- Win . setTimeout = new Proxy ( Win . setTimeout , {
78- apply ( Target : typeof setTimeout , ThisArg : undefined , Args : Parameters < typeof setTimeout > ) {
79- let StringifiedFunc = Args [ 0 ] . toString ( )
80- if ( PowerLinkGenerationSkeletionPositiveRegExps . filter ( PowerLinkGenerationSkeletionPositiveRegExp => PowerLinkGenerationSkeletionPositiveRegExp . filter ( Index => Index . test ( StringifiedFunc ) ) . length >= 1 ) . length === 1 ) {
81- console . debug ( '[NamuLink] setTimeout:' , Args [ 0 ] )
82- return
46+ } , 1000 )
47+
48+ let PowerLinkGenerationPositiveRegExps : RegExp [ ] [ ] = [ [
49+ / f o r * \( * ; * ; * \) * s w i t c h * \( * _ [ a - z 0 - 9 ] + \[ _ [ a - z 0 - 9 ] + \( [ a - z 0 - 9 ] + \) \] * = _ [ a - z 0 - 9 ] + / ,
50+ / _ [ a - z 0 - 9 ] + \[ ( ' | " ) [ A - Z ] + ( ' | " ) \] \) \( \[ * \] \) / ,
51+ / 0 x [ a - z 0 - 9 ] + * \) * ; * c a s e /
52+ ] , [
53+ / ; * r e t u r n * t h i s \[ _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - z ] + * \) / ,
54+ / ; * i f * \( * _ 0 x [ a - z 0 - 9 ] + * & & * \( * _ 0 x [ a - z 0 - 9 ] + * = * _ 0 x [ a - z 0 - 9 ] + / ,
55+ / \) * , * v o i d * \( * t h i s * \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - z ] + * \) * \] * = * _ 0 x [ a - z 0 - 9 ] + * \[ /
56+ ] ]
57+
58+ BrowserWindow . Function . prototype . bind = new Proxy ( BrowserWindow . Function . prototype . bind , {
59+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
60+ apply ( Target : typeof Function . prototype . bind , ThisArg : Function , Args : Parameters < typeof Function . prototype . bind > ) {
61+ let StringifiedFunc = ThisArg . toString ( )
62+ if ( PowerLinkGenerationPositiveRegExps . filter ( PowerLinkGenerationPositiveRegExp => PowerLinkGenerationPositiveRegExp . filter ( Index => Index . test ( StringifiedFunc ) ) . length >= 3 ) . length === 1 ) {
63+ console . debug ( `[${ UserscriptName } ]: Function.prototype.bind:` , ThisArg )
64+ return Reflect . apply ( Target , ( ) => { } , [ ] )
65+ }
66+ return Reflect . apply ( Target , ThisArg , Args )
8367 }
68+ } )
69+
70+ let PowerLinkGenerationSkeletionPositiveRegExps : RegExp [ ] [ ] = [ [
71+ / \( * \) * = > * { * v a r * _ 0 x [ 0 - 9 a - z ] + * = * a 0 _ 0 x [ 0 - 9 a - f ] + * ; * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] \( \) ; * } / ,
72+ / \( * \) * = > * { * v a r * _ 0 x [ 0 - 9 a - z ] + * = * a 0 _ 0 x [ 0 - 9 a - f ] + * ; * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] \( \) ; * } /
73+ ] , [
74+ / \( * \) * = > * { * v a r _ 0 x [ a - z 0 - 9 ] + * = * _ 0 x [ a - z 0 - 9 ] + * ; * i f * \( * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + * \( * 0 x [ 0 - 9 a - f ] + * \) * \] * \) * r e t u r n * c l e a r T i m e o u t / ,
75+ / \( * 0 x [ 0 - 9 a - f ] + * \) * \] * \) * , * v o i d * \( * t h i s \[ * _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] * = * v o i d * \( [ x 0 - 9 a - f * + - ] + * \) * \) * ; * t h i s \[ _ 0 x [ a - z 0 - 9 ] + \( * 0 x [ 0 - 9 a - f ] + * \) * \] * \( \) * ; /
76+ ] ]
77+
78+ BrowserWindow . setTimeout = new Proxy ( BrowserWindow . setTimeout , {
79+ apply ( Target : typeof setTimeout , ThisArg : undefined , Args : Parameters < typeof setTimeout > ) {
80+ let StringifiedFunc = Args [ 0 ] . toString ( )
81+ if ( PowerLinkGenerationSkeletionPositiveRegExps . filter ( PowerLinkGenerationSkeletionPositiveRegExp => PowerLinkGenerationSkeletionPositiveRegExp . filter ( Index => Index . test ( StringifiedFunc ) ) . length >= 1 ) . length === 1 ) {
82+ console . debug ( `[${ UserscriptName } ]: setTimeout:` , Args [ 0 ] )
83+ return
84+ }
85+
86+ return Reflect . apply ( Target , ThisArg , Args )
87+ }
88+ } )
89+ }
8490
85- return Reflect . apply ( Target , ThisArg , Args )
86- }
87- } )
91+ RunNamuLinkUserscript ( Win )
0 commit comments