2015-03-26 00:28:22 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2018-07-21 18:22:53 +02:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
|
|
|
Copyright (C) 2015-present Raymond Hill
|
2015-03-26 00:28:22 +01:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2018-07-22 14:14:50 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-03-26 00:28:22 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
(( ) => {
|
2015-03-26 00:28:22 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
const messaging = vAPI.messaging;
|
|
|
|
let details = {};
|
2015-03-26 00:28:22 +01:00
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
{
|
|
|
|
const matches = /details=([^&]+)/.exec(window.location.search);
|
|
|
|
if ( matches !== null ) {
|
2019-11-04 19:12:40 +01:00
|
|
|
details = JSON.parse(decodeURIComponent(matches[1]));
|
2015-03-30 19:10:29 +02:00
|
|
|
}
|
2019-05-22 00:56:59 +02:00
|
|
|
}
|
2015-03-26 00:28:22 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-09-17 21:15:01 +02:00
|
|
|
(async ( ) => {
|
|
|
|
const response = await messaging.send('documentBlocked', {
|
2019-05-22 00:56:59 +02:00
|
|
|
what: 'listsFromNetFilter',
|
2019-09-17 21:15:01 +02:00
|
|
|
rawFilter: details.fs,
|
|
|
|
});
|
|
|
|
if ( response instanceof Object === false ) { return; }
|
|
|
|
|
|
|
|
let lists;
|
|
|
|
for ( const rawFilter in response ) {
|
|
|
|
if ( response.hasOwnProperty(rawFilter) ) {
|
2015-06-13 17:21:55 +02:00
|
|
|
lists = response[rawFilter];
|
|
|
|
break;
|
|
|
|
}
|
2019-09-17 21:15:01 +02:00
|
|
|
}
|
2018-07-22 14:14:50 +02:00
|
|
|
|
2019-09-17 21:15:01 +02:00
|
|
|
if ( Array.isArray(lists) === false || lists.length === 0 ) { return; }
|
|
|
|
|
|
|
|
const parent = uDom.nodeFromSelector('#whyex > span:nth-of-type(2)');
|
|
|
|
for ( const list of lists ) {
|
2020-11-15 16:19:09 +01:00
|
|
|
const listElem = document.querySelector('#templates .filterList')
|
|
|
|
.cloneNode(true);
|
|
|
|
const sourceElem = listElem.querySelector('.filterListSource');
|
|
|
|
sourceElem.href += encodeURIComponent(list.assetKey);
|
|
|
|
sourceElem.textContent = list.title;
|
|
|
|
if ( typeof list.supportURL === 'string' && list.supportURL !== '' ) {
|
|
|
|
const supportElem = listElem.querySelector('.filterListSupport');
|
|
|
|
supportElem.setAttribute('href', list.supportURL);
|
|
|
|
supportElem.classList.remove('hidden');
|
2015-06-12 01:33:30 +02:00
|
|
|
}
|
2020-11-15 16:19:09 +01:00
|
|
|
parent.appendChild(listElem);
|
2015-04-06 16:26:32 +02:00
|
|
|
}
|
2019-09-17 21:15:01 +02:00
|
|
|
uDom.nodeFromId('whyex').style.removeProperty('display');
|
|
|
|
})();
|
2015-03-26 00:28:22 +01:00
|
|
|
|
2015-03-30 19:10:29 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
(( ) => {
|
|
|
|
const matches = /^(.*)\{\{hostname\}\}(.*)$/.exec(vAPI.i18n('docblockedProceed'));
|
|
|
|
if ( matches === null ) { return; }
|
2020-09-12 16:37:08 +02:00
|
|
|
const proceed = document.querySelector('#templates .proceed').cloneNode(true);
|
|
|
|
proceed.children[0].textContent = matches[1];
|
|
|
|
proceed.children[2].textContent = matches[2];
|
|
|
|
const hnOption = proceed.querySelector('.hn');
|
2020-05-04 18:41:10 +02:00
|
|
|
if ( details.hn !== details.dn ) {
|
2020-09-12 16:37:08 +02:00
|
|
|
hnOption.textContent = details.hn;
|
|
|
|
hnOption.setAttribute('value', details.hn);
|
2020-05-04 18:41:10 +02:00
|
|
|
} else {
|
2020-09-12 16:37:08 +02:00
|
|
|
hnOption.remove();
|
2015-04-06 16:26:32 +02:00
|
|
|
}
|
2020-09-12 16:37:08 +02:00
|
|
|
const dnOption = proceed.querySelector('.dn');
|
|
|
|
dnOption.textContent = details.dn;
|
|
|
|
dnOption.setAttribute('value', details.dn);
|
|
|
|
document.getElementById('proceed').append(proceed);
|
2015-03-30 19:10:29 +02:00
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-12-07 20:32:59 +01:00
|
|
|
uDom.nodeFromSelector('#theURL > p > span:first-of-type').textContent = details.url;
|
2015-06-12 01:33:30 +02:00
|
|
|
uDom.nodeFromId('why').textContent = details.fs;
|
2015-03-26 00:28:22 +01:00
|
|
|
|
2015-09-10 15:51:49 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/691
|
2021-07-25 13:08:03 +02:00
|
|
|
// Parse URL to extract as much useful information as possible. This is
|
|
|
|
// useful to assist the user in deciding whether to navigate to the web page.
|
2019-05-22 00:56:59 +02:00
|
|
|
(( ) => {
|
|
|
|
if ( typeof URL !== 'function' ) { return; }
|
2015-09-10 15:51:49 +02:00
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
const reURL = /^https?:\/\//;
|
2015-09-10 15:51:49 +02:00
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
const liFromParam = function(name, value) {
|
2015-09-14 13:21:35 +02:00
|
|
|
if ( value === '' ) {
|
|
|
|
value = name;
|
|
|
|
name = '';
|
|
|
|
}
|
2019-05-22 00:56:59 +02:00
|
|
|
const li = document.createElement('li');
|
|
|
|
let span = document.createElement('span');
|
2015-09-10 15:51:49 +02:00
|
|
|
span.textContent = name;
|
|
|
|
li.appendChild(span);
|
2015-09-14 13:21:35 +02:00
|
|
|
if ( name !== '' && value !== '' ) {
|
|
|
|
li.appendChild(document.createTextNode(' = '));
|
|
|
|
}
|
2015-09-10 15:51:49 +02:00
|
|
|
span = document.createElement('span');
|
|
|
|
if ( reURL.test(value) ) {
|
2019-05-22 00:56:59 +02:00
|
|
|
const a = document.createElement('a');
|
2015-09-10 15:51:49 +02:00
|
|
|
a.href = a.textContent = value;
|
|
|
|
span.appendChild(a);
|
|
|
|
} else {
|
|
|
|
span.textContent = value;
|
|
|
|
}
|
|
|
|
li.appendChild(span);
|
|
|
|
return li;
|
|
|
|
};
|
|
|
|
|
2021-07-06 16:13:50 +02:00
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1649
|
|
|
|
// Limit recursion.
|
|
|
|
const renderParams = function(parentNode, rawURL, depth = 0) {
|
2021-07-25 13:08:03 +02:00
|
|
|
let url;
|
|
|
|
try {
|
|
|
|
url = new URL(rawURL);
|
|
|
|
} catch(ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const search = url.search.slice(1);
|
|
|
|
if ( search === '' ) { return false; }
|
|
|
|
|
|
|
|
url.search = '';
|
|
|
|
const li = liFromParam(vAPI.i18n('docblockedNoParamsPrompt'), url.href);
|
2015-09-12 16:51:11 +02:00
|
|
|
parentNode.appendChild(li);
|
|
|
|
|
2021-07-25 13:08:03 +02:00
|
|
|
const params = new self.URLSearchParams(search);
|
|
|
|
for ( const [ name, value ] of params ) {
|
2019-05-22 00:56:59 +02:00
|
|
|
const li = liFromParam(name, value);
|
2021-07-06 16:13:50 +02:00
|
|
|
if ( depth < 2 && reURL.test(value) ) {
|
2019-05-22 00:56:59 +02:00
|
|
|
const ul = document.createElement('ul');
|
2021-07-06 16:13:50 +02:00
|
|
|
renderParams(ul, value, depth + 1);
|
2015-09-10 15:51:49 +02:00
|
|
|
li.appendChild(ul);
|
|
|
|
}
|
|
|
|
parentNode.appendChild(li);
|
|
|
|
}
|
2021-07-25 13:08:03 +02:00
|
|
|
|
2015-09-10 15:51:49 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( renderParams(uDom.nodeFromId('parsed'), details.url) === false ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-07 20:32:59 +01:00
|
|
|
const toggler = document.querySelector('#theURL > p > span:last-of-type');
|
2015-09-10 15:51:49 +02:00
|
|
|
|
2020-12-07 20:32:59 +01:00
|
|
|
toggler.addEventListener('click', ( ) => {
|
2019-05-22 00:56:59 +02:00
|
|
|
const cl = uDom.nodeFromId('theURL').classList;
|
2015-09-12 16:51:11 +02:00
|
|
|
cl.toggle('collapsed');
|
|
|
|
vAPI.localStorage.setItem(
|
|
|
|
'document-blocked-expand-url',
|
|
|
|
(cl.contains('collapsed') === false).toString()
|
|
|
|
);
|
2015-09-10 15:51:49 +02:00
|
|
|
});
|
2015-09-12 16:51:11 +02:00
|
|
|
|
2020-02-21 21:34:54 +01:00
|
|
|
vAPI.localStorage.getItemAsync('document-blocked-expand-url').then(value => {
|
|
|
|
uDom.nodeFromId('theURL').classList.toggle(
|
|
|
|
'collapsed',
|
|
|
|
value !== 'true' && value !== true
|
|
|
|
);
|
|
|
|
});
|
2015-09-10 15:51:49 +02:00
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
// https://www.reddit.com/r/uBlockOrigin/comments/breeux/close_this_window_doesnt_work_on_firefox/
|
|
|
|
|
2015-03-26 00:28:22 +01:00
|
|
|
if ( window.history.length > 1 ) {
|
2019-05-22 00:56:59 +02:00
|
|
|
uDom('#back').on(
|
|
|
|
'click',
|
|
|
|
( ) => {
|
|
|
|
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 {
|
2019-05-22 00:56:59 +02:00
|
|
|
uDom('#bye').on(
|
|
|
|
'click',
|
|
|
|
( ) => {
|
2019-09-17 21:15:01 +02:00
|
|
|
messaging.send('documentBlocked', {
|
|
|
|
what: 'closeThisTab',
|
|
|
|
});
|
2019-05-22 00:56:59 +02:00
|
|
|
}
|
|
|
|
);
|
2015-03-26 00:28:22 +01:00
|
|
|
uDom('#back').css('display', 'none');
|
|
|
|
}
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const getTargetHostname = function() {
|
|
|
|
const elem = document.querySelector('#proceed select');
|
|
|
|
if ( elem === null ) { return details.hn; }
|
|
|
|
return elem.value;
|
|
|
|
};
|
|
|
|
|
|
|
|
const proceedToURL = function() {
|
|
|
|
window.location.replace(details.url);
|
|
|
|
};
|
|
|
|
|
2019-09-17 21:15:01 +02:00
|
|
|
const proceedTemporary = async function() {
|
|
|
|
await messaging.send('documentBlocked', {
|
|
|
|
what: 'temporarilyWhitelistDocument',
|
|
|
|
hostname: getTargetHostname(),
|
|
|
|
});
|
|
|
|
proceedToURL();
|
2019-05-22 00:56:59 +02:00
|
|
|
};
|
|
|
|
|
2019-09-17 21:15:01 +02:00
|
|
|
const proceedPermanent = async function() {
|
|
|
|
await messaging.send('documentBlocked', {
|
|
|
|
what: 'toggleHostnameSwitch',
|
|
|
|
name: 'no-strict-blocking',
|
|
|
|
hostname: getTargetHostname(),
|
|
|
|
deep: true,
|
|
|
|
state: true,
|
|
|
|
persist: true,
|
|
|
|
});
|
|
|
|
proceedToURL();
|
2019-05-22 00:56:59 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|