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:
parent
43a510efe7
commit
80af6f6fea
33
clearurls.js
33
clearurls.js
|
@ -29,6 +29,7 @@ var dataHash;
|
|||
var localDataHash;
|
||||
var os;
|
||||
var currentURL;
|
||||
var lastVisited = "";
|
||||
|
||||
function start()
|
||||
{
|
||||
|
@ -237,8 +238,7 @@ function start()
|
|||
* @param {boolean} isActive Is this rule active?
|
||||
*/
|
||||
this.addRule = function(rule, isActive = true) {
|
||||
// Add start and end delimiters to rule
|
||||
rule = "^"+rule+"=[^\\/|\\?|&]*(\\/|&(amp;)?)?$";
|
||||
rule = "([\\/|\\?]|(&|&))("+rule+"=[^\\/|\\?|&]*)";
|
||||
|
||||
if(isActive)
|
||||
{
|
||||
|
@ -414,18 +414,19 @@ function start()
|
|||
* before the last ?. With adding a ? on the quantifier *,
|
||||
* 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) {
|
||||
var beforReplace = fields.flat().join("&");
|
||||
var match = new RegExp(rule, "i").test(field);
|
||||
|
||||
if(match) {
|
||||
delete fields[index];
|
||||
var beforReplace = fields;
|
||||
fields = fields.replace(new RegExp(rule, "gi"), "");
|
||||
|
||||
if(beforReplace !== fields)
|
||||
{
|
||||
//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;
|
||||
|
||||
|
@ -444,11 +445,11 @@ function start()
|
|||
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{
|
||||
url = domain;
|
||||
|
@ -507,6 +508,10 @@ function start()
|
|||
increaseGlobalURLCounter(URLbeforeReplaceCount);
|
||||
|
||||
if(storage.globalStatus){
|
||||
// The URL is already cleaned
|
||||
if(lastVisited === request.url) {
|
||||
return {};
|
||||
}
|
||||
|
||||
var result = {
|
||||
"changes": false,
|
||||
|
@ -550,6 +555,8 @@ function start()
|
|||
* a loop.
|
||||
*/
|
||||
if(result.changes){
|
||||
lastVisited = result.url;
|
||||
|
||||
return {
|
||||
redirectUrl: result.url
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "ClearURLs",
|
||||
"version": "1.5a",
|
||||
"version": "1.5.1a",
|
||||
"author": "Kevin R.",
|
||||
"description": "Remove tracking elements form URLs.",
|
||||
"homepage_url": "https://gitlab.com/KevinRoebert/ClearUrls",
|
||||
|
@ -50,7 +50,8 @@
|
|||
"webRequest",
|
||||
"webRequestBlocking",
|
||||
"storage",
|
||||
"tabs"
|
||||
"tabs",
|
||||
"unlimitedStorage"
|
||||
],
|
||||
"background": {
|
||||
"scripts": [
|
||||
|
|
Loading…
Reference in New Issue
Block a user