mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-09-30 09:06:56 +13:00
this fixes #270
This commit is contained in:
parent
22d5f9b052
commit
07ba0a0a4b
1 changed files with 53 additions and 3 deletions
|
@ -95,12 +95,13 @@ var processUserRules = function(response) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var fromRequestPolicy = function(content) {
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/757
|
// https://github.com/chrisaljoudi/uBlock/issues/757
|
||||||
// Support RequestPolicy rule syntax
|
// Support RequestPolicy rule syntax
|
||||||
|
|
||||||
|
var fromRequestPolicy = function(content) {
|
||||||
var matches = /\[origins-to-destinations\]([^\[]+)/.exec(content);
|
var matches = /\[origins-to-destinations\]([^\[]+)/.exec(content);
|
||||||
if ( matches === null || matches.length !== 2 ) {
|
if ( matches === null || matches.length !== 2 ) {
|
||||||
return content;
|
return '';
|
||||||
}
|
}
|
||||||
return matches[1].trim()
|
return matches[1].trim()
|
||||||
.replace(/\|/g, ' ')
|
.replace(/\|/g, ' ')
|
||||||
|
@ -109,12 +110,61 @@ var fromRequestPolicy = function(content) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/270
|
||||||
|
|
||||||
|
var fromNoScript = function(content) {
|
||||||
|
var noscript = null;
|
||||||
|
try {
|
||||||
|
noscript = JSON.parse(content);
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
noscript === null ||
|
||||||
|
typeof noscript !== 'object' ||
|
||||||
|
typeof noscript.prefs !== 'object' ||
|
||||||
|
typeof noscript.prefs.clearClick === undefined ||
|
||||||
|
typeof noscript.whitelist !== 'string' ||
|
||||||
|
typeof noscript.V !== 'string'
|
||||||
|
) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
var out = {};
|
||||||
|
var reBad = /[a-z]+:\w*$/;
|
||||||
|
var reURL = /[a-z]+:\/\/([0-9a-z.-]+)/;
|
||||||
|
var directives = noscript.whitelist.split(/\s+/);
|
||||||
|
var i = directives.length;
|
||||||
|
var directive, matches;
|
||||||
|
while ( i-- ) {
|
||||||
|
directive = directives[i].trim();
|
||||||
|
if ( directive === '' ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( reBad.test(directive) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
matches = reURL.exec(directive);
|
||||||
|
if ( matches !== null ) {
|
||||||
|
directive = matches[1];
|
||||||
|
}
|
||||||
|
out['* ' + directive + ' script allow'] = true;
|
||||||
|
}
|
||||||
|
return Object.keys(out).join('\n');
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
function handleImportFilePicker() {
|
function handleImportFilePicker() {
|
||||||
var fileReaderOnLoadHandler = function() {
|
var fileReaderOnLoadHandler = function() {
|
||||||
if ( typeof this.result !== 'string' || this.result === '' ) {
|
if ( typeof this.result !== 'string' || this.result === '' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var result = fromRequestPolicy(this.result);
|
var result = fromRequestPolicy(this.result);
|
||||||
|
if ( result === '' ) {
|
||||||
|
result = fromNoScript(this.result);
|
||||||
|
if ( result === '' ) {
|
||||||
|
result = this.result;
|
||||||
|
}
|
||||||
|
}
|
||||||
var request = {
|
var request = {
|
||||||
'what': 'setUserRules',
|
'what': 'setUserRules',
|
||||||
'temporaryRules': rulesFromHTML('#diff .right li') + '\n' + result
|
'temporaryRules': rulesFromHTML('#diff .right li') + '\n' + result
|
||||||
|
|
Loading…
Reference in a new issue