Preparations for costume rules

+ Preparations for costume rules
- Feature "Report URLs"
+ Auto hash rules
+ Minimize rules length
+ Add start and end delimiters to rules
This commit is contained in:
Kevin Röbert
2019-03-12 18:13:23 +01:00
parent 81bc71de5e
commit 9c638c52f9
10 changed files with 541 additions and 140 deletions

View File

@@ -13,7 +13,6 @@ var hashStatus;
var loggingStatus;
var statisticsStatus;
var currentURL;
var reportServer;
async function getData()
{
@@ -29,7 +28,6 @@ async function getData()
hashStatus = data.hashStatus;
loggingStatus = data.loggingStatus;
statisticsStatus = data.statisticsStatus;
reportServer = data.reportServer;
browser.runtime.sendMessage({
function: "getCurrentURL",
@@ -201,7 +199,6 @@ $(document).ready(function(){
changeSwitchButton("statistics", "statisticsStatus");
$('#loggingPage').attr('href', browser.extension.getURL('./html/log.html'));
$('#settings').attr('href', browser.extension.getURL('./html/settings.html'));
$('#reportButton').on("click", reportURL);
setText();
});
@@ -262,26 +259,6 @@ function translate(string)
return browser.i18n.getMessage(string);
}
/**
* Send the url to the DB on clearurls.röb.it to checked for tracking fields.
*/
function reportURL()
{
$.ajax({
url: reportServer+'/report_url.php?url='+encodeURI(currentURL),
success: function(result) {
BootstrapDialog.show({
message: translate('success_report_url')
});
},
error: function(result) {
BootstrapDialog.show({
message: translate('error_report_url')
});
}
});
}
function handleError(error) {
console.log(`Error: ${error}`);
}

View File

@@ -83,11 +83,6 @@ function save()
params: ["types", $('input[name=types]').val()]
}).then(handleResponse, handleError);
browser.runtime.sendMessage({
function: "setData",
params: ["reportServer", $('input[name=report_server]').val()]
}).then(handleResponse, handleError);
browser.runtime.sendMessage({
function: "saveOnExit",
params: []
@@ -135,11 +130,6 @@ function getData()
function: "getData",
params: ["types"]
}).then((data) => handleResponseData(data, "types", "types"), handleError);
browser.runtime.sendMessage({
function: "getData",
params: ["reportServer"]
}).then((data) => handleResponseData(data, "reportServer", "report_server"), handleError);
}
/**
@@ -157,7 +147,6 @@ function setText()
$('#types_label').html(translate('setting_types_label'));
$('#save_settings_btn').text(translate('settings_html_save_button'));
$('#save_settings_btn').prop('title', translate('settings_html_save_button_title'));
$('#report_server_label').html(translate('setting_report_server_label'));
}
/**

View File

@@ -79,7 +79,7 @@ function setData(key, value)
break;
case "hashURL":
case "ruleURL":
storage[key] = replaceOldGithubURLs(value);
storage[key] = replaceOldURLs(value);
break;
case "types":
storage[key] = value.split(',');
@@ -132,23 +132,27 @@ function initSettings()
storage.log = {"log": []};
storage.statisticsStatus = true;
storage.badged_color = "ffa500";
storage.hashURL = "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/rules.hash";
storage.ruleURL = "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/data.json";
storage.hashURL = "https://gitlab.com/KevinRoebert/ClearUrls/-/jobs/artifacts/master/raw/rules.min.hash?job=hash%20rules";
storage.ruleURL = "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/data.min.json";
storage.types = ["font", "image", "imageset", "main_frame", "media", "object", "object_subrequest", "other", "script", "stylesheet", "sub_frame", "websocket", "xbl", "xml_dtd", "xmlhttprequest", "xslt"];
storage.reportServer = "https://clearurls.xn--rb-fka.it";
}
/**
* Replace the old GitHub URLs with the
* Replace the old URLs with the
* new GitLab URLs.
*/
function replaceOldGithubURLs(url)
function replaceOldURLs(url)
{
switch (url) {
case "https://raw.githubusercontent.com/KevinRoebert/ClearUrls/master/data/rules.hash?flush_cache=true":
return "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/rules.hash";
case "https://raw.githubusercontent.com/KevinRoebert/ClearUrls/master/data/data.json?flush_cache=true":
return "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/data.json";
case "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/rules.hash":
return "https://gitlab.com/KevinRoebert/ClearUrls/-/jobs/artifacts/master/raw/rules.min.hash?job=hash%20rules";
case "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/data.json":
return "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/data.min.json";
default:
return url;
}

View File

@@ -53,10 +53,17 @@ function checkOSAndroid()
*/
function countFields(url)
{
var matches = (url.match(/[^\/|\?|&]+=[^\/|\?|&]+/gi) || []);
var count = matches.length;
return extractFileds(url).length;
}
return count;
/**
* Extract the fields from an url.
* @param {String} url URL as String
* @return {Array} Fields as array
*/
function extractFileds(url)
{
return (url.match(/[^\/|\?|&]+=[^\/|\?|&]+/gi) || []);
}
/**