2015-05-03 05:30:29 +12:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2017-12-03 05:46:13 +13:00
|
|
|
uMatrix - a browser extension to block requests.
|
2018-10-07 03:51:34 +13:00
|
|
|
Copyright (C) 2015-present Raymond Hill
|
2015-05-03 05:30:29 +12: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 */
|
|
|
|
|
2017-12-07 03:47:20 +13:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-03 05:30:29 +12:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let details = {};
|
2015-05-03 05:30:29 +12:00
|
|
|
|
|
|
|
(function() {
|
2018-10-07 03:51:34 +13:00
|
|
|
let matches = /details=([^&]+)/.exec(window.location.search);
|
2017-12-03 05:46:13 +13:00
|
|
|
if ( matches === null ) { return; }
|
|
|
|
try {
|
|
|
|
details = JSON.parse(atob(matches[1]));
|
|
|
|
} catch(ex) {
|
2015-05-03 05:30:29 +12:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
uDom('.what').text(details.url);
|
2017-12-03 05:46:13 +13:00
|
|
|
// uDom('#why').text(details.why.slice(3));
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uMatrix/issues/502
|
|
|
|
// Code below originally imported from:
|
|
|
|
// https://github.com/gorhill/uBlock/blob/master/src/js/document-blocked.js
|
|
|
|
|
|
|
|
(function() {
|
2018-10-07 03:51:34 +13:00
|
|
|
let reURL = /^https?:\/\//;
|
2017-12-03 05:46:13 +13:00
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let liFromParam = function(name, value) {
|
2017-12-03 05:46:13 +13:00
|
|
|
if ( value === '' ) {
|
|
|
|
value = name;
|
|
|
|
name = '';
|
|
|
|
}
|
2018-10-07 03:51:34 +13:00
|
|
|
let li = document.createElement('li');
|
|
|
|
let span = document.createElement('span');
|
2017-12-03 05:46:13 +13:00
|
|
|
span.textContent = name;
|
|
|
|
li.appendChild(span);
|
|
|
|
if ( name !== '' && value !== '' ) {
|
|
|
|
li.appendChild(document.createTextNode(' = '));
|
|
|
|
}
|
|
|
|
span = document.createElement('span');
|
|
|
|
if ( reURL.test(value) ) {
|
2018-10-07 03:51:34 +13:00
|
|
|
let a = document.createElement('a');
|
2017-12-03 05:46:13 +13:00
|
|
|
a.href = a.textContent = value;
|
|
|
|
span.appendChild(a);
|
|
|
|
} else {
|
|
|
|
span.textContent = value;
|
|
|
|
}
|
|
|
|
li.appendChild(span);
|
|
|
|
return li;
|
|
|
|
};
|
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let safeDecodeURIComponent = function(s) {
|
2017-12-03 05:46:13 +13:00
|
|
|
try {
|
|
|
|
s = decodeURIComponent(s);
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let renderParams = function(parentNode, rawURL) {
|
|
|
|
let a = document.createElement('a');
|
2017-12-03 05:46:13 +13:00
|
|
|
a.href = rawURL;
|
|
|
|
if ( a.search.length === 0 ) { return false; }
|
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let pos = rawURL.indexOf('?');
|
|
|
|
let li = liFromParam(
|
|
|
|
vAPI.i18n('mainBlockedNoParamsPrompt'),
|
2017-12-03 05:46:13 +13:00
|
|
|
rawURL.slice(0, pos)
|
|
|
|
);
|
|
|
|
parentNode.appendChild(li);
|
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let params = a.search.slice(1).split('&');
|
2017-12-03 05:46:13 +13:00
|
|
|
for ( var i = 0; i < params.length; i++ ) {
|
2018-10-07 03:51:34 +13:00
|
|
|
let param = params[i];
|
|
|
|
let pos = param.indexOf('=');
|
2017-12-03 05:46:13 +13:00
|
|
|
if ( pos === -1 ) {
|
|
|
|
pos = param.length;
|
|
|
|
}
|
2018-10-07 03:51:34 +13:00
|
|
|
let name = safeDecodeURIComponent(param.slice(0, pos));
|
|
|
|
let value = safeDecodeURIComponent(param.slice(pos + 1));
|
2017-12-03 05:46:13 +13:00
|
|
|
li = liFromParam(name, value);
|
|
|
|
if ( reURL.test(value) ) {
|
2018-10-07 03:51:34 +13:00
|
|
|
let ul = document.createElement('ul');
|
2017-12-03 05:46:13 +13:00
|
|
|
renderParams(ul, value);
|
|
|
|
li.appendChild(ul);
|
|
|
|
}
|
|
|
|
parentNode.appendChild(li);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let hasParams = renderParams(uDom.nodeFromId('parsed'), details.url);
|
|
|
|
if ( hasParams === false ) { return; }
|
2017-12-03 05:46:13 +13:00
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let theURLNode = document.getElementById('theURL');
|
|
|
|
theURLNode.classList.add('hasParams');
|
|
|
|
theURLNode.classList.toggle(
|
|
|
|
'collapsed',
|
|
|
|
vAPI.localStorage.getItem('document-blocked-collapse-url') === 'true'
|
|
|
|
);
|
2017-12-03 05:46:13 +13:00
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
let toggleCollapse = function() {
|
2017-12-03 05:46:13 +13:00
|
|
|
vAPI.localStorage.setItem(
|
|
|
|
'document-blocked-collapse-url',
|
2018-10-07 03:51:34 +13:00
|
|
|
theURLNode.classList.toggle('collapsed').toString()
|
2017-12-03 05:46:13 +13:00
|
|
|
);
|
2018-10-07 03:51:34 +13:00
|
|
|
};
|
2017-12-03 05:46:13 +13:00
|
|
|
|
2018-10-07 03:51:34 +13:00
|
|
|
theURLNode.querySelector('.collapse').addEventListener(
|
|
|
|
'click',
|
|
|
|
toggleCollapse
|
|
|
|
);
|
|
|
|
theURLNode.querySelector('.expand').addEventListener(
|
|
|
|
'click',
|
|
|
|
toggleCollapse
|
2017-12-03 05:46:13 +13:00
|
|
|
);
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2015-05-03 05:30:29 +12:00
|
|
|
|
|
|
|
if ( window.history.length > 1 ) {
|
|
|
|
uDom('#back').on('click', function() { window.history.back(); });
|
|
|
|
uDom('#bye').css('display', 'none');
|
|
|
|
} else {
|
|
|
|
uDom('#bye').on('click', function() { window.close(); });
|
|
|
|
uDom('#back').css('display', 'none');
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// See if the target hostname is still blacklisted, and if not, navigate to it.
|
|
|
|
|
2017-12-07 03:47:20 +13:00
|
|
|
vAPI.messaging.send('main-blocked.js', {
|
2015-05-03 05:30:29 +12:00
|
|
|
what: 'mustBlock',
|
|
|
|
scope: details.hn,
|
|
|
|
hostname: details.hn,
|
2018-10-07 03:51:34 +13:00
|
|
|
type: details.type
|
|
|
|
}, response => {
|
2015-05-03 05:30:29 +12:00
|
|
|
if ( response === false ) {
|
|
|
|
window.location.replace(details.url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|