Merge branch 'master' into 'master'

Whitelist support

See merge request KevinRoebert/ClearUrls!87
This commit is contained in:
2155X
2021-01-31 11:41:51 +00:00
7 changed files with 218 additions and 1 deletions

View File

@@ -231,6 +231,22 @@
"message": "Here you can find the cleaned URLs:",
"description": "This string is used as title on the cleaning tool page for the clean URLs."
},
"whitelists_page_title": {
"message": "ClearURLs Whitelists Manager",
"description": "This string is used as title on the whitelists page."
},
"whitelists_description": {
"message": "Using this tool you can whitelist certain URLs so they will not be cleared. You can paste in multiple URLs at once, but every URL must be on a separate line.",
"description": "This string is used as description of the whitelists manager."
},
"whitelists_btn": {
"message": "Save Changes",
"description": "This string is used as name for the whitelists manager save button."
},
"whitelists_urls_label": {
"message": "Paste the whitelisted URLs:",
"description": "This string is used as title on the whitelists manager page for the whitelisted URLs."
},
"local_hosts_skipping": {
"message": "Skip URLs on local hosts (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, 169.254.0.0/16, 127.0.0.1, localhost)",
"description": "This string is used as label for the local host skipping switch"

View File

@@ -663,13 +663,34 @@ function start() {
* Check the request.
*/
function promise(requestDetails) {
if (isDataURL(requestDetails)) {
if (isWhitelistedURL(requestDetails) || isDataURL(requestDetails)) {
return {};
} else {
return clearUrl(requestDetails);
}
}
/**
* Check if URL is whitelisted
*
* @type {requestDetails}
* @return {boolean}
*/
function isWhitelistedURL(requestDetails) {
if (requestDetails.url == null)
return false;
let whitelistsData = storage['WhitelistedURLs'];
for (let i = 0; i < whitelistsData.length; i++) {
if (whitelistsData[i] !== null && whitelistsData[i] !== "" && Boolean(requestDetails.url.match(whitelistsData[i]))) {
return true;
}
}
return false;
}
/**
* To prevent long loading on data urls
* we will check here for data urls.

View File

@@ -199,6 +199,7 @@ function resetGlobalCounter(){
document.getElementById('loggingPage').href = browser.extension.getURL('./html/log.html');
document.getElementById('settings').href = browser.extension.getURL('./html/settings.html');
document.getElementById('cleaning_tools').href = browser.extension.getURL('./html/cleaningTool.html');
document.getElementById('whitelists').href = browser.extension.getURL('./html/whitelists.html');
setText();
});
})();

View File

@@ -53,6 +53,7 @@ function storageDataAsString(key) {
let value = storage[key];
switch (key) {
case "WhitelistedURLs":
case "ClearURLsData":
case "log":
return JSON.stringify(value);
@@ -145,6 +146,7 @@ function getEntireData() {
*/
function setData(key, value) {
switch (key) {
case "WhitelistedURLs":
case "ClearURLsData":
case "log":
storage[key] = JSON.parse(value);
@@ -182,6 +184,7 @@ function initStorage(items) {
* Set default values for the settings.
*/
function initSettings() {
storage.WhitelistedURLs = [];
storage.ClearURLsData = [];
storage.dataHash = "";
storage.badgedStatus = true;

98
core_js/whitelists.js Normal file
View File

@@ -0,0 +1,98 @@
/*
* ClearURLs
* Copyright (c) 2017-2020 Kevin Röbert
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* 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/>.
*/
/*jshint esversion: 6 */
/**
* Load only when document is ready
*/
(function() {
setText();
loadWhitelist();
document.getElementById('whitelists_btn').onclick = saveWhitelist;
})();
/**
* This function saves all URLs line by line in the textarea for whitelisting.
*/
function saveWhitelist() {
const urlsBox = document.getElementById('whitelistedURLs');
const urls = urlsBox.value.split('\n');
let temp = [];
for (let i = 0; i < urls.length; i++) {
temp.push(urls[i]);
}
browser.runtime.sendMessage({
function: "setData",
params: ['WhitelistedURLs', JSON.stringify(temp)]
}).catch(handleError);
loadWhitelist();
}
/**
* This function loads all URLs line by line in the textarea for whitelisting.
*/
function loadWhitelist() {
const urlsBox = document.getElementById('whitelistedURLs');
urlsBox.value = "";
browser.runtime.sendMessage({
function: "getData",
params: ['WhitelistedURLs']
}).then((data) => {
let arr = data.response;
for (let i = 0; i < arr.length; i++) {
urlsBox.value = urlsBox.value + arr[i];
if(i < arr.length - 1) {
urlsBox.value = urlsBox.value + "\n";
}
}
}).catch(handleError);
}
/**
* Translate a string with the i18n API.
*
* @param {string} string Name of the attribute used for localization
*/
function translate(string)
{
return browser.i18n.getMessage(string);
}
/**
* Set the text for the UI.
*/
function setText()
{
document.title = translate('whitelists_page_title');
document.getElementById('page_title').textContent = translate('whitelists_page_title');
document.getElementById('whitelists_description').textContent = translate('whitelists_description');
document.getElementById('whitelists_btn').textContent = translate('whitelists_btn');
document.getElementById('whitelists_urls_label').textContent = translate('whitelists_urls_label');
}
function handleError(error) {
console.log(`Error: ${error}`);
}

View File

@@ -54,6 +54,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<div class="row" id="references_section">
<div class="col-sm-1 text-center">
<a id="whitelists" target="_blank"><span class="fas fa-cog" style="font-size: 1.5em; margin-right: 1em;"></span></a>
<a id="cleaning_tools" target="_blank"><span class="fas fa-tools" style="font-size: 1.5em; margin-right: 1em;"></span></a>
<a id="settings" target="_blank"><span class="fas fa-cog" style="font-size: 1.5em"></span></a>
</div>

77
html/whitelists.html Normal file
View File

@@ -0,0 +1,77 @@
<!--
ClearURLs
Copyright (c) 2017-2020 Kevin Röbert
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
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/>.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>ClearURLs whitelists manager</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" sizes="any" type="image/svg+xml" href="/img/clearurls.svg">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/core.css">
<style>
td {
word-wrap: break-word;
max-width: 200px;
}
</style>
</head>
<body>
<nav class="navbar-margin navbar navbar-dark bg-dark">
<div class="container">
<span class="navbar-brand">
<span class="float-left"><img src="../img/clearurls.svg"
width="30" height="30" alt=""></span>
<span style="color: #ff7800;" class="float-right" id="page_title"></span><br />
<span class="badge badge-warning float-left small-version"
id="version"></span>
</span>
</div>
</nav>
<div class="row">
<div class="col-lg-4 offset-lg-4 text-center">
<h4 id="whitelists_description"></h4>
<br />
<div class="form-group">
<label for="whitelistedURLs" id="whitelists_urls_label"></label>
<textarea id="whitelistedURLs" name="whitelistedURLs" class="form-control" rows="8" cols="60"></textarea>
</div>
<br />
<p class="text-center">
<button type="button" id="whitelists_btn"
class="btn btn-success" title="Save changes"></button>
</p>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="../browser-polyfill.js"></script>
<script src="../core_js/whitelists.js"></script>
<script src="../core_js/write_version.js"></script>
</body>
</html>