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

@ -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 = "([\\/|\\?]|(&|&))("+rule+"=[^\\/|\\?|&]*)";
rule = "^"+rule+"=[^\\/|\\?|&]*(\\/|&(amp;)?)?$";
if(isActive) if(isActive)
{ {
@ -414,18 +414,19 @@ 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.flat().join("&"); var beforReplace = fields;
var match = new RegExp(rule, "i").test(field); fields = fields.replace(new RegExp(rule, "gi"), "");
if(match) {
delete fields[index];
if(beforReplace !== fields)
{
//Log the action //Log the action
pushToLog(domain+"?"+beforReplace, domain+"?"+fields.flat().join("&"), rule); if(storage.loggingStatus)
{
pushToLog(domain+beforReplace, domain+"?"+extractFileds(fields).flat().join("&"), rule);
}
if(badges[tabid] == null) badges[tabid] = 0; if(badges[tabid] == null) badges[tabid] = 0;
@ -444,11 +445,11 @@ function start()
changes = true; 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": [