|
20 | 20 |
|
21 | 21 | */
|
22 | 22 |
|
23 |
| -/* eslint-disable indent */ |
24 |
| - |
25 | 23 | // ruleset: $rulesetId$
|
26 | 24 |
|
27 | 25 | // Important!
|
28 | 26 | // Isolate from global scope
|
29 | 27 |
|
30 | 28 | // Start of local scope
|
31 |
| -(( ) => { |
| 29 | +(function uBOL_$scriptletName$() { |
32 | 30 |
|
33 | 31 | /******************************************************************************/
|
34 | 32 |
|
35 |
| -// Start of code to inject |
36 |
| -const uBOL_$scriptletName$ = function() { |
| 33 | +function $scriptletName$(){} |
37 | 34 |
|
38 |
| -const scriptletGlobals = {}; // eslint-disable-line |
| 35 | +/******************************************************************************/ |
39 | 36 |
|
| 37 | +const scriptletGlobals = {}; // eslint-disable-line |
40 | 38 | const argsList = self.$argsList$;
|
41 |
| - |
42 | 39 | const hostnamesMap = new Map(self.$hostnamesMap$);
|
43 |
| - |
44 |
| -const entitiesMap = new Map(self.$entitiesMap$); |
45 |
| - |
46 | 40 | const exceptionsMap = new Map(self.$exceptionsMap$);
|
| 41 | +const hasEntities = self.$hasEntities$; |
| 42 | +const hasAncestors = self.$hasAncestors$; |
47 | 43 |
|
48 |
| -/******************************************************************************/ |
49 |
| - |
50 |
| -function $scriptletName$(){} |
51 |
| - |
52 |
| -/******************************************************************************/ |
53 |
| - |
54 |
| -const hnParts = []; |
55 |
| -try { |
56 |
| - let origin = document.location.origin; |
57 |
| - if ( origin === 'null' ) { |
58 |
| - const origins = document.location.ancestorOrigins || []; |
59 |
| - for ( let i = 0; i < origins.length; i++ ) { |
60 |
| - origin = origins[i]; |
61 |
| - if ( origin !== 'null' ) { break; } |
| 44 | +const collectArgIndices = (hn, map, out) => { |
| 45 | + let argsIndices = map.get(hn); |
| 46 | + if ( argsIndices === undefined ) { return; } |
| 47 | + if ( typeof argsIndices !== 'number' ) { |
| 48 | + for ( const argsIndex of argsIndices ) { |
| 49 | + out.add(argsIndex); |
62 | 50 | }
|
| 51 | + } else { |
| 52 | + out.add(argsIndices); |
63 | 53 | }
|
64 |
| - const beg = origin.lastIndexOf('://'); |
65 |
| - if ( beg === -1 ) { return; } |
66 |
| - let hn = origin.slice(beg+3) |
67 |
| - const end = hn.indexOf(':'); |
68 |
| - if ( end !== -1 ) { hn = hn.slice(0, end); } |
69 |
| - hnParts.push(...hn.split('.')); |
70 |
| -} catch { |
71 |
| -} |
72 |
| -cons
C95D
t hnpartslen = hnParts.length; |
73 |
| -if ( hnpartslen === 0 ) { return; } |
74 |
| - |
75 |
| -const todoIndices = new Set(); |
76 |
| -const tonotdoIndices = []; |
| 54 | +}; |
77 | 55 |
|
78 |
| -// Exceptions |
79 |
| -if ( exceptionsMap.size !== 0 ) { |
| 56 | +const indicesFromHostname = (hostname, suffix = '') => { |
| 57 | + const hnParts = hostname.split('.'); |
| 58 | + const hnpartslen = hnParts.length; |
| 59 | + if ( hnpartslen === 0 ) { return; } |
80 | 60 | for ( let i = 0; i < hnpartslen; i++ ) {
|
81 |
| - const hn = hnParts.slice(i).join('.'); |
82 |
| - const excepted = exceptionsMap.get(hn); |
83 |
| - if ( excepted ) { tonotdoIndices.push(...excepted); } |
| 61 | + const hn = `${hnParts.slice(i).join('.')}${suffix}`; |
| 62 | + collectArgIndices(hn, hostnamesMap, todoIndices); |
| 63 | + collectArgIndices(hn, exceptionsMap, tonotdoIndices); |
84 | 64 | }
|
85 |
| - exceptionsMap.clear(); |
86 |
| -} |
87 |
| - |
88 |
| -// Hostname-based |
89 |
| -if ( hostnamesMap.size !== 0 ) { |
90 |
| - const collectArgIndices = hn => { |
91 |
| - let argsIndices = hostnamesMap.get(hn); |
92 |
| - if ( argsIndices === undefined ) { return; } |
93 |
| - if ( typeof argsIndices === 'number' ) { argsIndices = [ argsIndices ]; } |
94 |
| - for ( const argsIndex of argsIndices ) { |
95 |
| - if ( tonotdoIndices.includes(argsIndex) ) { continue; } |
96 |
| - todoIndices.add(argsIndex); |
| 65 | + if ( hasEntities ) { |
| 66 | + const n = hnpartslen - 1; |
| 67 | + for ( let i = 0; i < n; i++ ) { |
| 68 | + for ( let j = n; j > i; j-- ) { |
| 69 | + const en = `${hnParts.slice(i,j).join('.')}.*${suffix}`; |
| 70 | + collectArgIndices(en, hostnamesMap, todoIndices); |
| 71 | + collectArgIndices(en, exceptionsMap, tonotdoIndices); |
| 72 | + } |
97 | 73 | }
|
98 |
| - }; |
99 |
| - for ( let i = 0; i < hnpartslen; i++ ) { |
100 |
| - const hn = hnParts.slice(i).join('.'); |
101 |
| - collectArgIndices(hn); |
102 | 74 | }
|
103 |
| - collectArgIndices('*'); |
104 |
| - hostnamesMap.clear(); |
105 |
| -} |
| 75 | +}; |
106 | 76 |
|
107 |
| -// Entity-based |
108 |
| -if ( entitiesMap.size !== 0 ) { |
109 |
| - const n = hnpartslen - 1; |
110 |
| - for ( let i = 0; i < n; i++ ) { |
111 |
| - for ( let j = n; j > i; j-- ) { |
112 |
| - const en = hnParts.slice(i,j).join('.'); |
113 |
| - let argsIndices = entitiesMap.get(en); |
114 |
| - if ( argsIndices === undefined ) { continue; } |
115 |
| - if ( typeof argsIndices === 'number' ) { argsIndices = [ argsIndices ]; } |
116 |
| - for ( const argsIndex of argsIndices ) { |
117 |
| - if ( tonotdoIndices.includes(argsIndex) ) { continue; } |
118 |
| - todoIndices.add(argsIndex); |
119 |
| - } |
120 |
| - } |
| 77 | +const entries = (( ) => { |
| 78 | + const docloc = document.location; |
| 79 | + const origins = [ docloc.origin ]; |
| 80 | + if ( docloc.ancestorOrigins ) { |
| 81 | + origins.push(...docloc.ancestorOrigins); |
| 82 | + } |
| 83 | + return origins.map((origin, i) => { |
| 84 | + const beg = origin.lastIndexOf('://'); |
| 85 | + if ( beg === -1 ) { return; } |
| 86 | + const hn = origin.slice(beg+3) |
| 87 | + const end = hn.indexOf(':'); |
| 88 | + return { hn: end === -1 ? hn : hn.slice(0, end), i }; |
| 89 | + }).filter(a => a !== undefined); |
| 90 | +})(); |
| 91 | +if ( entries.length === 0 ) { return; } |
| 92 | + |
| 93 | +const todoIndices = new Set(); |
| 94 | +const tonotdoIndices = new Set(); |
| 95 | + |
| 96 | +indicesFromHostname(entries[0].hn); |
| 97 | +if ( hasAncestors ) { |
| 98 | + for ( const entry of entries ) { |
| 99 | + if ( entry.i === 0 ) { continue; } |
| 100 | + indicesFromHostname(entry.hn, '>>'); |
121 | 101 | }
|
122 |
| - entitiesMap.clear(); |
123 | 102 | }
|
124 | 103 |
|
125 | 104 | // Apply scriplets
|
126 | 105 | for ( const i of todoIndices ) {
|
| 106 | + if ( tonotdoIndices.has(i) ) { continue; } |
127 | 107 | try { $scriptletName$(...argsList[i]); }
|
128 | 108 | catch { }
|
129 | 109 | }
|
130 |
| -argsList.length = 0; |
131 |
| - |
132 |
| -/******************************************************************************/ |
133 |
| - |
134 |
| -}; |
135 |
| -// End of code to inject |
136 |
| - |
137 |
| -/******************************************************************************/ |
138 |
| - |
139 |
| -uBOL_$scriptletName$(); |
140 | 110 |
|
141 | 111 | /******************************************************************************/
|
142 | 112 |
|
143 | 113 | // End of local scope
|
144 | 114 | })();
|
145 | 115 |
|
146 |
| -/******************************************************************************/ |
147 |
| - |
148 | 116 | void 0;
|