21
21
22
22
import { dom , qs$ } from './dom.js' ;
23
23
import { i18n , i18n$ } from './i18n.js' ;
24
+ import { faIconsInit } from './fa-icons.js' ;
24
25
25
26
/******************************************************************************/
26
27
27
28
const messaging = vAPI . messaging ;
28
- let details = { } ;
29
+ const details = { } ;
29
30
30
31
{
31
32
const matches = / d e t a i l s = ( [ ^ & ] + ) / . exec ( window . location . search ) ;
32
33
if ( matches !== null ) {
33
- details = JSON . parse ( decodeURIComponent ( matches [ 1 ] ) ) ;
34
+ Object . assign ( details , JSON . parse ( decodeURIComponent ( matches [ 1 ] ) ) ) ;
34
35
}
35
36
}
36
37
37
38
/******************************************************************************/
38
39
39
- ( async ( ) => {
40
- const response = await messaging . send ( 'documentBlocked' , {
41
- what : 'listsFromNetFilter' ,
42
- rawFilter : details . fs ,
43
- } ) ;
44
- if ( response instanceof Object === false ) { return ; }
45
-
46
- let lists ;
47
- for ( const rawFilter in response ) {
48
- if ( Object . hasOwn ( response , rawFilter ) ) {
49
- lists = response [ rawFilter ] ;
50
- break ;
51
- }
52
- }
53
-
54
- if ( Array . isArray ( lists ) === false || lists . length === 0 ) {
55
- qs$ ( '#whyex' ) . style . setProperty ( 'visibility' , 'collapse' ) ;
56
- return ;
57
- }
58
-
59
- const parent = qs$ ( '#whyex > ul' ) ;
60
- parent . firstElementChild . remove ( ) ; // remove placeholder element
61
- for ( const list of lists ) {
62
- const listElem = dom . clone ( '#templates .filterList' ) ;
63
- const sourceElem = qs$ ( listElem , '.filterListSource' ) ;
64
- sourceElem . href += encodeURIComponent ( list . assetKey ) ;
65
- sourceElem . append ( i18n . patchUnicodeFlags ( list . title ) ) ;
66
- if ( typeof list . supportURL === 'string' && list . supportURL !== '' ) {
67
- const supportElem = qs$ ( listElem , '.filterListSupport' ) ;
68
- dom . attr ( supportElem , 'href' , list . supportURL ) ;
69
- dom . cl . remove ( supportElem , 'hidden' ) ;
70
- }
71
- parent . appendChild ( listElem ) ;
72
- }
73
- qs$ ( '#whyex' ) . style . removeProperty ( 'visibility' ) ;
74
- } ) ( ) ;
75
-
76
- /******************************************************************************/
77
-
78
40
const urlToFragment = raw => {
79
41
try {
80
42
const fragment = new DocumentFragment ( ) ;
@@ -94,7 +56,26 @@ const urlToFragment = raw => {
94
56
95
57
dom . clear ( '#theURL > p > span:first-of-type' ) ;
96
58
qs$ ( '#theURL > p > span:first-of-type' ) . append ( urlToFragment ( details . url ) ) ;
97
- dom . text ( '#why' , details . fs ) ;
59
+
60
+ /******************************************************************************/
61
+
62
+ const lookupFilterLists = async ( ) => {
63
+ const response = await messaging . send ( 'documentBlocked' , {
64
+ what : 'listsFromNetFilter' ,
65
+ rawFilter : details . fs ,
66
+ } ) ;
67
+ if ( response instanceof Object === false ) { return ; }
68
+ let lists ;
69
+ for ( const rawFilter in response ) {
70
+ if ( Object . hasOwn ( response , rawFilter ) ) {
71
+ lists = response [ rawFilter ] ;
72
+ break ;
73
+ }
74
+ }
75
+ return lists ;
76
+ } ;
77
+
78
+ /******************************************************************************/
98
79
99
80
if ( typeof details . to === 'string' && details . to . length !== 0 ) {
100
81
const fragment = new DocumentFragment ( ) ;
@@ -221,18 +202,14 @@ if ( window.history.length > 1 ) {
221
202
222
203
/******************************************************************************/
223
204
224
- const getTargetHostname = function ( ) {
225
- return details . hn ;
226
- } ;
227
-
228
205
const proceedToURL = function ( ) {
229
206
window . location . replace ( details . url ) ;
230
207
} ;
231
208
232
209
const proceedTemporary = async function ( ) {
233
210
await messaging . send ( 'documentBlocked' , {
234
211
what : 'temporarilyWhitelistDocument' ,
235
- hostname : getTargetHostname ( ) ,
212
+ hostname : details . hn ,
236
213
} ) ;
237
214
proceedToURL ( ) ;
238
215
} ;
@@ -241,7 +218,7 @@ const proceedPermanent = async function() {
241
218
await messaging . send ( 'documentBlocked' , {
242
219
what : 'toggleHostnameSwitch' ,
243
220
name : 'no-strict-blocking' ,
244
- hostname : getTargetHostname ( ) ,
221
+ hostname : details . hn ,
245
222
deep : true ,
246
223
state : true ,
247
224
persist : true ,
@@ -263,4 +240,49 @@ dom.on('#proceed', 'click', ( ) => {
263
240
}
264
241
} ) ;
265
242
243
+ lookupFilterLists ( ) . then ( ( lists = [ ] ) => {
244
+ let reason = details . reason ;
245
+ if ( Boolean ( reason ) === false ) {
246
+ reason = lists . reduce ( ( a , b ) => a || b . reason , undefined ) ;
247
+ }
248
+ if ( reason ) {
249
+ const msg = i18n$ ( `docblockedReason${ reason . charAt ( 0 ) . toUpperCase ( ) } ${ reason . slice ( 1 ) } ` ) ;
250
+ if ( msg ) { reason = msg } ;
251
+ }
252
+ const why = qs$ ( reason ? 'template.why-reason' : 'template.why' )
253
+ . content
254
+ . cloneNode ( true ) ;
255
+ i18n . render ( why ) ;
256
+ dom . text ( qs$ ( why , '.why' ) , details . fs ) ;
257
+ if ( reason ) {
258
+ dom . text ( qs$ ( why , 'summary' ) , `Reason: ${ reason } ` ) ;
259
+ }
260
+ qs$ ( '#why' ) . append ( why ) ;
261
+ dom . cl . remove ( dom . body , 'loading' ) ;
262
+
263
+ if ( lists . length === 0 ) { return ; }
264
+
265
+ const whyExtra = qs$ ( 'template.why-extra' ) . content . cloneNode ( true ) ;
266
+ i18n . render ( whyExtra ) ;
267
+
268
+ const listTemplate = qs$ ( 'template.filterList' ) ;
269
+ const parent = qs$ ( whyExtra , '.why-extra' ) ;
270
+ let separator = '' ;
271
+ for ( const list of lists ) {
272
+ const listElem = listTemplate . content . cloneNode ( true ) ;
273
+ const sourceElem = qs$ ( listElem , '.filterListSource' ) ;
274
+ sourceElem . href += encodeURIComponent ( list . assetKey ) ;
275
+ sourceElem . append ( i18n . patchUnicodeFlags ( list . title ) ) ;
276
+ if ( typeof list . supportURL === 'string' && list . supportURL !== '' ) {
277
+ const supportElem = qs$ ( listElem , '.filterListSupport' ) ;
278
+ dom . attr ( supportElem , 'href' , list . supportURL ) ;
279
+ dom . cl . remove ( supportElem , 'hidden' ) ;
280
+ }
281
+ parent . append ( separator , listElem ) ;
282
+ separator = '\u00A0\u2022\u00A0' ;
283
+ }
284
+ faIconsInit ( whyExtra ) ;
285
+ qs$ ( '#why .why' ) . after ( whyExtra ) ;
286
+ } ) ;
287
+
266
288
/******************************************************************************/
0 commit comments