mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-20 13:03:56 +02:00
strict blocking: give choice of domain/hostname on warning page
This commit is contained in:
parent
7306724174
commit
d098a9fb3d
4 changed files with 78 additions and 21 deletions
|
@ -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;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -69,7 +79,17 @@ button {
|
|||
</div>
|
||||
|
||||
<div style="display: none;">
|
||||
<span id="proceedTemplate"><span></span><span class="code"></span><span></span></span>
|
||||
<span id="proceedTemplate">
|
||||
<span></span>
|
||||
<span class="proceedChoice">
|
||||
<select class="code">
|
||||
<option class="hn" value="" selected>
|
||||
<option class="dn" value="">
|
||||
</select>
|
||||
</span>
|
||||
<span class="proceedChoice code hn"></span>
|
||||
<span></span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<script src="js/vapi-common.js"></script>
|
||||
|
|
|
@ -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);
|
||||
})();
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
|||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
Loading…
Reference in a new issue