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
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
const safeDecodeURIComponent = function(s) {
|
2016-02-04 14:21:59 +01:00
|
|
|
try {
|
|
|
|
s = decodeURIComponent(s);
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
const renderParams = function(parentNode, rawURL) {
|
|
|
|
const a = document.createElement('a');
|
2015-10-13 16:56:59 +02:00
|
|
|
a.href = rawURL;
|
2019-05-22 00:56:59 +02:00
|
|
|
if ( a.search.length === 0 ) { return false; }
|
2015-09-12 16:51:11 +02:00
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
let pos = rawURL.indexOf('?');
|
|
|
|
const li = liFromParam(
|
2015-09-12 16:51:11 +02:00
|
|
|
vAPI.i18n('docblockedNoParamsPrompt'),
|
|
|
|
rawURL.slice(0, pos)
|
|
|
|
);
|
|
|
|
parentNode.appendChild(li);
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
const params = a.search.slice(1).split('&');
|
|
|
|
for ( const param of params ) {
|
|
|
|
let pos = param.indexOf('=');
|
2015-09-10 15:51:49 +02:00
|
|
|
if ( pos === -1 ) {
|
|
|
|
pos = param.length;
|
|
|
|
}
|
2019-05-22 00:56:59 +02:00
|
|
|
const name = safeDecodeURIComponent(param.slice(0, pos));
|
|
|
|
const value = safeDecodeURIComponent(param.slice(pos + 1));
|
|
|
|
const li = liFromParam(name, value);
|
2015-09-10 15:51:49 +02:00
|
|
|
if ( reURL.test(value) ) {
|
2019-05-22 00:56:59 +02:00
|
|
|
const ul = document.createElement('ul');
|
2015-09-10 15:51:49 +02:00
|
|
|
renderParams(ul, value);
|
|
|
|
li.appendChild(ul);
|
|
|
|
}
|
|
|
|
parentNode.appendChild(li);
|
|
|
|
}
|
|
|
|
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
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|