From d098a9fb3d671781d761b0b8d646df02cc646508 Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 6 Apr 2015 10:26:32 -0400 Subject: [PATCH] strict blocking: give choice of domain/hostname on warning page --- src/document-blocked.html | 22 +++++++++++++++++- src/js/document-blocked.js | 28 +++++++++++++++++++---- src/js/messaging.js | 2 +- src/js/traffic.js | 47 ++++++++++++++++++++++++++------------ 4 files changed, 78 insertions(+), 21 deletions(-) diff --git a/src/document-blocked.html b/src/document-blocked.html index ee06972d9..0b3f690a1 100644 --- a/src/document-blocked.html +++ b/src/document-blocked.html @@ -22,6 +22,8 @@ body > div > p:first-child { background-color: rgba(0, 0, 0, 0.1); display: inline-block; font-family: monospace; + font-size: large; + line-height: 1; padding: 2px 4px; word-break: break-all; } @@ -41,6 +43,14 @@ button { color: #f2a500; font-size: 180px; } +.proceedChoice { + display: inline-block; + text-align: left; + vertical-align: middle; + } +select { + direction: rtl; + } @@ -69,7 +79,17 @@ button {
- + + + + + + + +
diff --git a/src/js/document-blocked.js b/src/js/document-blocked.js index 248f98394..e297bd56e 100644 --- a/src/js/document-blocked.js +++ b/src/js/document-blocked.js @@ -42,6 +42,17 @@ var details = {}; /******************************************************************************/ +var getTargetHostname = function() { + var hostname = details.hn; + var elem = document.querySelector('#proceed select'); + if ( elem !== null ) { + hostname = elem.value; + } + return hostname; +}; + +/******************************************************************************/ + var proceedToURL = function() { window.location.replace(details.url); }; @@ -51,7 +62,7 @@ var proceedToURL = function() { var proceedTemporary = function() { messager.send({ what: 'temporarilyWhitelistDocument', - url: details.url + hostname: getTargetHostname() }, proceedToURL); }; @@ -61,7 +72,7 @@ var proceedPermanent = function() { messager.send({ what: 'toggleHostnameSwitch', name: 'noStrictBlocking', - hostname: details.hn, + hostname: getTargetHostname(), state: true }, proceedToURL); }; @@ -75,8 +86,17 @@ var proceedPermanent = function() { } var proceed = uDom('#proceedTemplate').clone(); proceed.descendants('span:nth-of-type(1)').text(matches[1]); - proceed.descendants('span:nth-of-type(2)').text(details.hn); - proceed.descendants('span:nth-of-type(3)').text(matches[2]); + proceed.descendants('span:nth-of-type(4)').text(matches[2]); + + if ( details.hn === details.dn ) { + proceed.descendants('.hn').text(details.hn); + proceed.descendants('span:nth-of-type(2)').remove(); + } else { + proceed.descendants('.hn').text(details.hn).attr('value', details.hn); + proceed.descendants('.dn').text(details.dn).attr('value', details.dn); + proceed.descendants('span:nth-of-type(3)').remove(); + } + uDom('#proceed').append(proceed); })(); diff --git a/src/js/messaging.js b/src/js/messaging.js index c798bacd3..2a142cd69 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -1288,7 +1288,7 @@ var onMessage = function(request, sender, callback) { switch ( request.what ) { case 'temporarilyWhitelistDocument': - µBlock.webRequest.temporarilyWhitelistDocument(request.url); + µBlock.webRequest.temporarilyWhitelistDocument(request.hostname); break; default: diff --git a/src/js/traffic.js b/src/js/traffic.js index 7e6929c2a..06449aacb 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -187,7 +187,7 @@ var onBeforeRootFrameRequest = function(details) { // behind-the-scene var µb = µBlock; var requestHostname = details.hostname; - var requestDomain = µb.URI.domainFromHostname(requestHostname); + var requestDomain = µb.URI.domainFromHostname(requestHostname) || requestHostname; var context = { rootHostname: requestHostname, rootDomain: requestDomain, @@ -206,15 +206,9 @@ var onBeforeRootFrameRequest = function(details) { } // Temporarily whitelisted? - var obsolete = documentWhitelists[requestHostname]; - if ( obsolete !== undefined ) { - if ( obsolete > Date.now() ) { - if ( result === '' ) { - result = 'ta:*' + ' ' + requestHostname + ' doc allow'; - } - } else { - delete documentWhitelists[requestHostname]; - } + result = isTemporarilyWhitelisted(result, requestHostname); + if ( result.charAt(1) === 'a' ) { + return; } // Filtering @@ -242,6 +236,7 @@ var onBeforeRootFrameRequest = function(details) { var query = btoa(JSON.stringify({ url: requestURL, hn: requestHostname, + dn: requestDomain, why: result })); @@ -465,10 +460,33 @@ vAPI.net.registerListeners(); /******************************************************************************/ -exports.temporarilyWhitelistDocument = function(url) { - var µb = µBlock; - var hostname = µb.URI.hostnameFromURI(url); - if ( hostname === '' ) { +var isTemporarilyWhitelisted = function(result, hostname) { + var obsolete, pos; + + for (;;) { + obsolete = documentWhitelists[hostname]; + if ( obsolete !== undefined ) { + if ( obsolete > Date.now() ) { + if ( result === '' ) { + return 'ua:*' + ' ' + hostname + ' doc allow'; + } + } else { + delete documentWhitelists[hostname]; + } + } + pos = hostname.indexOf('.'); + if ( pos === -1 ) { + break; + } + hostname = hostname.slice(pos + 1); + } + return result; +}; + +/******************************************************************************/ + +exports.temporarilyWhitelistDocument = function(hostname) { + if ( typeof hostname !== 'string' || hostname === '' ) { return; } @@ -484,4 +502,3 @@ return exports; })(); /******************************************************************************/ -