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
|
|
|
|
*/
|
|
|
|
|
2018-07-22 14:14:50 +02:00
|
|
|
'use strict';
|
|
|
|
|
2023-05-21 03:35:52 +02:00
|
|
|
import { i18n, i18n$ } from './i18n.js';
|
2022-11-12 15:51:22 +01:00
|
|
|
import { dom, qs$ } from './dom.js';
|
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
|
|
|
|
2022-11-15 15:44:19 +01:00
|
|
|
if ( Array.isArray(lists) === false || lists.length === 0 ) {
|
|
|
|
qs$('#whyex').style.setProperty('visibility', 'collapse');
|
|
|
|
return;
|
|
|
|
}
|
2019-09-17 21:15:01 +02:00
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
const parent = qs$('#whyex > ul');
|
2022-11-15 15:44:19 +01:00
|
|
|
parent.firstElementChild.remove(); // remove placeholder element
|
2019-09-17 21:15:01 +02:00
|
|
|
for ( const list of lists ) {
|
2022-11-12 15:51:22 +01:00
|
|
|
const listElem = dom.clone('#templates .filterList');
|
|
|
|
const sourceElem = qs$(listElem, '.filterListSource');
|
2020-11-15 16:19:09 +01:00
|
|
|
sourceElem.href += encodeURIComponent(list.assetKey);
|
2023-05-21 03:35:52 +02:00
|
|
|
sourceElem.append(i18n.patchUnicodeFlags(list.title));
|
2020-11-15 16:19:09 +01:00
|
|
|
if ( typeof list.supportURL === 'string' && list.supportURL !== '' ) {
|
2022-11-12 15:51:22 +01:00
|
|
|
const supportElem = qs$(listElem, '.filterListSupport');
|
|
|
|
dom.attr(supportElem, 'href', list.supportURL);
|
|
|
|
dom.cl.remove(supportElem, '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
|
|
|
}
|
2022-11-15 15:44:19 +01:00
|
|
|
qs$('#whyex').style.removeProperty('visibility');
|
2019-09-17 21:15:01 +02:00
|
|
|
})();
|
2015-03-26 00:28:22 +01:00
|
|
|
|
2015-03-30 19:10:29 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.text('#theURL > p > span:first-of-type', details.url);
|
|
|
|
dom.text('#why', 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 = '';
|
|
|
|
}
|
2022-11-12 15:51:22 +01:00
|
|
|
const li = dom.create('li');
|
|
|
|
let span = dom.create('span');
|
|
|
|
dom.text(span, name);
|
2015-09-10 15:51:49 +02:00
|
|
|
li.appendChild(span);
|
2015-09-14 13:21:35 +02:00
|
|
|
if ( name !== '' && value !== '' ) {
|
|
|
|
li.appendChild(document.createTextNode(' = '));
|
|
|
|
}
|
2022-11-12 15:51:22 +01:00
|
|
|
span = dom.create('span');
|
2015-09-10 15:51:49 +02:00
|
|
|
if ( reURL.test(value) ) {
|
2022-11-12 15:51:22 +01:00
|
|
|
const a = dom.create('a');
|
|
|
|
dom.attr(a, 'href', value);
|
|
|
|
dom.text(a, value);
|
2015-09-10 15:51:49 +02:00
|
|
|
span.appendChild(a);
|
|
|
|
} else {
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.text(span, value);
|
2015-09-10 15:51:49 +02:00
|
|
|
}
|
|
|
|
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 = '';
|
2022-09-13 23:44:24 +02:00
|
|
|
const li = liFromParam(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) ) {
|
2022-11-12 15:51:22 +01:00
|
|
|
const ul = dom.create('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;
|
|
|
|
};
|
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
if ( renderParams(qs$('#parsed'), details.url) === false ) {
|
2015-09-10 15:51:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.cl.remove('#toggleParse', 'hidden');
|
2015-09-10 15:51:49 +02:00
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.on('#toggleParse', 'click', ( ) => {
|
|
|
|
dom.cl.toggle('#theURL', 'collapsed');
|
2015-09-12 16:51:11 +02:00
|
|
|
vAPI.localStorage.setItem(
|
|
|
|
'document-blocked-expand-url',
|
2022-11-12 15:51:22 +01:00
|
|
|
(dom.cl.has('#theURL', 'collapsed') === false).toString()
|
2015-09-12 16:51:11 +02:00
|
|
|
);
|
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 => {
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.cl.toggle('#theURL', 'collapsed', value !== 'true' && value !== true);
|
2020-02-21 21:34:54 +01:00
|
|
|
});
|
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 ) {
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.on('#back', 'click', ( ) => {
|
|
|
|
window.history.back();
|
|
|
|
});
|
|
|
|
qs$('#bye').style.display = 'none';
|
2015-03-26 00:28:22 +01:00
|
|
|
} else {
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.on('#bye', 'click', ( ) => {
|
|
|
|
messaging.send('documentBlocked', {
|
|
|
|
what: 'closeThisTab',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
qs$('#back').style.display = 'none';
|
2015-03-26 00:28:22 +01:00
|
|
|
}
|
|
|
|
|
2019-05-22 00:56:59 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const getTargetHostname = function() {
|
2022-09-10 20:11:23 +02:00
|
|
|
return details.hn;
|
2019-05-22 00:56:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.on('#disableWarning', 'change', ev => {
|
2022-09-11 15:09:31 +02:00
|
|
|
const checked = ev.target.checked;
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.cl.toggle('[data-i18n="docblockedBack"]', 'disabled', checked);
|
|
|
|
dom.cl.toggle('[data-i18n="docblockedClose"]', 'disabled', checked);
|
2022-09-11 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.on('#proceed', 'click', ( ) => {
|
|
|
|
if ( qs$('#disableWarning').checked ) {
|
2022-09-10 20:11:23 +02:00
|
|
|
proceedPermanent();
|
|
|
|
} else {
|
|
|
|
proceedTemporary();
|
|
|
|
}
|
|
|
|
});
|
2015-03-26 00:28:22 +01:00
|
|
|
|
2015-03-30 23:42:12 +02:00
|
|
|
/******************************************************************************/
|