@ -1,7 +1,7 @@
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
uMatrix - a browser extension to block requests .
uMatrix - a browser extension to block requests .
Copyright ( C ) 2015 - 2017 Raymond Hill
Copyright ( C ) 2015 - present Raymond Hill
This program is free software : you can redistribute it and / or modify
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
@ -29,10 +29,10 @@
/******************************************************************************/
/******************************************************************************/
var details = { } ;
let details = { } ;
( function ( ) {
( function ( ) {
var matches = /details=([^&]+)/ . exec ( window . location . search ) ;
let matches = /details=([^&]+)/ . exec ( window . location . search ) ;
if ( matches === null ) { return ; }
if ( matches === null ) { return ; }
try {
try {
details = JSON . parse ( atob ( matches [ 1 ] ) ) ;
details = JSON . parse ( atob ( matches [ 1 ] ) ) ;
@ -52,17 +52,15 @@ uDom('.what').text(details.url);
// https://github.com/gorhill/uBlock/blob/master/src/js/document-blocked.js
// https://github.com/gorhill/uBlock/blob/master/src/js/document-blocked.js
( function ( ) {
( function ( ) {
if ( typeof URL !== 'function' ) { return ; }
let reURL = /^https?:\/\// ;
var reURL = /^https?:\/\// ;
let liFromParam = function ( name , value ) {
var liFromParam = function ( name , value ) {
if ( value === '' ) {
if ( value === '' ) {
value = name ;
value = name ;
name = '' ;
name = '' ;
}
}
var li = document . createElement ( 'li' ) ;
let li = document . createElement ( 'li' ) ;
var span = document . createElement ( 'span' ) ;
let span = document . createElement ( 'span' ) ;
span . textContent = name ;
span . textContent = name ;
li . appendChild ( span ) ;
li . appendChild ( span ) ;
if ( name !== '' && value !== '' ) {
if ( name !== '' && value !== '' ) {
@ -70,7 +68,7 @@ uDom('.what').text(details.url);
}
}
span = document . createElement ( 'span' ) ;
span = document . createElement ( 'span' ) ;
if ( reURL . test ( value ) ) {
if ( reURL . test ( value ) ) {
var a = document . createElement ( 'a' ) ;
let a = document . createElement ( 'a' ) ;
a . href = a . textContent = value ;
a . href = a . textContent = value ;
span . appendChild ( a ) ;
span . appendChild ( a ) ;
} else {
} else {
@ -80,7 +78,7 @@ uDom('.what').text(details.url);
return li ;
return li ;
} ;
} ;
var safeDecodeURIComponent = function ( s ) {
let safeDecodeURIComponent = function ( s ) {
try {
try {
s = decodeURIComponent ( s ) ;
s = decodeURIComponent ( s ) ;
} catch ( ex ) {
} catch ( ex ) {
@ -88,31 +86,30 @@ uDom('.what').text(details.url);
return s ;
return s ;
} ;
} ;
var renderParams = function ( parentNode , rawURL ) {
let renderParams = function ( parentNode , rawURL ) {
var a = document . createElement ( 'a' ) ;
let a = document . createElement ( 'a' ) ;
a . href = rawURL ;
a . href = rawURL ;
if ( a . search . length === 0 ) { return false ; }
if ( a . search . length === 0 ) { return false ; }
var pos = rawURL . indexOf ( '?' ) ;
let pos = rawURL . indexOf ( '?' ) ;
var li = liFromParam (
let li = liFromParam (
vAPI . i18n ( ' docb lockedNoParamsPrompt') ,
vAPI . i18n ( ' mainB lockedNoParamsPrompt') ,
rawURL . slice ( 0 , pos )
rawURL . slice ( 0 , pos )
) ;
) ;
parentNode . appendChild ( li ) ;
parentNode . appendChild ( li ) ;
var params = a . search . slice ( 1 ) . split ( '&' ) ;
let params = a . search . slice ( 1 ) . split ( '&' ) ;
var param , name , value , ul ;
for ( var i = 0 ; i < params . length ; i ++ ) {
for ( var i = 0 ; i < params . length ; i ++ ) {
param = params [ i ] ;
let param = params [ i ] ;
pos = param . indexOf ( '=' ) ;
let pos = param . indexOf ( '=' ) ;
if ( pos === - 1 ) {
if ( pos === - 1 ) {
pos = param . length ;
pos = param . length ;
}
}
name = safeDecodeURIComponent ( param . slice ( 0 , pos ) ) ;
let name = safeDecodeURIComponent ( param . slice ( 0 , pos ) ) ;
value = safeDecodeURIComponent ( param . slice ( pos + 1 ) ) ;
let value = safeDecodeURIComponent ( param . slice ( pos + 1 ) ) ;
li = liFromParam ( name , value ) ;
li = liFromParam ( name , value ) ;
if ( reURL . test ( value ) ) {
if ( reURL . test ( value ) ) {
ul = document . createElement ( 'ul' ) ;
let ul = document . createElement ( 'ul' ) ;
renderParams ( ul , value ) ;
renderParams ( ul , value ) ;
li . appendChild ( ul ) ;
li . appendChild ( ul ) ;
}
}
@ -121,25 +118,30 @@ uDom('.what').text(details.url);
return true ;
return true ;
} ;
} ;
if ( renderParams ( uDom . nodeFromId ( 'parsed' ) , details . url ) === false ) {
let hasParams = renderParams ( uDom . nodeFromId ( 'parsed' ) , details . url ) ;
return ;
if ( hasParams === false ) { return ; }
}
var toggler = document . createElement ( 'span' ) ;
let theURLNode = document . getElementById ( 'theURL' ) ;
toggler . className = 'fa' ;
theURLNode . classList . add ( 'hasParams' ) ;
uDom ( '#theURL > p' ) . append ( toggler ) ;
theURLNode . classList . toggle (
'collapsed' ,
vAPI . localStorage . getItem ( 'document-blocked-collapse-url' ) === 'true'
) ;
uDom ( toggler ) . on ( 'click' , function ( ) {
let toggleCollapse = function ( ) {
var collapsed = uDom . nodeFromId ( 'theURL' ) . classList . toggle ( 'collapsed' ) ;
vAPI . localStorage . setItem (
vAPI . localStorage . setItem (
'document-blocked-collapse-url' ,
'document-blocked-collapse-url' ,
collapsed. toString ( )
theURLNode. classList . toggle ( ' collapsed') . toString ( )
) ;
) ;
} ) ;
} ;
uDom . nodeFromId ( 'theURL' ) . classList . toggle (
theURLNode . querySelector ( '.collapse' ) . addEventListener (
'collapsed' ,
'click' ,
vAPI . localStorage . getItem ( 'document-blocked-collapse-url' ) === 'true'
toggleCollapse
) ;
theURLNode . querySelector ( '.expand' ) . addEventListener (
'click' ,
toggleCollapse
) ;
) ;
} ) ( ) ;
} ) ( ) ;
@ -161,8 +163,8 @@ vAPI.messaging.send('main-blocked.js', {
what : 'mustBlock' ,
what : 'mustBlock' ,
scope : details . hn ,
scope : details . hn ,
hostname : details . hn ,
hostname : details . hn ,
type : 'doc'
type : details . type
} , function ( response ) {
} , response => {
if ( response === false ) {
if ( response === false ) {
window . location . replace ( details . url ) ;
window . location . replace ( details . url ) ;
}
}