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);
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
|
font-size: large;
|
||||||
|
line-height: 1;
|
||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +43,14 @@ button {
|
||||||
color: #f2a500;
|
color: #f2a500;
|
||||||
font-size: 180px;
|
font-size: 180px;
|
||||||
}
|
}
|
||||||
|
.proceedChoice {
|
||||||
|
display: inline-block;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
direction: rtl;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -69,7 +79,17 @@ button {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="display: none;">
|
<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>
|
</div>
|
||||||
|
|
||||||
<script src="js/vapi-common.js"></script>
|
<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() {
|
var proceedToURL = function() {
|
||||||
window.location.replace(details.url);
|
window.location.replace(details.url);
|
||||||
};
|
};
|
||||||
|
@ -51,7 +62,7 @@ var proceedToURL = function() {
|
||||||
var proceedTemporary = function() {
|
var proceedTemporary = function() {
|
||||||
messager.send({
|
messager.send({
|
||||||
what: 'temporarilyWhitelistDocument',
|
what: 'temporarilyWhitelistDocument',
|
||||||
url: details.url
|
hostname: getTargetHostname()
|
||||||
}, proceedToURL);
|
}, proceedToURL);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,7 +72,7 @@ var proceedPermanent = function() {
|
||||||
messager.send({
|
messager.send({
|
||||||
what: 'toggleHostnameSwitch',
|
what: 'toggleHostnameSwitch',
|
||||||
name: 'noStrictBlocking',
|
name: 'noStrictBlocking',
|
||||||
hostname: details.hn,
|
hostname: getTargetHostname(),
|
||||||
state: true
|
state: true
|
||||||
}, proceedToURL);
|
}, proceedToURL);
|
||||||
};
|
};
|
||||||
|
@ -75,8 +86,17 @@ var proceedPermanent = function() {
|
||||||
}
|
}
|
||||||
var proceed = uDom('#proceedTemplate').clone();
|
var proceed = uDom('#proceedTemplate').clone();
|
||||||
proceed.descendants('span:nth-of-type(1)').text(matches[1]);
|
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(4)').text(matches[2]);
|
||||||
proceed.descendants('span:nth-of-type(3)').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);
|
uDom('#proceed').append(proceed);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
@ -1288,7 +1288,7 @@ var onMessage = function(request, sender, callback) {
|
||||||
|
|
||||||
switch ( request.what ) {
|
switch ( request.what ) {
|
||||||
case 'temporarilyWhitelistDocument':
|
case 'temporarilyWhitelistDocument':
|
||||||
µBlock.webRequest.temporarilyWhitelistDocument(request.url);
|
µBlock.webRequest.temporarilyWhitelistDocument(request.hostname);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -187,7 +187,7 @@ var onBeforeRootFrameRequest = function(details) {
|
||||||
// behind-the-scene
|
// behind-the-scene
|
||||||
var µb = µBlock;
|
var µb = µBlock;
|
||||||
var requestHostname = details.hostname;
|
var requestHostname = details.hostname;
|
||||||
var requestDomain = µb.URI.domainFromHostname(requestHostname);
|
var requestDomain = µb.URI.domainFromHostname(requestHostname) || requestHostname;
|
||||||
var context = {
|
var context = {
|
||||||
rootHostname: requestHostname,
|
rootHostname: requestHostname,
|
||||||
rootDomain: requestDomain,
|
rootDomain: requestDomain,
|
||||||
|
@ -206,15 +206,9 @@ var onBeforeRootFrameRequest = function(details) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporarily whitelisted?
|
// Temporarily whitelisted?
|
||||||
var obsolete = documentWhitelists[requestHostname];
|
result = isTemporarilyWhitelisted(result, requestHostname);
|
||||||
if ( obsolete !== undefined ) {
|
if ( result.charAt(1) === 'a' ) {
|
||||||
if ( obsolete > Date.now() ) {
|
return;
|
||||||
if ( result === '' ) {
|
|
||||||
result = 'ta:*' + ' ' + requestHostname + ' doc allow';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete documentWhitelists[requestHostname];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filtering
|
// Filtering
|
||||||
|
@ -242,6 +236,7 @@ var onBeforeRootFrameRequest = function(details) {
|
||||||
var query = btoa(JSON.stringify({
|
var query = btoa(JSON.stringify({
|
||||||
url: requestURL,
|
url: requestURL,
|
||||||
hn: requestHostname,
|
hn: requestHostname,
|
||||||
|
dn: requestDomain,
|
||||||
why: result
|
why: result
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -465,10 +460,33 @@ vAPI.net.registerListeners();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
exports.temporarilyWhitelistDocument = function(url) {
|
var isTemporarilyWhitelisted = function(result, hostname) {
|
||||||
var µb = µBlock;
|
var obsolete, pos;
|
||||||
var hostname = µb.URI.hostnameFromURI(url);
|
|
||||||
if ( hostname === '' ) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,4 +502,3 @@ return exports;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue