2121
2222import { dom , qs$ } from './dom.js' ;
2323import { i18n , i18n$ } from './i18n.js' ;
24+ import { faIconsInit } from './fa-icons.js' ;
2425
2526/******************************************************************************/
2627
2728const messaging = vAPI . messaging ;
28- let details = { } ;
29+ const details = { } ;
2930
3031{
3132 const matches = / d e t a i l s = ( [ ^ & ] + ) / . exec ( window . location . search ) ;
3233 if ( matches !== null ) {
33- details = JSON . parse ( decodeURIComponent ( matches [ 1 ] ) ) ;
34+ Object . assign ( details , JSON . parse ( decodeURIComponent ( matches [ 1 ] ) ) ) ;
3435 }
3536}
3637
3738/******************************************************************************/
3839
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-
7840const urlToFragment = raw => {
7941 try {
8042 const fragment = new DocumentFragment ( ) ;
@@ -94,7 +56,26 @@ const urlToFragment = raw => {
9456
9557dom . clear ( '#theURL > p > span:first-of-type' ) ;
9658qs$ ( '#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+ /******************************************************************************/
9879
9980if ( typeof details . to === 'string' && details . to . length !== 0 ) {
10081 const fragment = new DocumentFragment ( ) ;
@@ -221,18 +202,14 @@ if ( window.history.length > 1 ) {
221202
222203/******************************************************************************/
223204
224- const getTargetHostname = function ( ) {
225- return details . hn ;
226- } ;
227-
228205const proceedToURL = function ( ) {
229206 window . location . replace ( details . url ) ;
230207} ;
231208
232209const proceedTemporary = async function ( ) {
233210 await messaging . send ( 'documentBlocked' , {
234211 what : 'temporarilyWhitelistDocument' ,
235- hostname : getTargetHostname ( ) ,
212+ hostname : details . hn ,
236213 } ) ;
237214 proceedToURL ( ) ;
238215} ;
@@ -241,7 +218,7 @@ const proceedPermanent = async function() {
241218 await messaging . send ( 'documentBlocked' , {
242219 what : 'toggleHostnameSwitch' ,
243220 name : 'no-strict-blocking' ,
244- hostname : getTargetHostname ( ) ,
221+ hostname : details . hn ,
245222 deep : true ,
246223 state : true ,
247224 persist : true ,
@@ -263,4 +240,49 @@ dom.on('#proceed', 'click', ( ) => {
263240 }
264241} ) ;
265242
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+
266288/******************************************************************************/
0 commit comments