mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-16 06:05:37 +07:00
Removed jQuery from core scripts
This commit is contained in:
@@ -24,18 +24,18 @@ var length = 0;
|
||||
/**
|
||||
* Load only when document is ready
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
(function() {
|
||||
setText();
|
||||
$('#cleaning_tool_btn').on("click", cleanURLs);
|
||||
});
|
||||
document.getElementById('cleaning_tool_btn').onclick = cleanURLs;
|
||||
})();
|
||||
|
||||
/**
|
||||
* This function cleans all URLs line by line in the textarea.
|
||||
*/
|
||||
function cleanURLs() {
|
||||
const cleanTArea = $('#cleanURLs');
|
||||
const dirtyTArea = $('#dirtyURLs');
|
||||
const urls = dirtyTArea.val().split('\n');
|
||||
const cleanTArea = document.getElementById('cleanURLs');
|
||||
const dirtyTArea = document.getElementById('dirtyURLs');
|
||||
const urls = dirtyTArea.value.split('\n');
|
||||
cleanedURLs = [];
|
||||
length = urls.length;
|
||||
|
||||
@@ -46,7 +46,7 @@ function cleanURLs() {
|
||||
}).then((data) => {
|
||||
cleanedURLs.push(data.response);
|
||||
if(i >= length-1) {
|
||||
cleanTArea.val(cleanedURLs.join('\n'));
|
||||
cleanTArea.value= cleanedURLs.join('\n');
|
||||
}
|
||||
}, handleError);
|
||||
}
|
||||
@@ -68,11 +68,11 @@ function translate(string)
|
||||
function setText()
|
||||
{
|
||||
document.title = translate('cleaning_tool_page_title');
|
||||
$('#page_title').text(translate('cleaning_tool_page_title'));
|
||||
$('#cleaning_tool_description').text(translate('cleaning_tool_description'));
|
||||
$('#cleaning_tool_btn').text(translate('cleaning_tool_btn'));
|
||||
$('#cleaning_tool_dirty_urls_label').text(translate('cleaning_tool_dirty_urls_label'));
|
||||
$('#cleaning_tool_clean_urls_label').text(translate('cleaning_tool_clean_urls_label'));
|
||||
document.getElementById('page_title').textContent = translate('cleaning_tool_page_title');
|
||||
document.getElementById('cleaning_tool_description').textContent = translate('cleaning_tool_description');
|
||||
document.getElementById('cleaning_tool_btn').textContent = translate('cleaning_tool_btn');
|
||||
document.getElementById('cleaning_tool_dirty_urls_label').textContent = translate('cleaning_tool_dirty_urls_label');
|
||||
document.getElementById('cleaning_tool_clean_urls_label').textContent = translate('cleaning_tool_clean_urls_label');
|
||||
}
|
||||
|
||||
function handleError(error) {
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
*/
|
||||
|
||||
/*jshint esversion: 6 */
|
||||
var element = $("#statistics_value");
|
||||
var elGlobalPercentage = $("#statistics_value_global_percentage");
|
||||
var elProgressbar_blocked = $('#progress_blocked');
|
||||
var elProgressbar_non_blocked = $('#progress_non_blocked');
|
||||
var elTotal = $('#statistics_total_elements');
|
||||
var element = document.getElementById('statistics_value');
|
||||
var elGlobalPercentage = document.getElementById('statistics_value_global_percentage');
|
||||
var elProgressbar_blocked = document.getElementById('progress_blocked');
|
||||
var elProgressbar_non_blocked = document.getElementById('progress_non_blocked');
|
||||
var elTotal = document.getElementById('statistics_total_elements');
|
||||
var globalPercentage = 0;
|
||||
var globalCounter;
|
||||
var globalurlcounter;
|
||||
@@ -55,11 +55,11 @@ function changeStatistics()
|
||||
|
||||
if(isNaN(Number(globalPercentage))) globalPercentage = 0;
|
||||
|
||||
element.text(globalCounter.toLocaleString());
|
||||
elGlobalPercentage.text(globalPercentage+"%");
|
||||
elProgressbar_blocked.css('width', globalPercentage+'%');
|
||||
elProgressbar_non_blocked.css('width', (100-globalPercentage)+'%');
|
||||
elTotal.text(globalurlcounter.toLocaleString());
|
||||
element.textContent = globalCounter.toLocaleString();
|
||||
elGlobalPercentage.textContent = globalPercentage+"%";
|
||||
elProgressbar_blocked.style.width = globalPercentage+'%';
|
||||
elProgressbar_non_blocked.style.width = (100-globalPercentage)+'%';
|
||||
elTotal.textContent = globalurlcounter.toLocaleString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,14 +67,14 @@ function changeStatistics()
|
||||
*/
|
||||
function setHashStatus()
|
||||
{
|
||||
let element = $('#hashStatus');
|
||||
let element = document.getElementById('hashStatus');
|
||||
|
||||
if(hashStatus)
|
||||
{
|
||||
element.text(translate(hashStatus));
|
||||
element.textContent = translate(hashStatus);
|
||||
}
|
||||
else {
|
||||
element.text(translate('hash_status_code_5'));
|
||||
element.textContent = translate('hash_status_code_5');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -86,14 +86,14 @@ function setHashStatus()
|
||||
*/
|
||||
function changeSwitchButton(id, storageID)
|
||||
{
|
||||
let element = $('#'+id);
|
||||
let element = document.getElementById(id);
|
||||
|
||||
changeVisibility(id, storageID);
|
||||
|
||||
element.on('change', function(){
|
||||
element.onchange = function(){
|
||||
browser.runtime.sendMessage({
|
||||
function: "setData",
|
||||
params: [storageID, element.is(':checked')]
|
||||
params: [storageID, element.checked]
|
||||
}).then((data) => {
|
||||
if(storageID === "globalStatus"){
|
||||
browser.runtime.sendMessage({
|
||||
@@ -108,7 +108,7 @@ function changeSwitchButton(id, storageID)
|
||||
params: []
|
||||
}).catch(handleError);
|
||||
}).catch(handleError);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,10 +121,10 @@ function changeVisibility(id, storageID)
|
||||
switch(storageID)
|
||||
{
|
||||
case "loggingStatus":
|
||||
element = $('#log_section');
|
||||
element = document.getElementById('log_section');
|
||||
break;
|
||||
case "statisticsStatus":
|
||||
element = $('#statistic_section');
|
||||
element = document.getElementById('statistic_section');
|
||||
break;
|
||||
default:
|
||||
element = "undefine";
|
||||
@@ -132,14 +132,14 @@ function changeVisibility(id, storageID)
|
||||
|
||||
if(element !== "undefine")
|
||||
{
|
||||
if($('#'+id).is(':checked'))
|
||||
if(document.getElementById(id).checked)
|
||||
{
|
||||
element.css('display', '');
|
||||
element.css('display', '');
|
||||
element.style.display = '';
|
||||
element.style.display = '';
|
||||
}
|
||||
else {
|
||||
element.css('display', 'none');
|
||||
element.css('display', 'none');
|
||||
element.style.display = 'none';
|
||||
element.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,8 +151,8 @@ function changeVisibility(id, storageID)
|
||||
*/
|
||||
function setSwitchButton(id, varname)
|
||||
{
|
||||
let element = $('#'+id);
|
||||
element.prop('checked', this[varname]);
|
||||
const element = document.getElementById(id);
|
||||
element.checked = this[varname];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +180,7 @@ function resetGlobalCounter(){
|
||||
changeStatistics();
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
(function() {
|
||||
loadData("globalCounter")
|
||||
.then(() => loadData("globalurlcounter"))
|
||||
.then(() => loadData("globalStatus"))
|
||||
@@ -191,17 +191,17 @@ $(document).ready(function(){
|
||||
.then(() => loadData("getCurrentURL", "currentURL"))
|
||||
.then(() => {
|
||||
init();
|
||||
$('#reset_counter_btn').on("click", resetGlobalCounter);
|
||||
document.getElementById('reset_counter_btn').onclick = resetGlobalCounter;
|
||||
changeSwitchButton("globalStatus", "globalStatus");
|
||||
changeSwitchButton("tabcounter", "badgedStatus");
|
||||
changeSwitchButton("logging", "loggingStatus");
|
||||
changeSwitchButton("statistics", "statisticsStatus");
|
||||
$('#loggingPage').attr('href', browser.extension.getURL('./html/log.html'));
|
||||
$('#settings').attr('href', browser.extension.getURL('./html/settings.html'));
|
||||
$('#cleaning_tools').attr('href', browser.extension.getURL('./html/cleaningTool.html'));
|
||||
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');
|
||||
setText();
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
/**
|
||||
* Set the text for the UI.
|
||||
@@ -220,7 +220,7 @@ function setText()
|
||||
injectText('configs_switch_filter','popup_html_configs_switch_filter');
|
||||
injectText('configs_head','popup_html_configs_head');
|
||||
injectText('configs_switch_statistics','configs_switch_statistics');
|
||||
$('#donate').prop('title', translate('donate_button'));
|
||||
document.getElementById('donate').title = translate('donate_button');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,8 +232,8 @@ function setText()
|
||||
*/
|
||||
function injectText(id, attribute, tooltip = "")
|
||||
{
|
||||
let object = $('#'+id);
|
||||
object.text(translate(attribute));
|
||||
const object = document.getElementById(id);
|
||||
object.textContent = translate(attribute);
|
||||
|
||||
/*
|
||||
This function will throw an error if no translation
|
||||
@@ -243,7 +243,7 @@ function injectText(id, attribute, tooltip = "")
|
||||
|
||||
if(tooltip !== "")
|
||||
{
|
||||
object.prop('title', tooltip);
|
||||
object.setAttribute('title', tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,18 +27,18 @@
|
||||
function setText()
|
||||
{
|
||||
document.title = translate('blocked_html_title');
|
||||
$('#title').html(translate('blocked_html_title'));
|
||||
$('#body').html(translate('blocked_html_body'));
|
||||
$('#page').text(translate('blocked_html_button'));
|
||||
document.getElementById('title').innerHTML = translate('blocked_html_title');
|
||||
document.getElementById('body').innerHTML = translate('blocked_html_body');
|
||||
document.getElementById('page').textContent = translate('blocked_html_button');
|
||||
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
(function() {
|
||||
setText();
|
||||
|
||||
let source = new URLSearchParams(window.location.search).get("source");
|
||||
$('#page').attr('href', decodeURIComponent(source));
|
||||
});
|
||||
const source = new URLSearchParams(window.location.search).get("source");
|
||||
document.getElementById('page').href = decodeURIComponent(source);
|
||||
})();
|
||||
|
||||
/**
|
||||
* Translate a string with the i18n API.
|
||||
|
||||
@@ -206,7 +206,7 @@ function initSettings() {
|
||||
storage.watchDogErrorCount = 0;
|
||||
|
||||
if (getBrowser() === "Firefox") {
|
||||
storage.types = ["font", "image", "imageset", "main_frame", "media", "object", "object_subrequest", "other", "script", "stylesheet", "sub_frame", "websocket", "xbl", "xml_dtd", "xmlhttprequest", "xslt"];
|
||||
storage.types = ["font", "image", "imageset", "main_frame", "media", "object", "object_subrequest", "other", "script", "stylesheet", "sub_frame", "websocket", "xml_dtd", "xmlhttprequest", "xslt"];
|
||||
storage.pingRequestTypes = ["ping", "beacon"];
|
||||
} else if (getBrowser() === "Chrome") {
|
||||
storage.types = ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"];
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
* This script is responsible for some tools.
|
||||
*/
|
||||
|
||||
// Needed by the sha256 method
|
||||
const enc = new TextEncoder();
|
||||
|
||||
/*
|
||||
* To support Waterfox.
|
||||
*/
|
||||
@@ -287,7 +290,7 @@ Object.prototype.getOrDefault = function (key, defaultValue) {
|
||||
};
|
||||
|
||||
function handleError(error) {
|
||||
console.log("[ClearURLs ERROR]:" + error);
|
||||
console.error("[ClearURLs ERROR]:" + error);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,4 +329,21 @@ function pushToLog(beforeProcessing, afterProcessing, rule) {
|
||||
*/
|
||||
function isStorageAvailable() {
|
||||
return storage.ClearURLsData.length !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calculates the SHA-256 hash as HEX string of the given message.
|
||||
* This method uses the native hashing implementations of the SubtleCrypto interface which is supported by all browsers
|
||||
* that implement the Web Cryptography API specification and is based on:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
|
||||
*
|
||||
* @param message message for which the hash should be calculated
|
||||
* @returns {Promise<string>} SHA-256 of the given message
|
||||
*/
|
||||
async function sha256(message) {
|
||||
const msgUint8 = enc.encode(message);
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
|
||||
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
@@ -21,4 +21,4 @@
|
||||
* @return version
|
||||
*/
|
||||
const version = browser.runtime.getManifest().version;
|
||||
$('#version').text(version);
|
||||
document.getElementById('version').textContent = version;
|
||||
|
||||
Reference in New Issue
Block a user