From a56a0592cc5c32a1ff07b2a385617f14c998a0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20R=C3=B6bert?= Date: Fri, 4 Aug 2017 03:08:46 +0200 Subject: [PATCH] Alles in einem --- clearurls.js | 48 ++++++++++++++++++++++++++++--------------- data/data.json | 19 +++++++++++++++++ rules/exceptions.json | 5 ----- rules/rules.json | 11 ---------- 4 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 data/data.json delete mode 100644 rules/exceptions.json delete mode 100644 rules/rules.json diff --git a/clearurls.js b/clearurls.js index 0a0dace..74c0e8b 100644 --- a/clearurls.js +++ b/clearurls.js @@ -1,3 +1,22 @@ +/* + * ################################################################## + * # Fetch Rules & Exception from URL # + * ################################################################## + */ +function fetchFromURL(url) +{ + fetch(url) + .then((response) => response.text().then(toJSON)); + + function toJSON(retrievedText) { + return JSON.parse(retrievedText); + } +} + +var globalRules = fetchFromURL('https://raw.githubusercontent.com/KevinRoebert/ClearUrls/master/rules/rules.json'); +var globalExceptions = fetchFromURL('https://raw.githubusercontent.com/KevinRoebert/ClearUrls/master/rules/exceptions.json'); +// ################################################################## + /* * ################################################################## * # Supertyp Provider # @@ -46,6 +65,10 @@ function Provider(_name,_completeProvider=false){ rules.push(rule); }; + this.setRules = function(_rules) { + rules = _rules; + }; + /** * Return all rules as an array. * @@ -92,14 +115,15 @@ function Provider(_name,_completeProvider=false){ */ var amazon = new Provider("Amazon"); amazon.setURLPattern('(https:\\/\\/||http:\\/\\/).*(\\.amazon\\.)\\w{2,}\\/.*'); - amazon.addException('.*(amazon\\.)\\w{2,}(\\/gp\\/).*'); - amazon.addRule('pf_rd_[a-zA-Z]=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); - amazon.addRule('qid=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); - amazon.addRule('sr=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); - amazon.addRule('srs=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); - amazon.addRule('.*(amazon-adsystem\\.com)\\/.*'); - amazon.addRule('.*(adsensecustomsearchads\\.com)\\/.*'); - amazon.addRule('pd_rd_[a-zA-Z]*=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); + amazon.setRules(globalRules); + // amazon.addException('.*(amazon\\.)\\w{2,}(\\/gp\\/).*'); + // amazon.addRule('pf_rd_[a-zA-Z]=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); + // amazon.addRule('qid=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); + // amazon.addRule('sr=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); + // amazon.addRule('srs=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); + // amazon.addRule('.*(amazon-adsystem\\.com)\\/.*'); + // amazon.addRule('.*(adsensecustomsearchads\\.com)\\/.*'); + // amazon.addRule('pd_rd_[a-zA-Z]*=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?'); // ################################################################## /* @@ -240,14 +264,6 @@ function clearUrl(request) }; -function fetchFromURL() -{ - fetch('https://fiddle.jshell.net/robots.txt') - .then((response) => response.text().then(yourCallback)); - - function yourCallback( retrievedText ) { /* . . . */ } -} - /** * Call by each Request and checking the url. * diff --git a/data/data.json b/data/data.json new file mode 100644 index 0000000..0dd77f4 --- /dev/null +++ b/data/data.json @@ -0,0 +1,19 @@ +{ + "providers": { + "amazon": { + "urlPattern": "", + "rules": [ + "pf_rd_[a-zA-Z]=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", + "qid=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", + "sr=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", + "srs=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", + ".*(amazon-adsystem\\.com)\\/.*", + ".*(adsensecustomsearchads\\.com)\\/.*", + "pd_rd_[a-zA-Z]*=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?" + ], + "exceptions": [ + ".*(amazon\\.)\\w{2,}(\\/gp\\/).*" + ] + } + } +} \ No newline at end of file diff --git a/rules/exceptions.json b/rules/exceptions.json deleted file mode 100644 index 3e9bd5f..0000000 --- a/rules/exceptions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "amazon": [ - ".*(amazon\\.)\\w{2,}(\\/gp\\/).*" - ] -} \ No newline at end of file diff --git a/rules/rules.json b/rules/rules.json deleted file mode 100644 index 487f0de..0000000 --- a/rules/rules.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "amazon": [ - "pf_rd_[a-zA-Z]=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", - "qid=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", - "sr=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", - "srs=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?", - ".*(amazon-adsystem\\.com)\\/.*", - ".*(adsensecustomsearchads\\.com)\\/.*", - "pd_rd_[a-zA-Z]*=[a-zA-Z0-9\\-\\.\\_]*[\\?|&]?" - ] -} \ No newline at end of file