This commit is contained in:
Kevin R
2020-08-20 04:01:58 +02:00
parent 4d4a418a95
commit 4432fb46bf
13 changed files with 420 additions and 26 deletions

23
source/log/Log.ts Normal file
View File

@@ -0,0 +1,23 @@
import CircularBuffer from '../utils/CircularBuffer'
import LogEntry from './LogEntry'
export default class Log extends CircularBuffer<LogEntry> {
public constructor(capacity: number) {
super(capacity)
}
/**
* Creates a new Log object from the given string.
*
* @param enc - the encoded log
* @returns a log object
*/
// public static from(enc: string) : Log {}
/**
* Returns this log as string.
*
* @returns the log as string
*/
// public toString() : string {}
}

37
source/log/LogEntry.ts Normal file
View File

@@ -0,0 +1,37 @@
import Rule from '../rules/rule'
export default class LogEntry {
private _before: string
private _after: string
private _rule: Rule
private _timestamp: number
private _runtime: number
constructor(before: string, after: string, rule: Rule, timestamp: number = Date.now(), runtime: number) {
this._before = before
this._after = after
this._rule = rule
this._timestamp = timestamp
this._runtime = runtime
}
get before() : string {
return this._before
}
get after() : string {
return this._after
}
get rule() : Rule {
return this._rule
}
get timestamp() : number {
return this._timestamp
}
get runtime() : number {
return this._runtime
}
}

276
source/manifest.json Normal file
View File

@@ -0,0 +1,276 @@
{
"manifest_version": 2,
"name": "ClearURLs",
"version": "1.19.0",
"author": "Kevin Röbert",
"description": "__MSG_extension_description__",
"homepage_url": "https://gitlab.com/KevinRoebert/ClearUrls",
"default_locale": "en",
"icons": {
"16": "img/clearurls_16x16.png",
"19": "img/clearurls_19x19.png",
"20": "img/clearurls_20x20.png",
"24": "img/clearurls_24x24.png",
"30": "img/clearurls_30x30.png",
"32": "img/clearurls_32x32.png",
"38": "img/clearurls_38x38.png",
"48": "img/clearurls_48x48.png",
"64": "img/clearurls_64x64.png",
"96": "img/clearurls_96x96.png",
"128": "img/clearurls_128x128.png"
},
"browser_action": {
"browser_style": true,
"default_icon": {
"16": "img/clearurls_16x16.png",
"19": "img/clearurls_19x19.png",
"20": "img/clearurls_20x20.png",
"24": "img/clearurls_24x24.png",
"30": "img/clearurls_30x30.png",
"32": "img/clearurls_32x32.png",
"38": "img/clearurls_38x38.png",
"48": "img/clearurls_48x48.png",
"64": "img/clearurls_64x64.png",
"96": "img/clearurls_96x96.png",
"128": "img/clearurls_128x128.png"
},
"default_title": "ClearURLs Add-on",
"default_popup": "html/popup.html"
},
"permissions": [
"<all_urls>",
"webRequest",
"webRequestBlocking",
"storage",
"unlimitedStorage",
"contextMenus",
"clipboardWrite",
"webNavigation",
"tabs",
"downloads"
],
"background": {
"scripts": [
"background/main.js"
]
},
"content_scripts": [
{
"all_frames": true,
"matches": [
"*://*.google.com/*",
"*://*.google.ad/*",
"*://*.google.ae/*",
"*://*.google.com.af/*",
"*://*.google.com.ag/*",
"*://*.google.com.ai/*",
"*://*.google.al/*",
"*://*.google.am/*",
"*://*.google.co.ao/*",
"*://*.google.com.ar/*",
"*://*.google.as/*",
"*://*.google.at/*",
"*://*.google.com.au/*",
"*://*.google.az/*",
"*://*.google.ba/*",
"*://*.google.com.bd/*",
"*://*.google.be/*",
"*://*.google.bf/*",
"*://*.google.bg/*",
"*://*.google.com.bh/*",
"*://*.google.bi/*",
"*://*.google.bj/*",
"*://*.google.com.bn/*",
"*://*.google.com.bo/*",
"*://*.google.com.br/*",
"*://*.google.bs/*",
"*://*.google.bt/*",
"*://*.google.co.bw/*",
"*://*.google.by/*",
"*://*.google.com.bz/*",
"*://*.google.ca/*",
"*://*.google.cd/*",
"*://*.google.cf/*",
"*://*.google.cg/*",
"*://*.google.ch/*",
"*://*.google.ci/*",
"*://*.google.co.ck/*",
"*://*.google.cl/*",
"*://*.google.cm/*",
"*://*.google.cn/*",
"*://*.google.com.co/*",
"*://*.google.co.cr/*",
"*://*.google.com.cu/*",
"*://*.google.cv/*",
"*://*.google.com.cy/*",
"*://*.google.cz/*",
"*://*.google.de/*",
"*://*.google.dj/*",
"*://*.google.dk/*",
"*://*.google.dm/*",
"*://*.google.com.do/*",
"*://*.google.dz/*",
"*://*.google.com.ec/*",
"*://*.google.ee/*",
"*://*.google.com.eg/*",
"*://*.google.es/*",
"*://*.google.com.et/*",
"*://*.google.fi/*",
"*://*.google.com.fj/*",
"*://*.google.fm/*",
"*://*.google.fr/*",
"*://*.google.ga/*",
"*://*.google.ge/*",
"*://*.google.gg/*",
"*://*.google.com.gh/*",
"*://*.google.com.gi/*",
"*://*.google.gl/*",
"*://*.google.gm/*",
"*://*.google.gp/*",
"*://*.google.gr/*",
"*://*.google.com.gt/*",
"*://*.google.gy/*",
"*://*.google.com.hk/*",
"*://*.google.hn/*",
"*://*.google.hr/*",
"*://*.google.ht/*",
"*://*.google.hu/*",
"*://*.google.co.id/*",
"*://*.google.ie/*",
"*://*.google.co.il/*",
"*://*.google.im/*",
"*://*.google.co.in/*",
"*://*.google.iq/*",
"*://*.google.is/*",
"*://*.google.it/*",
"*://*.google.je/*",
"*://*.google.com.jm/*",
"*://*.google.jo/*",
"*://*.google.co.jp/*",
"*://*.google.co.ke/*",
"*://*.google.com.kh/*",
"*://*.google.ki/*",
"*://*.google.kg/*",
"*://*.google.co.kr/*",
"*://*.google.com.kw/*",
"*://*.google.kz/*",
"*://*.google.la/*",
"*://*.google.com.lb/*",
"*://*.google.li/*",
"*://*.google.lk/*",
"*://*.google.co.ls/*",
"*://*.google.lt/*",
"*://*.google.lu/*",
"*://*.google.lv/*",
"*://*.google.com.ly/*",
"*://*.google.co.ma/*",
"*://*.google.md/*",
"*://*.google.me/*",
"*://*.google.mg/*",
"*://*.google.mk/*",
"*://*.google.ml/*",
"*://*.google.com.mm/*",
"*://*.google.mn/*",
"*://*.google.ms/*",
"*://*.google.com.mt/*",
"*://*.google.mu/*",
"*://*.google.mv/*",
"*://*.google.mw/*",
"*://*.google.com.mx/*",
"*://*.google.com.my/*",
"*://*.google.co.mz/*",
"*://*.google.com.na/*",
"*://*.google.com.nf/*",
"*://*.google.com.ng/*",
"*://*.google.com.ni/*",
"*://*.google.ne/*",
"*://*.google.nl/*",
"*://*.google.no/*",
"*://*.google.com.np/*",
"*://*.google.nr/*",
"*://*.google.nu/*",
"*://*.google.co.nz/*",
"*://*.google.com.om/*",
"*://*.google.com.pa/*",
"*://*.google.com.pe/*",
"*://*.google.com.pg/*",
"*://*.google.com.ph/*",
"*://*.google.com.pk/*",
"*://*.google.pl/*",
"*://*.google.pn/*",
"*://*.google.com.pr/*",
"*://*.google.ps/*",
"*://*.google.pt/*",
"*://*.google.com.py/*",
"*://*.google.com.qa/*",
"*://*.google.ro/*",
"*://*.google.ru/*",
"*://*.google.rw/*",
"*://*.google.com.sa/*",
"*://*.google.com.sb/*",
"*://*.google.sc/*",
"*://*.google.se/*",
"*://*.google.com.sg/*",
"*://*.google.sh/*",
"*://*.google.si/*",
"*://*.google.sk/*",
"*://*.google.com.sl/*",
"*://*.google.sn/*",
"*://*.google.so/*",
"*://*.google.sm/*",
"*://*.google.sr/*",
"*://*.google.st/*",
"*://*.google.com.sv/*",
"*://*.google.td/*",
"*://*.google.tg/*",
"*://*.google.co.th/*",
"*://*.google.com.tj/*",
"*://*.google.tk/*",
"*://*.google.tl/*",
"*://*.google.tm/*",
"*://*.google.tn/*",
"*://*.google.to/*",
"*://*.google.com.tr/*",
"*://*.google.tt/*",
"*://*.google.com.tw/*",
"*://*.google.co.tz/*",
"*://*.google.com.ua/*",
"*://*.google.co.ug/*",
"*://*.google.co.uk/*",
"*://*.google.com.uy/*",
"*://*.google.co.uz/*",
"*://*.google.com.vc/*",
"*://*.google.co.ve/*",
"*://*.google.vg/*",
"*://*.google.co.vi/*",
"*://*.google.com.vn/*",
"*://*.google.vu/*",
"*://*.google.ws/*",
"*://*.google.rs/*",
"*://*.google.co.za/*",
"*://*.google.co.zm/*",
"*://*.google.co.zw/*",
"*://*.google.cat/*"
],
"js": [
"scripts/googleLinkFix.js"
],
"run_at": "document_end"
},
{
"all_frames": true,
"matches": [
"*://*.yandex.ru/*",
"*://*.yandex.com/*",
"*://*.ya.ru/*"
],
"js": [
"scripts/yandexLinkFix.js"
],
"run_at": "document_end"
}
],
"options_ui": {
"page": "html/settings.html"
}
}

11
source/rules/rule.ts Normal file
View File

@@ -0,0 +1,11 @@
export default class Rule {
private _rule: RegExp
constructor(rule: RegExp) {
this._rule = rule
}
get value() : RegExp {
return this._rule
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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/>.
*
* Based on:
* Remove Google Redirection
* https://github.com/kodango/Remove-Google-Redirection/blob/master/extension/chrome/remove-google-redirection.user.js
* Copyright (c) 2017 kodango
* MIT License: https://github.com/kodango/Remove-Google-Redirection/blob/master/LICENSE
*/
(function (window) {
"use strict";
function injectFunction() {
let ele = document.createElement('script');
let s = document.getElementsByTagName('script')[0];
ele.type = 'text/javascript';
ele.textContent = "Object.defineProperty(window, 'rwt', {" +
" value: function() { return true; }," +
" writable: false," +
" configurable: false" +
"});";
s.parentNode.insertBefore(ele, s);
}
/*
* The main entry
*/
function main()
{
injectFunction();
document.addEventListener('mouseover', function (event) {
let a = event.target, depth = 1;
while (a && a.tagName !== 'A' && depth-- > 0) {
a = a.parentNode;
}
if (a && a.tagName === 'A') {
try {
a.removeAttribute('data-cthref');
delete a.dataset.cthref;
} catch(e) {
console.log(e);
}
}
}, true);
}
main();
})(window);

View File

@@ -0,0 +1,66 @@
/*
* 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/>.
*
* Based on:
* Remove Google Redirection
* https://github.com/kodango/Remove-Google-Redirection/blob/master/extension/chrome/remove-google-redirection.user.js
* Copyright (c) 2017 kodango
* MIT License: https://github.com/kodango/Remove-Google-Redirection/blob/master/LICENSE
*/
(function (window) {
"use strict";
function injectFunction() {
let ele = document.createElement('script');
let s = document.getElementsByTagName('script')[0];
ele.type = 'text/javascript';
ele.textContent = "Object.defineProperty(window, '_borschik', {" +
" value: function() { return false; }," +
" writable: false," +
" configurable: false" +
"});";
s.parentNode.insertBefore(ele, s);
}
/*
* The main entry
*/
function main() {
injectFunction();
document.addEventListener('mouseover', function (event) {
let a = event.target, depth = 1;
while (a && a.tagName !== 'A' && depth-- > 0) {
a = a.parentNode;
}
if (a && a.tagName === 'A') {
try {
a.removeAttribute('data-counter');
delete a.dataset.cthref;
} catch (e) {
console.log(e);
}
}
}, true);
}
main();
})(window);

View File

@@ -26,9 +26,11 @@
import OptionsSync from 'webext-options-sync'
import { Utils } from '../utils/utils'
export default new OptionsSync({
/**
* Saves all options in sync storage.
*/
export const syncStorage = new OptionsSync({
defaults: {
rules: '{}',
rulesHash: '',
badgedStatus: true,
enabled: true,
@@ -36,7 +38,6 @@ export default new OptionsSync({
cleanedCount: 0,
rulesStatus: 'error',
loggingEnabled: false,
log: '',
logLimit: 100,
statisticsEnabled: true,
badgedColor: '#ffa500',
@@ -54,23 +55,24 @@ export default new OptionsSync({
pingRequestTypes: '',
},
migrations: [
(savedOptions, defaults) => {
// Secound param is normaly "defaults", but currently not used
(savedOptions, _) => {
if (Utils.getBrowser() === 'Firefox') {
if (savedOptions.requestTypes === '') {
savedOptions.requestTypes = 'font,image,imageset,main_frame,media,object,object_subrequest,other,script,stylesheet,sub_frame,websocket,xml_dtd,xmlhttprequest,xslt'
savedOptions.requestTypes = Object.values(FirefoxRequestTypes).join(',')
}
if (savedOptions.pingRequestTypes === '') {
savedOptions.pingRequestTypes = 'ping,beacon'
savedOptions.pingRequestTypes = Object.values(FirefoxPingRequestTypes).join(',')
}
} else {
}
else {
if (savedOptions.requestTypes === '') {
savedOptions.requestTypes = 'main_frame,sub_frame,stylesheet,script,image,font,object,xmlhttprequest,ping,csp_report,media,websocket,other'
savedOptions.requestTypes = Object.values(ChromeRequestTypes).join(',')
}
if (savedOptions.pingRequestTypes === '') {
savedOptions.pingRequestTypes = 'ping'
savedOptions.pingRequestTypes = Object.values(ChromePingRequestTypes).join(',')
}
}
},
@@ -79,4 +81,71 @@ export default new OptionsSync({
],
logging: true,
storageName: 'clearurlsData',
})
})
/**
* Saves rules and logs on local storage.
*/
/* export class LocalStorage {
private _rules: {}
private _log: Log
public constructor() {
this._rules = {}
this._log = new Log()
}
} */
/**
* Models the supported request types of Firefox.
*/
export enum FirefoxRequestTypes {
FONT = 'font',
IMAGE = 'image',
IMAGESET = 'imageset',
MAIN_FRAME = 'main_frame',
MEDIA = 'media',
OBJECT = 'object',
OBJECT_SUBREQUEST = 'object_subrequest',
OTHER = 'other',
SCRIPT = 'script',
STYLESHEET = 'stylesheet',
SUB_FRAME = 'sub_frame',
WEBSOCKET = 'websocket',
XML_DTD = 'xml_dtd',
XMLHTTPREQUEST = 'xmlhttprequest',
XSLT = 'xslt',
}
/**
* Models the supported ping request types of Firefox.
*/
export enum FirefoxPingRequestTypes {
PING = 'ping',
BEACON = 'beacon',
}
/**
* Models the supported request types of Chrome.
*/
export enum ChromeRequestTypes {
MAIN_FRAME = 'main_frame',
SUB_FRAME = 'sub_frame',
STYLESHEET = 'stylesheet',
SCRIPT = 'script',
IMAGE = 'image',
FONT = 'font',
OBJECT = 'object',
XMLHTTPREQUEST = 'xmlhttprequest',
CSP_REPORT = 'csp_report',
MEDIA = 'media',
WEBSOCKET = 'websocket',
OTHER = 'other',
}
/**
* Models the supported ping request types of Chrome.
*/
export enum ChromePingRequestTypes {
PING = 'ping',
}

View File

View File

@@ -0,0 +1,63 @@
export default class CircularBuffer<T> {
private buffer: T[]
public readonly capacity: number
/**
* Create a new circular buffer, that removes the oldes elements if the capacity is reached.
*
* @param capacity - the capacity of this queue
* @throws error if the capacity is <= 0
*/
public constructor(capacity: number) {
if (capacity <= 0) {
throw new Error('The capacity must be > 0')
}
this.capacity = capacity
this.buffer = []
}
/**
* Returns true if the buffer is empty.
*
* @returns true if the buffer is empty otherwise false
*/
public isEmpty() : boolean {
return this.buffer.length === 0
}
/**
* Returns true if the buffer is full.
*
* @returns true if the buffer is full otherwise false
*/
public isFull() : boolean {
return this.buffer.length === this.capacity
}
/**
* Enqueues an item.
*
* @param item - item that should be enqueued
*/
public enqueue(item: T) : void {
if (this.isFull()) {
this.buffer.shift()
}
this.buffer.push(item)
}
/**
* Returns the buffer in a fresh array.
*
* @returns the buffer
*/
public toArray() : T[] {
return [...this.buffer]
}
get size() : number {
return this.buffer.length
}
}

View File

@@ -22,6 +22,8 @@
*/
import { browser } from 'webextension-polyfill-ts'
declare const InstallTrigger: any
export class Utils {
// Needed by the sha256 method
static enc = new TextEncoder()