Counter fix

This commit is contained in:
Kevin Röbert 2017-08-23 14:01:48 +02:00
parent b07cd8c62c
commit 36d5cdd016
2 changed files with 54 additions and 29 deletions

View File

@ -204,13 +204,21 @@ function removeFieldsFormURL(provider, request)
badges[tabid] = 0; badges[tabid] = 0;
} }
browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid});
browser.storage.local.set({"globalCounter": ++globalCounter}); browser.storage.local.set({"globalCounter": ++globalCounter});
browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid});
changes = true; changes = true;
} }
} }
if(provider.isCaneling()){ if(provider.isCaneling()){
if(badges[tabid] == null)
{
badges[tabid] = 0;
}
browser.storage.local.set({"globalCounter": ++globalCounter});
browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid});
cancel = true; cancel = true;
} }
} }
@ -222,6 +230,19 @@ function removeFieldsFormURL(provider, request)
} }
}; };
/**
* Return the number of parameters query strings.
* @param {String} url URL as String
* @return {int} Number of Parameters
*/
function countFields(url)
{
var matches = url.match(/[a-z\d]+=[a-z\d]+/gi);
var count = matches? matches.length : 0;
return count;
}
/** /**
* Function which called from the webRequest to * Function which called from the webRequest to
* remove the tracking fields from the url. * remove the tracking fields from the url.
@ -231,7 +252,11 @@ function removeFieldsFormURL(provider, request)
*/ */
function clearUrl(request) function clearUrl(request)
{ {
browser.storage.local.set({"globalURLCounter": ++globalURLCounter}); var URLbeforeReplaceCount = countFields(request.url);
//Add Fields form Request to global url counter
globalURLCounter += URLbeforeReplaceCount;
browser.storage.local.set({"globalURLCounter": globalURLCounter});
browser.storage.local.get('globalStatus', clear); browser.storage.local.get('globalStatus', clear);
function clear(data){ function clear(data){

View File

@ -70,7 +70,7 @@ function changeStatistics(){
globalURLCounter = 0; globalURLCounter = 0;
} }
globalPercentage.text((globalCounter/globalURLCounter).toFixed(3)*100+"%"); globalPercentage.text(((globalCounter/globalURLCounter)*100).toFixed(3)+"%");
}); });
}; };