diff options
Diffstat (limited to 'js/main-blocked.js')
-rw-r--r-- | js/main-blocked.js | 238 |
1 files changed, 119 insertions, 119 deletions
diff --git a/js/main-blocked.js b/js/main-blocked.js index 6e0edbc..80ac9d3 100644 --- a/js/main-blocked.js +++ b/js/main-blocked.js @@ -29,148 +29,148 @@ (function() { -/******************************************************************************/ - -var details = {}; + /******************************************************************************/ -(function() { - var matches = /details=([^&]+)/.exec(window.location.search); - if ( matches === null ) { return; } - try { - details = JSON.parse(atob(matches[1])); - } catch(ex) { - } -})(); + var details = {}; -/******************************************************************************/ + (function() { + var matches = /details=([^&]+)/.exec(window.location.search); + if ( matches === null ) { return; } + try { + details = JSON.parse(atob(matches[1])); + } catch(ex) { + } + })(); -uDom('.what').text(details.url); -// uDom('#why').text(details.why.slice(3)); + /******************************************************************************/ -/******************************************************************************/ + uDom('.what').text(details.url); + // uDom('#why').text(details.why.slice(3)); -// https://github.com/gorhill/uMatrix/issues/502 -// Code below originally imported from: -// https://github.com/gorhill/uBlock/blob/master/src/js/document-blocked.js + /******************************************************************************/ -(function() { - if ( typeof URL !== 'function' ) { return; } + // https://github.com/gorhill/uMatrix/issues/502 + // Code below originally imported from: + // https://github.com/gorhill/uBlock/blob/master/src/js/document-blocked.js - var reURL = /^https?:\/\//; + (function() { + if ( typeof URL !== 'function' ) { return; } - var liFromParam = function(name, value) { - if ( value === '' ) { - value = name; - name = ''; - } - var li = document.createElement('li'); - var span = document.createElement('span'); - span.textContent = name; - li.appendChild(span); - if ( name !== '' && value !== '' ) { - li.appendChild(document.createTextNode(' = ')); - } - span = document.createElement('span'); - if ( reURL.test(value) ) { - var a = document.createElement('a'); - a.href = a.textContent = value; - span.appendChild(a); - } else { - span.textContent = value; - } - li.appendChild(span); - return li; - }; + var reURL = /^https?:\/\//; - var safeDecodeURIComponent = function(s) { - try { - s = decodeURIComponent(s); - } catch (ex) { - } - return s; - }; - - var renderParams = function(parentNode, rawURL) { - var a = document.createElement('a'); - a.href = rawURL; - if ( a.search.length === 0 ) { return false; } - - var pos = rawURL.indexOf('?'); - var li = liFromParam( - vAPI.i18n('docblockedNoParamsPrompt'), - rawURL.slice(0, pos) - ); - parentNode.appendChild(li); - - var params = a.search.slice(1).split('&'); - var param, name, value, ul; - for ( var i = 0; i < params.length; i++ ) { - param = params[i]; - pos = param.indexOf('='); - if ( pos === -1 ) { - pos = param.length; + var liFromParam = function(name, value) { + if ( value === '' ) { + value = name; + name = ''; + } + var li = document.createElement('li'); + var span = document.createElement('span'); + span.textContent = name; + li.appendChild(span); + if ( name !== '' && value !== '' ) { + li.appendChild(document.createTextNode(' = ')); } - name = safeDecodeURIComponent(param.slice(0, pos)); - value = safeDecodeURIComponent(param.slice(pos + 1)); - li = liFromParam(name, value); + span = document.createElement('span'); if ( reURL.test(value) ) { - ul = document.createElement('ul'); - renderParams(ul, value); - li.appendChild(ul); + var a = document.createElement('a'); + a.href = a.textContent = value; + span.appendChild(a); + } else { + span.textContent = value; } + li.appendChild(span); + return li; + }; + + var safeDecodeURIComponent = function(s) { + try { + s = decodeURIComponent(s); + } catch (ex) { + } + return s; + }; + + var renderParams = function(parentNode, rawURL) { + var a = document.createElement('a'); + a.href = rawURL; + if ( a.search.length === 0 ) { return false; } + + var pos = rawURL.indexOf('?'); + var li = liFromParam( + vAPI.i18n('docblockedNoParamsPrompt'), + rawURL.slice(0, pos) + ); parentNode.appendChild(li); - } - return true; - }; - if ( renderParams(uDom.nodeFromId('parsed'), details.url) === false ) { - return; - } + var params = a.search.slice(1).split('&'); + var param, name, value, ul; + for ( var i = 0; i < params.length; i++ ) { + param = params[i]; + pos = param.indexOf('='); + if ( pos === -1 ) { + pos = param.length; + } + name = safeDecodeURIComponent(param.slice(0, pos)); + value = safeDecodeURIComponent(param.slice(pos + 1)); + li = liFromParam(name, value); + if ( reURL.test(value) ) { + ul = document.createElement('ul'); + renderParams(ul, value); + li.appendChild(ul); + } + parentNode.appendChild(li); + } + return true; + }; - var toggler = document.createElement('span'); - toggler.className = 'fa'; - uDom('#theURL > p').append(toggler); + if ( renderParams(uDom.nodeFromId('parsed'), details.url) === false ) { + return; + } - uDom(toggler).on('click', function() { - var collapsed = uDom.nodeFromId('theURL').classList.toggle('collapsed'); - vAPI.localStorage.setItem( - 'document-blocked-collapse-url', - collapsed.toString() + var toggler = document.createElement('span'); + toggler.className = 'fa'; + uDom('#theURL > p').append(toggler); + + uDom(toggler).on('click', function() { + var collapsed = uDom.nodeFromId('theURL').classList.toggle('collapsed'); + vAPI.localStorage.setItem( + 'document-blocked-collapse-url', + collapsed.toString() + ); + }); + + uDom.nodeFromId('theURL').classList.toggle( + 'collapsed', + vAPI.localStorage.getItem('document-blocked-collapse-url') === 'true' ); - }); + })(); - uDom.nodeFromId('theURL').classList.toggle( - 'collapsed', - vAPI.localStorage.getItem('document-blocked-collapse-url') === 'true' - ); -})(); + /******************************************************************************/ -/******************************************************************************/ - -if ( window.history.length > 1 ) { - uDom('#back').on('click', function() { window.history.back(); }); - uDom('#bye').css('display', 'none'); -} else { - uDom('#bye').on('click', function() { window.close(); }); - uDom('#back').css('display', 'none'); -} + if ( window.history.length > 1 ) { + uDom('#back').on('click', function() { window.history.back(); }); + uDom('#bye').css('display', 'none'); + } else { + uDom('#bye').on('click', function() { window.close(); }); + uDom('#back').css('display', 'none'); + } -/******************************************************************************/ + /******************************************************************************/ -// See if the target hostname is still blacklisted, and if not, navigate to it. + // See if the target hostname is still blacklisted, and if not, navigate to it. -vAPI.messaging.send('main-blocked.js', { - what: 'mustBlock', - scope: details.hn, - hostname: details.hn, - type: 'doc' -}, function(response) { - if ( response === false ) { - window.location.replace(details.url); - } -}); + vAPI.messaging.send('main-blocked.js', { + what: 'mustBlock', + scope: details.hn, + hostname: details.hn, + type: 'doc' + }, function(response) { + if ( response === false ) { + window.location.replace(details.url); + } + }); -/******************************************************************************/ + /******************************************************************************/ })(); |