From 257334b4c2a4d68252a415b94042b83a62c947fb Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 10 May 2015 18:22:52 -0400 Subject: [PATCH] importing rp rules --- src/js/user-rules.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/js/user-rules.js b/src/js/user-rules.js index cfd0362..1f700f2 100644 --- a/src/js/user-rules.js +++ b/src/js/user-rules.js @@ -95,14 +95,29 @@ var processUserRules = function(response) { /******************************************************************************/ +var fromRequestPolicy = function(content) { + // https://github.com/chrisaljoudi/uBlock/issues/757 + // Support RequestPolicy rule syntax + var matches = /\[origins-to-destinations\]([^\[]+)/.exec(content); + if ( matches === null || matches.length !== 2 ) { + return content; + } + return matches[1].trim() + .replace(/\|/g, ' ') + .replace(/\n/g, ' * allow\n'); +}; + +/******************************************************************************/ + function handleImportFilePicker() { var fileReaderOnLoadHandler = function() { if ( typeof this.result !== 'string' || this.result === '' ) { return; } + var result = fromRequestPolicy(this.result); var request = { 'what': 'setUserRules', - 'temporaryRules': rulesFromHTML('#diff .right li') + '\n' + this.result + 'temporaryRules': rulesFromHTML('#diff .right li') + '\n' + result }; messager.send(request, processUserRules); };