mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-17 16:02:33 +01:00
3c85c03194
<https://github.com/gorhill/uBlock/issues/3436>: a new per-site switch has been added, no-scripting, which purpose is to wholly disable/enable javascript for a given site. This new switch has precedence over all other ways javascript can be disabled, including precedence over dynamic filtering rules. The popup panel will report the number of script resources which have been seen by uBO for the current page. There is a minor inaccuracy to be fixed regarding the count, and which fix requires to extend request journaling. <https://github.com/gorhill/uBlock/issues/308>: the `noscript` tags will now be respected when the new no-scripting switch is in effect on a given site. A default setting has been added to the _Settings_ pane to disable/enable globally the new no-script switch, such that one can work in default-deny mode regarding javascript execution. <https://github.com/uBlockOrigin/uBlock-issues/issues/155>: a new hidden setting, `requestJournalProcessPeriod`, has been added to allow controlling the delay before uBO internally process it's network request journal queue. Default to 1000 (milliseconds).
84 lines
3.1 KiB
JavaScript
84 lines
3.1 KiB
JavaScript
/*******************************************************************************
|
|
|
|
uBlock Origin - a browser extension to block requests.
|
|
Copyright (C) 2014-present 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
|
|
*/
|
|
|
|
// Code below has been imported from uMatrix and modified to fit uBO:
|
|
// https://github.com/gorhill/uMatrix/blob/3f8794dd899a05e066c24066c6c0a2515d5c60d2/src/js/contentscript.js#L464-L531
|
|
|
|
'use strict';
|
|
|
|
/******************************************************************************/
|
|
|
|
// https://github.com/gorhill/uMatrix/issues/232
|
|
// Force `display` property, Firefox is still affected by the issue.
|
|
|
|
(function() {
|
|
let noscripts = document.querySelectorAll('noscript');
|
|
if ( noscripts.length === 0 ) { return; }
|
|
|
|
let redirectTimer,
|
|
reMetaContent = /^\s*(\d+)\s*;\s*url=(['"]?)([^'"]+)\2/i,
|
|
reSafeURL = /^https?:\/\//;
|
|
|
|
let autoRefresh = function(root) {
|
|
let meta = root.querySelector('meta[http-equiv="refresh"][content]');
|
|
if ( meta === null ) { return; }
|
|
let match = reMetaContent.exec(meta.getAttribute('content'));
|
|
if ( match === null || match[3].trim() === '' ) { return; }
|
|
let url = new URL(match[3], document.baseURI);
|
|
if ( reSafeURL.test(url.href) === false ) { return; }
|
|
redirectTimer = setTimeout(( ) => {
|
|
location.assign(url.href);
|
|
},
|
|
parseInt(match[1], 10) * 1000 + 1
|
|
);
|
|
meta.parentNode.removeChild(meta);
|
|
};
|
|
|
|
let morphNoscript = function(from) {
|
|
if ( /^application\/(?:xhtml\+)?xml/.test(document.contentType) ) {
|
|
let to = document.createElement('span');
|
|
while ( from.firstChild !== null ) {
|
|
to.appendChild(from.firstChild);
|
|
}
|
|
return to;
|
|
}
|
|
let parser = new DOMParser();
|
|
let doc = parser.parseFromString(
|
|
'<span>' + from.textContent + '</span>',
|
|
'text/html'
|
|
);
|
|
return document.adoptNode(doc.querySelector('span'));
|
|
};
|
|
|
|
for ( let noscript of noscripts ) {
|
|
let parent = noscript.parentNode;
|
|
if ( parent === null ) { continue; }
|
|
let span = morphNoscript(noscript);
|
|
span.style.setProperty('display', 'inline', 'important');
|
|
if ( redirectTimer === undefined ) {
|
|
autoRefresh(span);
|
|
}
|
|
parent.replaceChild(span, noscript);
|
|
}
|
|
})();
|
|
|
|
/******************************************************************************/
|