From c138e3387b54c8082ecee7247c093265f6406a68 Mon Sep 17 00:00:00 2001 From: Kevin R Date: Thu, 20 Aug 2020 23:42:46 +0200 Subject: [PATCH] refactor --- .../{CircularBuffer.ts => circularBuffer.ts} | 4 +- source/background/main.ts | 18 ++++++++ source/log/Log.ts | 23 ----------- source/log/log.ts | 41 +++++++++++++++++++ source/log/{LogEntry.ts => logEntry.ts} | 20 ++++++++- source/rules/rule.ts | 20 ++++++++- source/scripts/googleLinkFix.js | 38 ++++++++--------- source/scripts/yandexLinkFix.js | 40 ++++++++---------- source/storage/storage.ts | 34 +++++++-------- .../{CircularBuffer.ts => circularBuffer.ts} | 20 ++++++++- source/utils/utils.ts | 34 +++++++-------- 11 files changed, 185 insertions(+), 107 deletions(-) rename __tests__/utils/{CircularBuffer.ts => circularBuffer.ts} (94%) delete mode 100644 source/log/Log.ts create mode 100644 source/log/log.ts rename source/log/{LogEntry.ts => logEntry.ts} (51%) rename source/utils/{CircularBuffer.ts => circularBuffer.ts} (65%) diff --git a/__tests__/utils/CircularBuffer.ts b/__tests__/utils/circularBuffer.ts similarity index 94% rename from __tests__/utils/CircularBuffer.ts rename to __tests__/utils/circularBuffer.ts index 0c14bc6..39bf406 100644 --- a/__tests__/utils/CircularBuffer.ts +++ b/__tests__/utils/circularBuffer.ts @@ -1,4 +1,4 @@ -import CircularBuffer from '../../source/utils/CircularBuffer' +import CircularBuffer from '../../source/utils/circularBuffer' describe('CircularBuffer', () => { let capacity: number @@ -41,4 +41,4 @@ describe('CircularBuffer', () => { it('should throw exception on illegal argument', () => { expect(() => new CircularBuffer(0)).toThrow('The capacity must be > 0') }) -}) \ No newline at end of file +}) diff --git a/source/background/main.ts b/source/background/main.ts index ab9ba58..41efdda 100644 --- a/source/background/main.ts +++ b/source/background/main.ts @@ -1 +1,19 @@ +/* + * 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 . + */ + // import { browser } from 'webextension-polyfill-ts' diff --git a/source/log/Log.ts b/source/log/Log.ts deleted file mode 100644 index 740cc48..0000000 --- a/source/log/Log.ts +++ /dev/null @@ -1,23 +0,0 @@ -import CircularBuffer from '../utils/CircularBuffer' -import LogEntry from './LogEntry' - -export default class Log extends CircularBuffer { - 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 {} -} \ No newline at end of file diff --git a/source/log/log.ts b/source/log/log.ts new file mode 100644 index 0000000..8ebf0b0 --- /dev/null +++ b/source/log/log.ts @@ -0,0 +1,41 @@ +/* + * 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 . + */ + +import CircularBuffer from '../utils/circularBuffer' +import LogEntry from './logEntry' + +export default class Log extends CircularBuffer { + 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 {} +} diff --git a/source/log/LogEntry.ts b/source/log/logEntry.ts similarity index 51% rename from source/log/LogEntry.ts rename to source/log/logEntry.ts index 98eadd6..95c9da0 100644 --- a/source/log/LogEntry.ts +++ b/source/log/logEntry.ts @@ -1,3 +1,21 @@ +/* + * 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 . + */ + import Rule from '../rules/rule' export default class LogEntry { @@ -34,4 +52,4 @@ export default class LogEntry { get runtime() : number { return this._runtime } -} \ No newline at end of file +} diff --git a/source/rules/rule.ts b/source/rules/rule.ts index 1cdf192..d386d56 100644 --- a/source/rules/rule.ts +++ b/source/rules/rule.ts @@ -1,3 +1,21 @@ +/* + * 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 . + */ + export default class Rule { private _rule: RegExp @@ -8,4 +26,4 @@ export default class Rule { get value() : RegExp { return this._rule } -} \ No newline at end of file +} diff --git a/source/scripts/googleLinkFix.js b/source/scripts/googleLinkFix.js index 8d967e3..16e05e3 100644 --- a/source/scripts/googleLinkFix.js +++ b/source/scripts/googleLinkFix.js @@ -1,26 +1,20 @@ /* -* 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 . -* -* 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 -*/ + * 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 . + */ (function (window) { "use strict"; diff --git a/source/scripts/yandexLinkFix.js b/source/scripts/yandexLinkFix.js index 902d3e2..cf84949 100644 --- a/source/scripts/yandexLinkFix.js +++ b/source/scripts/yandexLinkFix.js @@ -1,26 +1,20 @@ /* -* 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 . -* -* 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 -*/ + * 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 . + */ (function (window) { "use strict"; @@ -63,4 +57,4 @@ } main(); -})(window); \ No newline at end of file +})(window); diff --git a/source/storage/storage.ts b/source/storage/storage.ts index e687ae6..dc3651e 100644 --- a/source/storage/storage.ts +++ b/source/storage/storage.ts @@ -1,20 +1,20 @@ /* -* 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 . -*/ + * 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 . + */ /*jshint esversion: 6 */ /* @@ -148,4 +148,4 @@ export enum ChromeRequestTypes { */ export enum ChromePingRequestTypes { PING = 'ping', -} \ No newline at end of file +} diff --git a/source/utils/CircularBuffer.ts b/source/utils/circularBuffer.ts similarity index 65% rename from source/utils/CircularBuffer.ts rename to source/utils/circularBuffer.ts index bb45dbe..f3b7f0f 100644 --- a/source/utils/CircularBuffer.ts +++ b/source/utils/circularBuffer.ts @@ -1,3 +1,21 @@ +/* + * 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 . + */ + export default class CircularBuffer { private buffer: T[] public readonly capacity: number @@ -60,4 +78,4 @@ export default class CircularBuffer { get size() : number { return this.buffer.length } -} \ No newline at end of file +} diff --git a/source/utils/utils.ts b/source/utils/utils.ts index 7f7a9c5..a86df63 100644 --- a/source/utils/utils.ts +++ b/source/utils/utils.ts @@ -1,20 +1,20 @@ /* -* 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 . -*/ + * 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 . + */ /*jshint esversion: 6 */ /* @@ -96,4 +96,4 @@ export class Utils { return hashArray.map(b => b.toString(16).padStart(2, '0')).join('') } -} \ No newline at end of file +}