From 2e7c4385ad6b60ae9f86b7e7f6a68f0dfee5509c Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sun, 23 May 2021 10:28:25 +0800 Subject: [PATCH 1/2] allow only filter some HTTP methods --- clearurls.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/clearurls.js b/clearurls.js index e0ed7bd..e1f33f9 100644 --- a/clearurls.js +++ b/clearurls.js @@ -216,6 +216,12 @@ function start() { for (let re = 0; re < redirections.length; re++) { providers[p].addRedirection(redirections[re]); } + + let methods = data.providers[prvKeys[p]].getOrDefault('methods', []); + //Add HTTP methods list to provider + for (let re = 0; re < methods.length; re++) { + providers[p].addMethod(methods[re]); + } } } @@ -344,6 +350,7 @@ function start() { let disabled_rawRules = {}; let enabled_referralMarketing = {}; let disabled_referralMarketing = {}; + let methods = []; if (_completeProvider) { enabled_rules[".*"] = true; @@ -496,6 +503,28 @@ function start() { } }; + /** + * Add a HTTP method to methods list. + * + * @param {String} method HTTP Method Name + */ + this.addMethod = function (method) { + if (methods.indexOf(method) == -1) { + methods.push(method); + } + } + + /** + * Check the requests' method. + * + * @param {requestDetails} details Requests deatils + * @returns {boolean} if need filter? true: false + */ + this.matchMethod = function (details) { + if (!methods.length) return true; + return methods.indexOf(details['method']) > -1 ? true : false; + } + /** * Private helper method to check if the url * an exception. @@ -598,6 +627,7 @@ function start() { * Call for every provider the removeFieldsFormURL method. */ for (let i = 0; i < providers.length; i++) { + if (!providers[i].matchMethod(request)) continue; if (providers[i].matchURL(request.url)) { result = removeFieldsFormURL(providers[i], request.url, false, request); } From 3b468fbdb718d49bdb94d8ef8d2dd183cd5de219 Mon Sep 17 00:00:00 2001 From: Kevin R Date: Mon, 27 Dec 2021 20:12:51 +0100 Subject: [PATCH 2/2] Simplify expression --- clearurls.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/clearurls.js b/clearurls.js index e1f33f9..ef3437a 100644 --- a/clearurls.js +++ b/clearurls.js @@ -505,24 +505,24 @@ function start() { /** * Add a HTTP method to methods list. - * + * * @param {String} method HTTP Method Name */ this.addMethod = function (method) { - if (methods.indexOf(method) == -1) { + if (methods.indexOf(method) === -1) { methods.push(method); } } /** * Check the requests' method. - * - * @param {requestDetails} details Requests deatils - * @returns {boolean} if need filter? true: false + * + * @param {requestDetails} details Requests details + * @returns {boolean} should be filtered or not */ this.matchMethod = function (details) { if (!methods.length) return true; - return methods.indexOf(details['method']) > -1 ? true : false; + return methods.indexOf(details['method']) > -1; } /** @@ -599,7 +599,7 @@ function start() { * Function which called from the webRequest to * remove the tracking fields from the url. * - * @param {webRequest} request webRequest-Object + * @param {requestDetails} request webRequest-Object * @return {Array} redirectUrl or none */ function clearUrl(request) {