From 349b645d8852571dca3b275d1c51f16d82ff46ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20R=C3=B6bert?= Date: Sat, 23 Jun 2018 12:56:37 +0200 Subject: [PATCH] Version 1.3.3.1 I've updated the ClearURLs core, so that ClearURLs only cleans the fields from urls. This means that ClearURLs can no longer examine all components of a URL and, if necessary, remove something, but only the so-called GET fields. This restricts not hardly, since everything that is not a GET field is a part of the url (the path) and should not actually be removed. However, because ClearURLs was able to remove these path elements, this problem came up again. Now ClearURLs can only remove GET fields and thus no longer destroy paths. I hope that there are fewer problems now. Another little side effect of the change, ClearURLs is now working more efficiently. --- clearurls.js | 74 ++++++++++++++++++++++++++++++++++++--------------- manifest.json | 2 +- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/clearurls.js b/clearurls.js index b585aaf..ed5f988 100644 --- a/clearurls.js +++ b/clearurls.js @@ -336,6 +336,8 @@ function start(items) function removeFieldsFormURL(provider, request) { var url = request.url; + var domain = url.replace(new RegExp("\\?.*", "i"), ""); + var fields = ""; var rules = provider.getRules(); var changes = false; var cancel = false; @@ -357,34 +359,50 @@ function start(items) }; } - for (var i = 0; i < rules.length; i++) { - var beforReplace = url; + /** + * Only test for matches, if there are fields that can be cleaned. + */ + if(existsFields(url)) + { + fields = url.replace(new RegExp(".*\\?", "i"), ""); - url = url.replace(new RegExp(rules[i], "i"), ""); + for (var i = 0; i < rules.length; i++) { + var beforReplace = fields; - if(beforReplace != url) - { - //Log the action - pushToLog(beforReplace, url, rules[i]); + fields = fields.replace(new RegExp(rules[i], "i"), ""); - if(badges[tabid] == null) + if(beforReplace != fields) { - badges[tabid] = 0; - } + //Log the action + pushToLog(domain+"?"+beforReplace, domain+"?"+fields, rules[i]); - increaseURLCounter(); - - if(!checkOSAndroid()) - { - if(storage.badgedStatus) { - browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid}); - } - else + if(badges[tabid] == null) { - browser.browserAction.setBadgeText({text: "", tabId: tabid}); + badges[tabid] = 0; } - } + increaseURLCounter(); + + if(!checkOSAndroid()) + { + if(storage.badgedStatus) { + browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid}); + } + else + { + browser.browserAction.setBadgeText({text: "", tabId: tabid}); + } + } + + changes = true; + } + } + url = domain+"?"+fields; + } + else { + if(domain != url) + { + url = domain; changes = true; } } @@ -417,8 +435,6 @@ function start(items) "url": url, "cancel": cancel }; - - } /** @@ -434,6 +450,19 @@ function start(items) return count; } + /** + * Returns true if fields exists. + * @param {String} url URL as String + * @return {boolean} + */ + function existsFields(url) + { + var matches = (url.match(/\?.+/i) || []); + var count = matches.length; + + return (count > 0); + } + /** * Function which called from the webRequest to * remove the tracking fields from the url. @@ -492,6 +521,7 @@ function start(items) * a loop. */ if(result.changes){ + console.log(result.url); return { redirectUrl: result.url }; diff --git a/manifest.json b/manifest.json index b4df38b..a8afea9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "ClearURLs", - "version": "1.3.2.0", + "version": "1.3.3.1", "author": "Kevin R.", "description": "Remove tracking elements form URLs.", "homepage_url": "https://gitlab.com/KevinRoebert/ClearUrls",