uBlock/src/js/document-blocked.js

174 lines
5.5 KiB
JavaScript
Raw Normal View History

2015-03-26 00:28:22 +01:00
/*******************************************************************************
uBlock - a browser extension to block requests.
Copyright (C) 2015 Raymond Hill
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/
/* global uDom */
/******************************************************************************/
(function() {
'use strict';
/******************************************************************************/
var messager = vAPI.messaging.channel('document-blocked.js');
2015-03-30 19:10:29 +02:00
var details = {};
2015-03-26 00:28:22 +01:00
2015-03-30 19:10:29 +02:00
(function() {
var matches = /details=([^&]+)/.exec(window.location.search);
if ( matches === null ) {
return;
}
details = JSON.parse(atob(matches[1]));
})();
2015-03-26 00:28:22 +01:00
/******************************************************************************/
2015-06-12 01:33:30 +02:00
(function() {
var onReponseReady = function(response) {
if ( typeof response !== 'object' ) {
return;
}
var lists;
for ( var rawFilter in response ) {
if ( response.hasOwnProperty(rawFilter) === false ) {
continue;
}
lists = response[rawFilter];
break;
}
2015-06-12 01:33:30 +02:00
if ( Array.isArray(lists) === false || lists.length === 0 ) {
return;
}
var parent = uDom.nodeFromSelector('#whyex > span');
var separator = '';
var entry, url, node;
for ( var i = 0; i < lists.length; i++ ) {
entry = lists[i];
if ( separator !== '' ) {
parent.appendChild(document.createTextNode(separator));
}
url = entry.supportURL;
if ( typeof url === 'string' && url !== '' ) {
node = document.createElement('a');
node.textContent = entry.title;
node.setAttribute('href', url);
node.setAttribute('target', '_blank');
} else {
node = document.createTextNode(entry.title);
}
parent.appendChild(node);
separator = ' \u2022 ';
}
uDom.nodeFromId('whyex').style.removeProperty('display');
};
messager.send({
what: 'listsFromNetFilter',
compiledFilter: details.fc,
rawFilter: details.fs
2015-06-12 01:33:30 +02:00
}, onReponseReady);
})();
/******************************************************************************/
var getTargetHostname = function() {
var hostname = details.hn;
var elem = document.querySelector('#proceed select');
if ( elem !== null ) {
hostname = elem.value;
}
return hostname;
};
/******************************************************************************/
2015-03-30 19:10:29 +02:00
var proceedToURL = function() {
window.location.replace(details.url);
};
/******************************************************************************/
2015-03-26 00:28:22 +01:00
2015-03-30 19:10:29 +02:00
var proceedTemporary = function() {
2015-03-26 00:28:22 +01:00
messager.send({
what: 'temporarilyWhitelistDocument',
hostname: getTargetHostname()
2015-03-30 19:10:29 +02:00
}, proceedToURL);
};
2015-03-26 00:28:22 +01:00
2015-03-30 19:10:29 +02:00
/******************************************************************************/
var proceedPermanent = function() {
messager.send({
what: 'toggleHostnameSwitch',
name: 'no-strict-blocking',
hostname: getTargetHostname(),
deep: true,
2015-03-30 19:10:29 +02:00
state: true
}, proceedToURL);
2015-03-26 00:28:22 +01:00
};
/******************************************************************************/
2015-03-30 19:10:29 +02:00
(function() {
var matches = /^(.*)\{\{hostname\}\}(.*)$/.exec(vAPI.i18n('docblockedProceed'));
if ( matches === null ) {
return;
}
var proceed = uDom('#proceedTemplate').clone();
proceed.descendants('span:nth-of-type(1)').text(matches[1]);
proceed.descendants('span:nth-of-type(4)').text(matches[2]);
if ( details.hn === details.dn ) {
proceed.descendants('span:nth-of-type(2)').remove();
2015-04-06 18:22:41 +02:00
proceed.descendants('.hn').text(details.hn);
} else {
2015-04-06 18:22:41 +02:00
proceed.descendants('span:nth-of-type(3)').remove();
proceed.descendants('.hn').text(details.hn).attr('value', details.hn);
proceed.descendants('.dn').text(details.dn).attr('value', details.dn);
}
2015-03-30 19:10:29 +02:00
uDom('#proceed').append(proceed);
})();
/******************************************************************************/
2015-06-12 01:33:30 +02:00
uDom.nodeFromSelector('.what').textContent = details.url;
uDom.nodeFromId('why').textContent = details.fs;
2015-03-26 00:28:22 +01:00
if ( window.history.length > 1 ) {
uDom('#back').on('click', function() { window.history.back(); });
2015-03-26 13:12:06 +01:00
uDom('#bye').css('display', 'none');
2015-03-26 00:28:22 +01:00
} else {
2015-03-26 13:12:06 +01:00
uDom('#bye').on('click', function() { window.close(); });
2015-03-26 00:28:22 +01:00
uDom('#back').css('display', 'none');
}
2015-03-30 19:10:29 +02:00
uDom('#proceedTemporary').attr('href', details.url).on('click', proceedTemporary);
uDom('#proceedPermanent').attr('href', details.url).on('click', proceedPermanent);
2015-03-26 00:28:22 +01:00
2015-03-30 23:42:12 +02:00
/******************************************************************************/
2015-03-26 00:28:22 +01:00
})();
/******************************************************************************/