Better performance + "unlimitedStorage" permission

+ Changed the regex interpretation for better performance.
+ Also asked for "unlimitedStorage" permission to have enough space for user generated rules.
This commit is contained in:
Kevin Röbert 2019-03-14 17:59:16 +01:00
parent 43a510efe7
commit 80af6f6fea
2 changed files with 57 additions and 49 deletions

View File

@ -1,20 +1,20 @@
/* /*
* ClearURLs * ClearURLs
* Copyright (c) 2017-2019 Kevin Röbert * Copyright (c) 2017-2019 Kevin Röbert
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/*jshint esversion: 6 */ /*jshint esversion: 6 */
/* /*
@ -29,6 +29,7 @@ var dataHash;
var localDataHash; var localDataHash;
var os; var os;
var currentURL; var currentURL;
var lastVisited = "";
function start() function start()
{ {
@ -237,8 +238,7 @@ function start()
* @param {boolean} isActive Is this rule active? * @param {boolean} isActive Is this rule active?
*/ */
this.addRule = function(rule, isActive = true) { this.addRule = function(rule, isActive = true) {
// Add start and end delimiters to rule rule = "([\\/|\\?]|(&|&amp;))("+rule+"=[^\\/|\\?|&]*)";
rule = "^"+rule+"=[^\\/|\\?|&]*(\\/|&(amp;)?)?$";
if(isActive) if(isActive)
{ {
@ -414,41 +414,42 @@ function start()
* before the last ?. With adding a ? on the quantifier *, * before the last ?. With adding a ? on the quantifier *,
* we fixed this problem. * we fixed this problem.
*/ */
fields = extractFileds(url.replace(new RegExp(".*?\\?", "i"), "")); fields = "?"+url.replace(new RegExp(".*?\\?", "i"), "");
fields.forEach(function(field, index) { rules.forEach(function(rule) {
rules.forEach(function(rule) { var beforReplace = fields;
var beforReplace = fields.flat().join("&"); fields = fields.replace(new RegExp(rule, "gi"), "");
var match = new RegExp(rule, "i").test(field);
if(match) { if(beforReplace !== fields)
delete fields[index]; {
//Log the action
//Log the action if(storage.loggingStatus)
pushToLog(domain+"?"+beforReplace, domain+"?"+fields.flat().join("&"), rule); {
pushToLog(domain+beforReplace, domain+"?"+extractFileds(fields).flat().join("&"), rule);
if(badges[tabid] == null) 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;
} }
});
if(badges[tabid] == null) 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;
}
}); });
if(fields.flat().length > 0) var finalFields = extractFileds(fields).flat();
if(finalFields.length > 0)
{ {
url = domain+"?"+fields.flat().join("&"); url = domain+"?"+finalFields.join("&");
} }
else{ else{
url = domain; url = domain;
@ -507,6 +508,10 @@ function start()
increaseGlobalURLCounter(URLbeforeReplaceCount); increaseGlobalURLCounter(URLbeforeReplaceCount);
if(storage.globalStatus){ if(storage.globalStatus){
// The URL is already cleaned
if(lastVisited === request.url) {
return {};
}
var result = { var result = {
"changes": false, "changes": false,
@ -550,6 +555,8 @@ function start()
* a loop. * a loop.
*/ */
if(result.changes){ if(result.changes){
lastVisited = result.url;
return { return {
redirectUrl: result.url redirectUrl: result.url
}; };

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "ClearURLs", "name": "ClearURLs",
"version": "1.5a", "version": "1.5.1a",
"author": "Kevin R.", "author": "Kevin R.",
"description": "Remove tracking elements form URLs.", "description": "Remove tracking elements form URLs.",
"homepage_url": "https://gitlab.com/KevinRoebert/ClearUrls", "homepage_url": "https://gitlab.com/KevinRoebert/ClearUrls",
@ -50,7 +50,8 @@
"webRequest", "webRequest",
"webRequestBlocking", "webRequestBlocking",
"storage", "storage",
"tabs" "tabs",
"unlimitedStorage"
], ],
"background": { "background": {
"scripts": [ "scripts": [