From f95cec89991e89d61510941c4cca2f224f606e00 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Wed, 5 Aug 2020 07:05:57 +0200 Subject: [PATCH 01/29] #32 added mockup files + support --- manifest.json | 7 +++++++ settings/settings.html | 0 settings/settings.js | 0 3 files changed, 7 insertions(+) create mode 100644 settings/settings.html create mode 100644 settings/settings.js diff --git a/manifest.json b/manifest.json index a7777d7..a1dd607 100644 --- a/manifest.json +++ b/manifest.json @@ -5,6 +5,13 @@ "manifest_version": 2, "author": "Serraniel", "homepage_url": "https://github.com/Serraniel/EnhancedAniwatch", + "options_ui": { + "page": "settings/settings.html", + "open_in_tab": true + }, + "permissions": [ + "storage" + ], "content_scripts": [{ "matches": [ "*://aniwatch.me/*" diff --git a/settings/settings.html b/settings/settings.html new file mode 100644 index 0000000..e69de29 diff --git a/settings/settings.js b/settings/settings.js new file mode 100644 index 0000000..e69de29 From c6df27e8187be8ebf540be2e4f0f268c181d35ed Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Wed, 5 Aug 2020 07:12:04 +0200 Subject: [PATCH 02/29] #32 added basic settings for #11 --- settings/settings.html | 22 ++++++++++++++++++++++ settings/settings.js | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/settings/settings.html b/settings/settings.html index e69de29..3d3b2ec 100644 --- a/settings/settings.html +++ b/settings/settings.html @@ -0,0 +1,22 @@ + + + + Enhanced Aniwatch Settings + + + + +
+

Enhanced Aniwatch Settings

+ +
+ +
+ + +
+ + + diff --git a/settings/settings.js b/settings/settings.js index e69de29..7e10f2b 100644 --- a/settings/settings.js +++ b/settings/settings.js @@ -0,0 +1,25 @@ +// Saves settings to chrome.storage +function save_settings() { + let items = { + maxPlayerWidth: document.getElementById('maxPlayerWidth').value, + actualPlayerWidth: document.getElementById('actualPlayerWidth').value + }; + + chrome.storage.local.set(items, function() { + alert('Settings saved.'); + }); +} + +// Restores the settings using stored in chrome.storage +function restore_settings() { + chrome.storage.local.get([ + 'maxPlayerWidth', + 'actualPlayerWidth' + ], function(r) { + document.getElementById('maxPlayerWidth').value = r.maxPlayerWidth; + document.getElementById('actualPlayerWidth').value = r.actualPlayerWidth; + }); +} + +document.getElementById('save').addEventListener('click', save_settings); +document.addEventListener('DOMContentLoaded', restore_settings); From 531d2a82ed9d2e9af363710f0bf0cf2ab8440528 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Sat, 15 Aug 2020 21:36:17 +0200 Subject: [PATCH 03/29] #32 added a SettingsProvider which supports all chrome.storage.local functions --- manifest.json | 1 + settings/SettingsProvider.js | 151 +++++++++++++++++++++++++++++++++++ settings/settings.html | 1 + 3 files changed, 153 insertions(+) create mode 100644 settings/SettingsProvider.js diff --git a/manifest.json b/manifest.json index a1dd607..a206238 100644 --- a/manifest.json +++ b/manifest.json @@ -17,6 +17,7 @@ "*://aniwatch.me/*" ], "js": [ + "settings/SettingsProvider.js", "utils/colors.js", "utils/helpers.js", "utils/aniwatchCore.js" diff --git a/settings/SettingsProvider.js b/settings/SettingsProvider.js new file mode 100644 index 0000000..77a5118 --- /dev/null +++ b/settings/SettingsProvider.js @@ -0,0 +1,151 @@ +// Currently only supports local storage + +let data = { + 'usedBytes': {} +}; + +// Get all the keys + values from the storage +function getStorageData(keys) { + chrome.storage.local.get(keys, function(values) { + Object.assign(data, values); + }); +} + +// Save all the keys + values to the storage +function setStorageData(items) { + chrome.storage.local.set(items); +} + +// Get Data from data{} +// or just use data[key] or data.key to grab it +function getStorageEntry(entry) { + if (typeof entry === 'string') { + if (data.hasOwnProperty(entry)) { + console.log(entry); + console.log(data[entry]); + return data[entry]; + } + else { + console.log("Initialize Data first."); + } + } +} + +// Get bytes used by local storage +// Accepts nothing, an object or a string +function getStorageBytesInUse(keys) { + // Get all used bytes + if (typeof keys === 'undefined' || (typeof keys === 'objects' && Object.keys(keys).length === 0)){ + console.log("No keys given, grabbing total bytes used."); + chrome.storage.local.getBytesInUse(null, function(value) { + if (chrome.runtime.lastError) { + console.log("Error retrieving entry: " + chrome.runtime.lastError); + return; + } + else { + console.log(`Used storage bytes: ${value}`); + data.usedBytes.total = value; + } + }); + } + // Get bytes for the provided object + else if (typeof keys === 'object') { + if (Object.keys(keys).length === 1) { + console.log(keys); + console.log(`Key given, grabbing total bytes used by ${keys}.`); + chrome.storage.local.getBytesInUse(keys, function(value) { + if (chrome.runtime.lastError) { + console.log("Error retrieving entry: " + chrome.runtime.lastError); + return; + } + console.log(`Used storage bytes by ${keys}: ${value}`); + data.usedBytes[keys] = value; + }); + } + else if (Object.keys(keys).length > 1) { + console.log(keys); + console.log(`Multiple keys given, grabbing total bytes used by ${keys}.`); + for (var key in keys) { + let temp = keys[key]; + console.log(temp); + chrome.storage.local.getBytesInUse(temp, function(value) { + if (chrome.runtime.lastError) { + console.log("Error retrieving entry: " + chrome.runtime.lastError); + return; + } + else { + console.log(`Used storage bytes by ${temp}: ${value}`); + data.usedBytes[temp] = value; + } + }); + } + } + } + // Get bytes for the provided string + else if (typeof keys === 'string') { + console.log(keys); + console.log(`Key given, grabbing total bytes used by ${keys}.`); + chrome.storage.local.getBytesInUse(keys, function(values) { + if (chrome.runtime.lastError) { + console.log("Error retrieving entry: " + chrome.runtime.lastError); + return; + } + else { + console.log(`Used storage bytes by ${keys}: ${values}`); + data.usedBytes[keys] = values; + } + }); + + } +} + +// Remove the provided Entry from local storage +function removeStorageEntry(keys) { + // stop if undefined or empty object + if (typeof keys === 'undefined' || (typeof keys === 'objects' && Object.keys(keys).length === 0)) { + console.log("thats not how this works."); + return; + } + // handle keys if object + else if (typeof keys === 'object') { + if (Object.keys(keys).length >= 1) { + console.log(keys); + for (var key in keys) { + let temp = keys[key]; + chrome.storage.local.remove(temp, function() { + if (chrome.runtime.lastError) { + console.log("Error retrieving entry: " + chrome.runtime.lastError); + return; + } + else { + console.log("deleting"); + delete data[temp]; + } + }); + } + return; + } + } + // handle keys as string + else if (typeof keys === 'string') { + console.log("reached"); + chrome.storage.local.remove(keys, function() { + if (chrome.runtime.lastError) { + console.log("Error retrieving entry: " + chrome.runtime.lastError); + return; + } + else { + delete data[keys]; + } + }); + } +} + +// Clear the storage completely +// also clears data +function clearStorageEntries() { + chrome.storage.local.clear(); + data = {}; +} + +// missing onChanged Event diff --git a/settings/settings.html b/settings/settings.html index 3d3b2ec..c0bb0b8 100644 --- a/settings/settings.html +++ b/settings/settings.html @@ -18,5 +18,6 @@ + From b93ad5e54810c19c400b996e3d4243cdf9288305 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Sat, 15 Aug 2020 21:36:44 +0200 Subject: [PATCH 04/29] fixed a comment --- settings/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/settings.js b/settings/settings.js index 7e10f2b..9d6bef8 100644 --- a/settings/settings.js +++ b/settings/settings.js @@ -10,7 +10,7 @@ function save_settings() { }); } -// Restores the settings using stored in chrome.storage +// Restores the settings from chrome.storage function restore_settings() { chrome.storage.local.get([ 'maxPlayerWidth', From 25c41d7bed948618d73f0629abd37203270b2d83 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 2 Nov 2020 18:36:03 +0100 Subject: [PATCH 05/29] #32 Post merge fixes and moved around some files :D --- manifest.json | 38 ------------------- {settings => src/html}/settings.html | 2 - .../javascript/settings}/SettingsProvider.js | 0 .../javascript/settings}/settings.js | 0 src/manifests/chrome.manifest.json | 30 +++++++++------ src/manifests/firefox.manifest.json | 30 +++++++++------ src/manifests/manifest.template.json | 30 +++++++++------ src/manifests/opera.manifest.json | 30 +++++++++------ 8 files changed, 72 insertions(+), 88 deletions(-) delete mode 100644 manifest.json rename {settings => src/html}/settings.html (89%) rename {settings => src/javascript/settings}/SettingsProvider.js (100%) rename {settings => src/javascript/settings}/settings.js (100%) diff --git a/manifest.json b/manifest.json deleted file mode 100644 index a206238..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ - { - "name": "Enhanced Aniwatch", - "version": "0.1.0.0", - "description": "Contains several enhancments for https://aniwatch.me.", - "manifest_version": 2, - "author": "Serraniel", - "homepage_url": "https://github.com/Serraniel/EnhancedAniwatch", - "options_ui": { - "page": "settings/settings.html", - "open_in_tab": true - }, - "permissions": [ - "storage" - ], - "content_scripts": [{ - "matches": [ - "*://aniwatch.me/*" - ], - "js": [ - "settings/SettingsProvider.js", - "utils/colors.js", - "utils/helpers.js", - "utils/aniwatchCore.js" - ], - "run_at": "document_start" - }, - { - "matches": [ - "*://aniwatch.me/*" - ], - "js": [ - "enhancements/quickSearch.js", - "enhancements/animeRequests.js" - ], - "run_at": "document_end" - } - ] - } \ No newline at end of file diff --git a/settings/settings.html b/src/html/settings.html similarity index 89% rename from settings/settings.html rename to src/html/settings.html index c0bb0b8..4a8647d 100644 --- a/settings/settings.html +++ b/src/html/settings.html @@ -17,7 +17,5 @@ - - diff --git a/settings/SettingsProvider.js b/src/javascript/settings/SettingsProvider.js similarity index 100% rename from settings/SettingsProvider.js rename to src/javascript/settings/SettingsProvider.js diff --git a/settings/settings.js b/src/javascript/settings/settings.js similarity index 100% rename from settings/settings.js rename to src/javascript/settings/settings.js diff --git a/src/manifests/chrome.manifest.json b/src/manifests/chrome.manifest.json index 0f4c6ac..ed0b479 100644 --- a/src/manifests/chrome.manifest.json +++ b/src/manifests/chrome.manifest.json @@ -14,16 +14,22 @@ "48": "images/icon/icon_48.png", "96": "images/icon/icon_96.png" }, - "content_scripts": [{ - "matches": [ - "*://aniwatch.me/*" - ], - "js": [ - "javascript/app.min.js" - ], - "css": [ - "stylesheets/aniwatchplus.min.css" - ], - "run_at": "document_end" - }] + "options_ui": { + "page": "html/settings.html", + "open_in_tab": true + }, + "content_scripts": [ + { + "matches": [ + "*://aniwatch.me/*" + ], + "js": [ + "javascript/app.min.js" + ], + "css": [ + "stylesheets/aniwatchplus.min.css" + ], + "run_at": "document_end" + } + ] } \ No newline at end of file diff --git a/src/manifests/firefox.manifest.json b/src/manifests/firefox.manifest.json index 3cc2904..ca58bad 100644 --- a/src/manifests/firefox.manifest.json +++ b/src/manifests/firefox.manifest.json @@ -14,16 +14,22 @@ "48": "images/icon/icon_48.png", "96": "images/icon/icon_96.png" }, - "content_scripts": [{ - "matches": [ - "*://aniwatch.me/*" - ], - "js": [ - "javascript/app.min.js" - ], - "css": [ - "stylesheets/aniwatchplus.min.css" - ], - "run_at": "document_end" - }] + "options_ui": { + "page": "html/settings.html", + "open_in_tab": true + }, + "content_scripts": [ + { + "matches": [ + "*://aniwatch.me/*" + ], + "js": [ + "javascript/app.min.js" + ], + "css": [ + "stylesheets/aniwatchplus.min.css" + ], + "run_at": "document_end" + } + ] } \ No newline at end of file diff --git a/src/manifests/manifest.template.json b/src/manifests/manifest.template.json index f2d1e2a..e8c8b3f 100644 --- a/src/manifests/manifest.template.json +++ b/src/manifests/manifest.template.json @@ -18,16 +18,22 @@ "48": "images/icon/icon_48.png", "96": "images/icon/icon_96.png" }, - "content_scripts": [{ - "matches": [ - "*://aniwatch.me/*" - ], - "js": [ - "javascript/app.min.js" - ], - "css": [ - "stylesheets/aniwatchplus.min.css" - ], - "run_at": "document_end" - }] + "options_ui": { + "page": "html/settings.html", + "open_in_tab": true + }, + "content_scripts": [ + { + "matches": [ + "*://aniwatch.me/*" + ], + "js": [ + "javascript/app.min.js" + ], + "css": [ + "stylesheets/aniwatchplus.min.css" + ], + "run_at": "document_end" + } + ] } \ No newline at end of file diff --git a/src/manifests/opera.manifest.json b/src/manifests/opera.manifest.json index 0ad7f9e..eede200 100644 --- a/src/manifests/opera.manifest.json +++ b/src/manifests/opera.manifest.json @@ -15,16 +15,22 @@ "48": "images/icon/icon_48.png", "96": "images/icon/icon_96.png" }, - "content_scripts": [{ - "matches": [ - "*://aniwatch.me/*" - ], - "js": [ - "javascript/app.min.js" - ], - "css": [ - "stylesheets/aniwatchplus.min.css" - ], - "run_at": "document_end" - }] + "options_ui": { + "page": "html/settings.html", + "open_in_tab": true + }, + "content_scripts": [ + { + "matches": [ + "*://aniwatch.me/*" + ], + "js": [ + "javascript/app.min.js" + ], + "css": [ + "stylesheets/aniwatchplus.min.css" + ], + "run_at": "document_end" + } + ] } \ No newline at end of file From 448cc3ecb6e4979dbc0d4f9a4869f676a892d9ee Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 2 Nov 2020 18:38:51 +0100 Subject: [PATCH 06/29] #32 Added "html" paths into gulpfile --- gulpfile.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index def9898..76bb06b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -25,6 +25,7 @@ const src = { styles: 'src/stylesheets', scripts: 'src/javascript', images: 'src/images', + html: 'src/html', } // Build path @@ -34,6 +35,7 @@ const tmp = { styles: '.tmp/stylesheets', scripts: '.tmp/javascript', images: '.tmp/images', + html: '.tmp/html', } // Dist path @@ -44,18 +46,21 @@ const dist = { styles: 'dist/chrome/stylesheets', scripts: 'dist/chrome/javascript', images: 'dist/chrome/images', + html: 'dist/chrome/html', }, firefox: { root: 'dist/firefox', styles: 'dist/firefox/stylesheets', scripts: 'dist/firefox/javascript', images: 'dist/firefox/images', + html: 'dist/firefox/html', }, opera: { root: 'dist/opera', styles: 'dist/opera/stylesheets', scripts: 'dist/opera/javascript', images: 'dist/opera/images', + html: 'dist/opera/html', }, zip: 'dist/zips', } From 74f48818e4982c495796dd9082fd24db3f17b1a7 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 2 Nov 2020 18:42:50 +0100 Subject: [PATCH 07/29] #32 Added html copy task to gulpfile --- gulpfile.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 76bb06b..836a96b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -147,6 +147,16 @@ gulp.task('images', () => { .pipe(gulp.dest(tmp.images)) }) +gulp.task('html', () => { + return gulp.src(`${src.html}/**/*`) + .pipe($.plumber()) + // any steps for HTML processing? + .pipe($.size({ + showFiles: true, + })) + .pipe(gulp.dest(tmp.html)) +}) + gulp.task('manifests', () => { const templateFile = `${src.manifests}/manifest.template.json`; @@ -179,6 +189,8 @@ gulp.task('watch', (done) => { gulp.watch(`${src.images}/**/*`, gulp.series('clean:build', 'images', 'dist:copy', 'dist:zip')) + gulp.watch(`${src.html}/**/*`, gulp.series('clean:build', 'html', 'dist:copy', 'dist:zip')) + gulp.watch(`${src.manifests}/**/*.*`, gulp.series('clean:build', 'manifests', 'dist:copy', 'dist:zip')) done(); @@ -198,7 +210,7 @@ gulp.task('clean', gulp.series('clean:build', 'clean:dist')) BUILD CLEAN ALL ============================================================================ */ -gulp.task('build', gulp.series('manifests', 'images', 'scripts', 'styles')); +gulp.task('build', gulp.series('manifests', 'images', 'scripts', 'styles', 'html')); gulp.task('build:clean', gulp.series('clean:build', 'manifests', 'images', 'scripts', 'styles')); @@ -220,6 +232,10 @@ gulp.task('dist:chrome', (done) => { gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`) .pipe(gulp.dest(dist.chrome.styles)), + // copy html + gulp.src(`${tmp.html}/*.html`) + .pipe(gulp.dest(dist.chrome.html)), + gulp.src(`${tmp.manifests}/chrome*`) .pipe($.rename('manifest.json')) .pipe(gulp.dest(dist.chrome.root)) @@ -240,6 +256,10 @@ gulp.task('dist:firefox', (done) => { gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`) .pipe(gulp.dest(dist.firefox.styles)), + // copy html + gulp.src(`${tmp.html}/*.html`) + .pipe(gulp.dest(dist.firefox.html)), + gulp.src(`${tmp.manifests}/firefox*`) .pipe($.rename('manifest.json')) .pipe(gulp.dest(dist.firefox.root)) @@ -260,6 +280,10 @@ gulp.task('dist:opera', (done) => { gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`) .pipe(gulp.dest(dist.opera.styles)), + // copy html + gulp.src(`${tmp.html}/*.html`) + .pipe(gulp.dest(dist.opera.html)), + gulp.src(`${tmp.manifests}/opera*`) .pipe($.rename('manifest.json')) .pipe(gulp.dest(dist.opera.root)) From 65cb3807352f054eeffa3fc1415799f1cf311de8 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 14:43:20 +0100 Subject: [PATCH 08/29] #32 Changed build script to handle multiple JS "bundles" as preparation for settings Also requires gulp-merge and factor-bundle as new devDependencies. --- gulpfile.js | 33 ++- package-lock.json | 374 ++++++++++++++++++++++++++++ package.json | 2 + src/javascript/{index.js => app.js} | 0 src/javascript/settings.js | 11 + 5 files changed, 414 insertions(+), 6 deletions(-) rename src/javascript/{index.js => app.js} (100%) create mode 100644 src/javascript/settings.js diff --git a/gulpfile.js b/gulpfile.js index 836a96b..11c9db9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,6 +9,8 @@ const source = require('vinyl-source-stream'); const buffer = require('vinyl-buffer'); const merge = require('merge-stream'); const fs = require('fs'); +const factor = require('factor-bundle'); +const { debug } = require('console'); const $ = gulpLoadPlugins() @@ -113,14 +115,33 @@ gulp.task('styles', () => { }) gulp.task('scripts', () => { - let b = browserify({ - entries: `${src.scripts}/index.js`, - debug: isDev + const modules = [ + 'app', + 'settings', + ]; + + const inputs = []; + const streams = []; + + modules.forEach(module => { + inputs.push(`${src.scripts}/${module}.js`); + streams.push(source(`${module}.js`)); }); - return b.transform('babelify').bundle() + const b = browserify(inputs, { debug: isDev }); + + let outstream = b + .transform('babelify') + .plugin(factor, { outputs: streams }) + .bundle() + .pipe(source('common.js')) + + streams.forEach(stream => { + outstream = outstream.pipe($.merge(stream)); + }); + + return outstream .pipe($.plumber()) - .pipe(source('app.js')) .pipe(buffer()) .pipe($.if(isDev, $.sourcemaps.init({ loadMaps: true }))) .pipe($.terser({ compress: { drop_console: isProd, drop_debugger: isProd } })) @@ -129,7 +150,7 @@ gulp.task('scripts', () => { showFiles: true, })) .pipe($.if(isDev, $.sourcemaps.write())) - .pipe(gulp.dest(`${tmp.scripts}`)) + .pipe(gulp.dest(`${tmp.scripts}`)); }) gulp.task('images', () => { diff --git a/package-lock.json b/package-lock.json index 33de3a1..ea2cf3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4306,6 +4306,41 @@ "through2": "^2.0.0" } }, + "deps-topo-sort": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/deps-topo-sort/-/deps-topo-sort-0.2.1.tgz", + "integrity": "sha1-S+ivB0dpcWSciwxIT9fUqHuLASo=", + "dev": true, + "requires": { + "JSONStream": "~0.7.1", + "minimist": "0.0.5", + "through": "~2.3.4" + }, + "dependencies": { + "JSONStream": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-0.7.4.tgz", + "integrity": "sha1-c0KQ5BUR7qfCz+FR+/mlY6l7l4Y=", + "dev": true, + "requires": { + "jsonparse": "0.0.5", + "through": ">=2.2.7 <3" + } + }, + "jsonparse": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz", + "integrity": "sha1-MwVCrT8KZUZlt3jz6y2an6UHrGQ=", + "dev": true + }, + "minimist": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz", + "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=", + "dev": true + } + } + }, "des.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz", @@ -5066,6 +5101,228 @@ "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", "dev": true }, + "factor-bundle": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/factor-bundle/-/factor-bundle-2.5.0.tgz", + "integrity": "sha1-jqiVfaOddYYoPMPuNTzZkRpF53k=", + "dev": true, + "requires": { + "JSONStream": "~0.8.4", + "browser-pack": "^5.0.1", + "defined": "0.0.0", + "deps-topo-sort": "~0.2.1", + "inherits": "^2.0.1", + "isarray": "0.0.1", + "labeled-stream-splicer": "^1.0.0", + "minimist": "~0.2.0", + "nub": "0.0.0", + "outpipe": "^1.1.0", + "reversepoint": "~0.2.0", + "stream-combiner": "~0.2.1", + "through2": "^0.5.1", + "xtend": "^4.0.0" + }, + "dependencies": { + "JSONStream": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-0.8.4.tgz", + "integrity": "sha1-kWV9/m/4V0gwZhMrRhi2Lo9Ih70=", + "dev": true, + "requires": { + "jsonparse": "0.0.5", + "through": ">=2.2.7 <3" + }, + "dependencies": { + "jsonparse": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz", + "integrity": "sha1-MwVCrT8KZUZlt3jz6y2an6UHrGQ=", + "dev": true + } + } + }, + "browser-pack": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/browser-pack/-/browser-pack-5.0.1.tgz", + "integrity": "sha1-QZdxmyDG4KqglFHFER5T77b7wY0=", + "dev": true, + "requires": { + "JSONStream": "^1.0.3", + "combine-source-map": "~0.6.1", + "defined": "^1.0.0", + "through2": "^1.0.0", + "umd": "^3.0.0" + }, + "dependencies": { + "JSONStream": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", + "integrity": "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==", + "dev": true, + "requires": { + "jsonparse": "^1.2.0", + "through": ">=2.2.7 <3" + } + }, + "defined": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz", + "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", + "dev": true + }, + "through2": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/through2/-/through2-1.1.1.tgz", + "integrity": "sha1-CEfLxESfNAVXTb3M2buEG4OsNUU=", + "dev": true, + "requires": { + "readable-stream": ">=1.1.13-1 <1.2.0-0", + "xtend": ">=4.0.0 <4.1.0-0" + } + } + } + }, + "combine-source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/combine-source-map/-/combine-source-map-0.6.1.tgz", + "integrity": "sha1-m0oJwxYDPXaODxHgKfonMOB5rZY=", + "dev": true, + "requires": { + "convert-source-map": "~1.1.0", + "inline-source-map": "~0.5.0", + "lodash.memoize": "~3.0.3", + "source-map": "~0.4.2" + } + }, + "convert-source-map": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.1.3.tgz", + "integrity": "sha1-SCnId+n+SbMWHzvzZziI4gRpmGA=", + "dev": true + }, + "defined": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/defined/-/defined-0.0.0.tgz", + "integrity": "sha1-817qfXBekzuvE7LwOz+D2SFAOz4=", + "dev": true + }, + "inline-source-map": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/inline-source-map/-/inline-source-map-0.5.0.tgz", + "integrity": "sha1-Skxd2OT7Xps82mDIIt+tyu5m4K8=", + "dev": true, + "requires": { + "source-map": "~0.4.0" + } + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "labeled-stream-splicer": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/labeled-stream-splicer/-/labeled-stream-splicer-1.0.2.tgz", + "integrity": "sha1-RhUzFTd4SYHo/SZOHzpDTE4N3WU=", + "dev": true, + "requires": { + "inherits": "^2.0.1", + "isarray": "~0.0.1", + "stream-splicer": "^1.1.0" + } + }, + "minimist": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.2.1.tgz", + "integrity": "sha512-GY8fANSrTMfBVfInqJAY41QkOM+upUTytK1jZ0c8+3HdHrJxBJ3rF5i9moClXTE8uUSnUo8cAsCoxDXvSY4DHg==", + "dev": true + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "dev": true, + "requires": { + "amdefine": ">=0.0.4" + } + }, + "stream-splicer": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/stream-splicer/-/stream-splicer-1.3.2.tgz", + "integrity": "sha1-PARBvhW5v04iYnXm3IOWR0VUZmE=", + "dev": true, + "requires": { + "indexof": "0.0.1", + "inherits": "^2.0.1", + "isarray": "~0.0.1", + "readable-stream": "^1.1.13-1", + "readable-wrap": "^1.0.0", + "through2": "^1.0.0" + }, + "dependencies": { + "through2": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/through2/-/through2-1.1.1.tgz", + "integrity": "sha1-CEfLxESfNAVXTb3M2buEG4OsNUU=", + "dev": true, + "requires": { + "readable-stream": ">=1.1.13-1 <1.2.0-0", + "xtend": ">=4.0.0 <4.1.0-0" + } + } + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, + "through2": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/through2/-/through2-0.5.1.tgz", + "integrity": "sha1-390BLrnHAOIyP9M084rGIqs3Lac=", + "dev": true, + "requires": { + "readable-stream": "~1.0.17", + "xtend": "~3.0.0" + }, + "dependencies": { + "readable-stream": { + "version": "1.0.34", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "xtend": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-3.0.0.tgz", + "integrity": "sha1-XM50B7r2Qsunvs2laBEcST9ZZlo=", + "dev": true + } + } + } + } + }, "fancy-log": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-1.3.3.tgz", @@ -6074,6 +6331,51 @@ "minimatch": "^3.0.3" } }, + "gulp-merge": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/gulp-merge/-/gulp-merge-0.1.1.tgz", + "integrity": "sha1-pGLuARd6jqfEYPDqia1ULsdSujc=", + "dev": true, + "requires": { + "through2": "~1.1.1" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, + "through2": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/through2/-/through2-1.1.1.tgz", + "integrity": "sha1-CEfLxESfNAVXTb3M2buEG4OsNUU=", + "dev": true, + "requires": { + "readable-stream": ">=1.1.13-1 <1.2.0-0", + "xtend": ">=4.0.0 <4.1.0-0" + } + } + } + }, "gulp-plumber": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/gulp-plumber/-/gulp-plumber-1.2.1.tgz", @@ -6855,6 +7157,12 @@ "integrity": "sha1-8w9xbI4r00bHtn0985FVZqfAVgc=", "dev": true }, + "indexof": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", + "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=", + "dev": true + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -8369,6 +8677,12 @@ "boolbase": "~1.0.0" } }, + "nub": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/nub/-/nub-0.0.0.tgz", + "integrity": "sha1-s2m9Mr3eZq9ZYFw7BSC8IZ3MwE8=", + "dev": true + }, "num2fraction": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz", @@ -8607,6 +8921,15 @@ "os-tmpdir": "^1.0.0" } }, + "outpipe": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/outpipe/-/outpipe-1.1.1.tgz", + "integrity": "sha1-UM+GFjZeh+Ax4ppeyTOaPaRyX6I=", + "dev": true, + "requires": { + "shell-quote": "^1.4.2" + } + }, "p-cancelable": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.3.0.tgz", @@ -10410,6 +10733,41 @@ } } }, + "readable-wrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/readable-wrap/-/readable-wrap-1.0.0.tgz", + "integrity": "sha1-O1ohHGMeEjA6VJkcgGwX564ga/8=", + "dev": true, + "requires": { + "readable-stream": "^1.1.13-1" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + } + } + }, "readdirp": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", @@ -10819,6 +11177,12 @@ "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", "dev": true }, + "reversepoint": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/reversepoint/-/reversepoint-0.2.1.tgz", + "integrity": "sha1-0qw/9NZlzw/3Ipa3p47nI39lk/U=", + "dev": true + }, "rgb-regex": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/rgb-regex/-/rgb-regex-1.0.1.tgz", @@ -11546,6 +11910,16 @@ } } }, + "stream-combiner": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.2.2.tgz", + "integrity": "sha1-rsjLrBd7Vrb0+kec7YwZEs7lKFg=", + "dev": true, + "requires": { + "duplexer": "~0.1.1", + "through": "~2.3.4" + } + }, "stream-combiner2": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/stream-combiner2/-/stream-combiner2-1.1.1.tgz", diff --git a/package.json b/package.json index 4d56bdc..93bccc3 100644 --- a/package.json +++ b/package.json @@ -48,12 +48,14 @@ "cross-env": "^7.0.2", "cssnano": "^4.1.10", "del": "^6.0.0", + "factor-bundle": "^2.5.0", "gulp": "^4.0.2", "gulp-autoprefixer": "^7.0.1", "gulp-babel": "^8.0.0", "gulp-if": "^3.0.0", "gulp-imagemin": "^7.1.0", "gulp-load-plugins": "^2.0.5", + "gulp-merge": "^0.1.1", "gulp-plumber": "^1.2.1", "gulp-postcss": "^9.0.0", "gulp-rename": "^2.0.0", diff --git a/src/javascript/index.js b/src/javascript/app.js similarity index 100% rename from src/javascript/index.js rename to src/javascript/app.js diff --git a/src/javascript/settings.js b/src/javascript/settings.js new file mode 100644 index 0000000..f046a11 --- /dev/null +++ b/src/javascript/settings.js @@ -0,0 +1,11 @@ +import { onReady } from "./utils/helpers"; + +onReady(() => { + +}); + +function saveOptions() { + +} + +document.getElementById('save').addEventListener('click', saveOptions) \ No newline at end of file From 147b2d8dd12fddc347f4dbd32e072eaf2d8ad299 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 14:43:51 +0100 Subject: [PATCH 09/29] #32 Altered JS Config for manifest files --- src/manifests/chrome.manifest.json | 1 + src/manifests/firefox.manifest.json | 1 + src/manifests/manifest.template.json | 1 + src/manifests/opera.manifest.json | 1 + 4 files changed, 4 insertions(+) diff --git a/src/manifests/chrome.manifest.json b/src/manifests/chrome.manifest.json index ed0b479..82ae094 100644 --- a/src/manifests/chrome.manifest.json +++ b/src/manifests/chrome.manifest.json @@ -24,6 +24,7 @@ "*://aniwatch.me/*" ], "js": [ + "javascript/common.min.js", "javascript/app.min.js" ], "css": [ diff --git a/src/manifests/firefox.manifest.json b/src/manifests/firefox.manifest.json index ca58bad..ebf1125 100644 --- a/src/manifests/firefox.manifest.json +++ b/src/manifests/firefox.manifest.json @@ -24,6 +24,7 @@ "*://aniwatch.me/*" ], "js": [ + "javascript/common.min.js", "javascript/app.min.js" ], "css": [ diff --git a/src/manifests/manifest.template.json b/src/manifests/manifest.template.json index e8c8b3f..da3f8de 100644 --- a/src/manifests/manifest.template.json +++ b/src/manifests/manifest.template.json @@ -28,6 +28,7 @@ "*://aniwatch.me/*" ], "js": [ + "javascript/common.min.js", "javascript/app.min.js" ], "css": [ diff --git a/src/manifests/opera.manifest.json b/src/manifests/opera.manifest.json index eede200..f1269b9 100644 --- a/src/manifests/opera.manifest.json +++ b/src/manifests/opera.manifest.json @@ -25,6 +25,7 @@ "*://aniwatch.me/*" ], "js": [ + "javascript/common.min.js", "javascript/app.min.js" ], "css": [ From 1dff60dc3b50607685f2cf60ce576838836fef43 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 16:20:50 +0100 Subject: [PATCH 10/29] #32 Preparing storage provider --- src/javascript/settings/storageProvider.js | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/javascript/settings/storageProvider.js diff --git a/src/javascript/settings/storageProvider.js b/src/javascript/settings/storageProvider.js new file mode 100644 index 0000000..ade62c1 --- /dev/null +++ b/src/javascript/settings/storageProvider.js @@ -0,0 +1,53 @@ +const { assigned } = require("../utils/helpers") + +class StorageProviderChromium { + + storeData(key, value, callback) { + } + + getData(key, defaultValue, callback) { + } + + getStorage() { + if (assigned(chrome.storage.sync)) { + return chrome.storage.sync; + } + + return chrome.storage.local; + } +} + + +class StorageProviderFirefox { + + storeData(key, value, callback) { + } + + getData(key, defaultValue, callback) { + } + + getStorage() { + } +} + +let __storageProvieder = undefined; + +function createStorageProvider() { + // chrome based browser + if (assigned(chrome?.app)) { + __storageProvieder = new StorageProviderChromium(); + } + // firefox + else { + __storageProvieder = new StorageProviderFirefox(); + } + +} + +export function globalStorageProvider() { + if (!assigned(__storageProvieder)) { + createStorageProvider(); + } + + return __storageProvieder; +} \ No newline at end of file From 20eca07408d16b48f1971647d32c7c53a39e2bfa Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 16:21:09 +0100 Subject: [PATCH 11/29] #32 Added storage permission to manifest files --- src/manifests/chrome.manifest.json | 1 + src/manifests/firefox.manifest.json | 1 + src/manifests/manifest.template.json | 1 + src/manifests/opera.manifest.json | 1 + 4 files changed, 4 insertions(+) diff --git a/src/manifests/chrome.manifest.json b/src/manifests/chrome.manifest.json index 82ae094..0d0b03b 100644 --- a/src/manifests/chrome.manifest.json +++ b/src/manifests/chrome.manifest.json @@ -5,6 +5,7 @@ "version_name": "$semanticVersion", "description": "$description", "permissions": [ + "storage", "*://aniwatch.me/*" ], "manifest_version": 2, diff --git a/src/manifests/firefox.manifest.json b/src/manifests/firefox.manifest.json index ebf1125..efd0708 100644 --- a/src/manifests/firefox.manifest.json +++ b/src/manifests/firefox.manifest.json @@ -4,6 +4,7 @@ "version": "$version", "description": "$description", "permissions": [ + "storage", "*://aniwatch.me/*" ], "manifest_version": 2, diff --git a/src/manifests/manifest.template.json b/src/manifests/manifest.template.json index da3f8de..61a13eb 100644 --- a/src/manifests/manifest.template.json +++ b/src/manifests/manifest.template.json @@ -5,6 +5,7 @@ "version_name": "0.3.0 Beta", "description": "Aniwatch Plus is an unofficial extension which provides several UI improvments for https://aniwatch.me.", "permissions": [ + "storage", "*://aniwatch.me/*" ], "manifest_version": 2, diff --git a/src/manifests/opera.manifest.json b/src/manifests/opera.manifest.json index f1269b9..dabadbf 100644 --- a/src/manifests/opera.manifest.json +++ b/src/manifests/opera.manifest.json @@ -5,6 +5,7 @@ "version_name": "$semanticVersion", "description": "$description", "permissions": [ + "storage", "*://aniwatch.me/*" ], "manifest_version": 2, From af5656f1ffeb51256ec8928d94cd82cbdff6a15a Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 16:35:02 +0100 Subject: [PATCH 12/29] #32 Implemented storage provider for chromium based browsers --- src/javascript/settings/storageProvider.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/javascript/settings/storageProvider.js b/src/javascript/settings/storageProvider.js index ade62c1..4ce2686 100644 --- a/src/javascript/settings/storageProvider.js +++ b/src/javascript/settings/storageProvider.js @@ -2,10 +2,22 @@ const { assigned } = require("../utils/helpers") class StorageProviderChromium { - storeData(key, value, callback) { + setData(key, value) { + let obj = {}; + obj[key] = value; + + this.getStorage().set(obj); } getData(key, defaultValue, callback) { + this.getStorage().get(key, items => { + if (assigned(items)) { + callback(items[key]); + } + else { + callback(defaultValue); + } + }) } getStorage() { @@ -20,7 +32,7 @@ class StorageProviderChromium { class StorageProviderFirefox { - storeData(key, value, callback) { + setData(key, value, callback) { } getData(key, defaultValue, callback) { @@ -44,7 +56,7 @@ function createStorageProvider() { } -export function globalStorageProvider() { +export function getGlobalStorageProvider() { if (!assigned(__storageProvieder)) { createStorageProvider(); } From 88a97af8f47e369de7541862544308beb23864ab Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 16:47:31 +0100 Subject: [PATCH 13/29] #32 Probably working script for a settings page? --- src/javascript/settings.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/javascript/settings.js b/src/javascript/settings.js index f046a11..9f2e1b1 100644 --- a/src/javascript/settings.js +++ b/src/javascript/settings.js @@ -1,11 +1,28 @@ +import { getGlobalStorageProvider } from "./settings/storageProvider"; import { onReady } from "./utils/helpers"; -onReady(() => { - -}); - -function saveOptions() { +const OPTION_SELECTOR = '.extension-option' +function storeOptions() { + document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => { + getGlobalStorageProvider().setData(optionElement.id, optionElement.check); + }); } -document.getElementById('save').addEventListener('click', saveOptions) \ No newline at end of file +function restoreOptions() { + document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => { + let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false; + + getGlobalStorageProvider().getData(optionElement.id, defaultValue, value => { + optionElement.checked = value; + }); + }); +} + +onReady(() => { + // register Store Button + document.getElementById('saveBtn').addEventListener('click', storeOptions); + + // try restore options + restoreOptions(); +}); \ No newline at end of file From f7cbaaac1e2a895ef5726e83e3323eb8c2057a36 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 16:54:35 +0100 Subject: [PATCH 14/29] #32 Small fix regarding default value of getData in chromium storage provider --- src/javascript/settings/storageProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/settings/storageProvider.js b/src/javascript/settings/storageProvider.js index 4ce2686..06d621a 100644 --- a/src/javascript/settings/storageProvider.js +++ b/src/javascript/settings/storageProvider.js @@ -11,7 +11,7 @@ class StorageProviderChromium { getData(key, defaultValue, callback) { this.getStorage().get(key, items => { - if (assigned(items)) { + if (assigned(items) && assigned(items[key])) { callback(items[key]); } else { From e8d607fd00ec78295f95491d9b7d1d1c2d6fd1fd Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 16:56:24 +0100 Subject: [PATCH 15/29] #32 Reworked settings page as dummy Only two dummy checkboxes to approve the concept --- src/html/settings.html | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/html/settings.html b/src/html/settings.html index 4a8647d..f273bd9 100644 --- a/src/html/settings.html +++ b/src/html/settings.html @@ -1,21 +1,27 @@ + - Enhanced Aniwatch Settings - - + Aniwatch Plus Settings + +
-

Enhanced Aniwatch Settings

- -
- -
- +

Aniwatch Plus Settings

-
+ +
+ + +
+ + + + + + + - + + \ No newline at end of file From f5c5af92ca735a47510a9d7e92c286f4a3593062 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:02:24 +0100 Subject: [PATCH 16/29] #32 Added reset Button to options page and fixed settings script --- src/html/settings.html | 3 ++- src/javascript/settings.js | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/html/settings.html b/src/html/settings.html index f273bd9..6157160 100644 --- a/src/html/settings.html +++ b/src/html/settings.html @@ -16,7 +16,8 @@
- + + diff --git a/src/javascript/settings.js b/src/javascript/settings.js index 9f2e1b1..a559277 100644 --- a/src/javascript/settings.js +++ b/src/javascript/settings.js @@ -1,11 +1,11 @@ import { getGlobalStorageProvider } from "./settings/storageProvider"; import { onReady } from "./utils/helpers"; -const OPTION_SELECTOR = '.extension-option' +const OPTION_SELECTOR = 'input[type="checkbox"'; function storeOptions() { document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => { - getGlobalStorageProvider().setData(optionElement.id, optionElement.check); + getGlobalStorageProvider().setData(optionElement.id, optionElement.checked); }); } @@ -19,9 +19,26 @@ function restoreOptions() { }); } +function resetOptions() { + document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => { + let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false; + + optionElement.checked = defaultValue; + }); +} + onReady(() => { // register Store Button - document.getElementById('saveBtn').addEventListener('click', storeOptions); + document.getElementById('btnSave').addEventListener('click', event => { + event.preventDefault(); + storeOptions(); + }); + + document.getElementById('btnReset').addEventListener('click', event => { + event.preventDefault(); + resetOptions(); + storeOptions(); + }) // try restore options restoreOptions(); From b4a18cdc4d7d5c1846159a43249d70a7fd869576 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:18:18 +0100 Subject: [PATCH 17/29] #32 Finalized settings page --- src/html/settings.html | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/html/settings.html b/src/html/settings.html index 6157160..8422a61 100644 --- a/src/html/settings.html +++ b/src/html/settings.html @@ -8,17 +8,45 @@
-

Aniwatch Plus Settings

+

Aniwatch Plus Settings

- -
+

General Settings

+
+

Website

+ +
- -
+ +
+ +
+ + +
+ +

Anime

+ +
+ +

Requests page

+ +
+

Player Settings

+
+

General

+ +
+ +

Watch2gether

+ +
+ +

- +
+ Please reload aniwatch website after you changed the settings.
From 2c45c6ba88923776c6bb549520b87c99df38a7a7 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:23:12 +0100 Subject: [PATCH 18/29] #32 Moved around some of the files and cleaned old and deprecated files from first draft --- .../storageProvider.js | 0 src/javascript/settings.js | 2 +- src/javascript/settings/SettingsProvider.js | 151 ------------------ src/javascript/settings/settings.js | 25 --- 4 files changed, 1 insertion(+), 177 deletions(-) rename src/javascript/{settings => browserApi}/storageProvider.js (100%) delete mode 100644 src/javascript/settings/SettingsProvider.js delete mode 100644 src/javascript/settings/settings.js diff --git a/src/javascript/settings/storageProvider.js b/src/javascript/browserApi/storageProvider.js similarity index 100% rename from src/javascript/settings/storageProvider.js rename to src/javascript/browserApi/storageProvider.js diff --git a/src/javascript/settings.js b/src/javascript/settings.js index a559277..8441fa2 100644 --- a/src/javascript/settings.js +++ b/src/javascript/settings.js @@ -1,4 +1,4 @@ -import { getGlobalStorageProvider } from "./settings/storageProvider"; +import { getGlobalStorageProvider } from "./browserApi/storageProvider"; import { onReady } from "./utils/helpers"; const OPTION_SELECTOR = 'input[type="checkbox"'; diff --git a/src/javascript/settings/SettingsProvider.js b/src/javascript/settings/SettingsProvider.js deleted file mode 100644 index 77a5118..0000000 --- a/src/javascript/settings/SettingsProvider.js +++ /dev/null @@ -1,151 +0,0 @@ -// Currently only supports local storage - -let data = { - 'usedBytes': {} -}; - -// Get all the keys + values from the storage -function getStorageData(keys) { - chrome.storage.local.get(keys, function(values) { - Object.assign(data, values); - }); -} - -// Save all the keys + values to the storage -function setStorageData(items) { - chrome.storage.local.set(items); -} - -// Get Data from data{} -// or just use data[key] or data.key to grab it -function getStorageEntry(entry) { - if (typeof entry === 'string') { - if (data.hasOwnProperty(entry)) { - console.log(entry); - console.log(data[entry]); - return data[entry]; - } - else { - console.log("Initialize Data first."); - } - } -} - -// Get bytes used by local storage -// Accepts nothing, an object or a string -function getStorageBytesInUse(keys) { - // Get all used bytes - if (typeof keys === 'undefined' || (typeof keys === 'objects' && Object.keys(keys).length === 0)){ - console.log("No keys given, grabbing total bytes used."); - chrome.storage.local.getBytesInUse(null, function(value) { - if (chrome.runtime.lastError) { - console.log("Error retrieving entry: " + chrome.runtime.lastError); - return; - } - else { - console.log(`Used storage bytes: ${value}`); - data.usedBytes.total = value; - } - }); - } - // Get bytes for the provided object - else if (typeof keys === 'object') { - if (Object.keys(keys).length === 1) { - console.log(keys); - console.log(`Key given, grabbing total bytes used by ${keys}.`); - chrome.storage.local.getBytesInUse(keys, function(value) { - if (chrome.runtime.lastError) { - console.log("Error retrieving entry: " + chrome.runtime.lastError); - return; - } - console.log(`Used storage bytes by ${keys}: ${value}`); - data.usedBytes[keys] = value; - }); - } - else if (Object.keys(keys).length > 1) { - console.log(keys); - console.log(`Multiple keys given, grabbing total bytes used by ${keys}.`); - for (var key in keys) { - let temp = keys[key]; - console.log(temp); - chrome.storage.local.getBytesInUse(temp, function(value) { - if (chrome.runtime.lastError) { - console.log("Error retrieving entry: " + chrome.runtime.lastError); - return; - } - else { - console.log(`Used storage bytes by ${temp}: ${value}`); - data.usedBytes[temp] = value; - } - }); - } - } - } - // Get bytes for the provided string - else if (typeof keys === 'string') { - console.log(keys); - console.log(`Key given, grabbing total bytes used by ${keys}.`); - chrome.storage.local.getBytesInUse(keys, function(values) { - if (chrome.runtime.lastError) { - console.log("Error retrieving entry: " + chrome.runtime.lastError); - return; - } - else { - console.log(`Used storage bytes by ${keys}: ${values}`); - data.usedBytes[keys] = values; - } - }); - - } -} - -// Remove the provided Entry from local storage -function removeStorageEntry(keys) { - // stop if undefined or empty object - if (typeof keys === 'undefined' || (typeof keys === 'objects' && Object.keys(keys).length === 0)) { - console.log("thats not how this works."); - return; - } - // handle keys if object - else if (typeof keys === 'object') { - if (Object.keys(keys).length >= 1) { - console.log(keys); - for (var key in keys) { - let temp = keys[key]; - chrome.storage.local.remove(temp, function() { - if (chrome.runtime.lastError) { - console.log("Error retrieving entry: " + chrome.runtime.lastError); - return; - } - else { - console.log("deleting"); - delete data[temp]; - } - }); - } - return; - } - } - // handle keys as string - else if (typeof keys === 'string') { - console.log("reached"); - chrome.storage.local.remove(keys, function() { - if (chrome.runtime.lastError) { - console.log("Error retrieving entry: " + chrome.runtime.lastError); - return; - } - else { - delete data[keys]; - } - }); - } -} - -// Clear the storage completely -// also clears data -function clearStorageEntries() { - chrome.storage.local.clear(); - data = {}; -} - -// missing onChanged Event diff --git a/src/javascript/settings/settings.js b/src/javascript/settings/settings.js deleted file mode 100644 index 9d6bef8..0000000 --- a/src/javascript/settings/settings.js +++ /dev/null @@ -1,25 +0,0 @@ -// Saves settings to chrome.storage -function save_settings() { - let items = { - maxPlayerWidth: document.getElementById('maxPlayerWidth').value, - actualPlayerWidth: document.getElementById('actualPlayerWidth').value - }; - - chrome.storage.local.set(items, function() { - alert('Settings saved.'); - }); -} - -// Restores the settings from chrome.storage -function restore_settings() { - chrome.storage.local.get([ - 'maxPlayerWidth', - 'actualPlayerWidth' - ], function(r) { - document.getElementById('maxPlayerWidth').value = r.maxPlayerWidth; - document.getElementById('actualPlayerWidth').value = r.actualPlayerWidth; - }); -} - -document.getElementById('save').addEventListener('click', save_settings); -document.addEventListener('DOMContentLoaded', restore_settings); From 0c2621f3a6b37769e679cdc23b217ae8863fcce7 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:23:29 +0100 Subject: [PATCH 19/29] #32 Added configuration class --- src/javascript/configuration/configuration.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/javascript/configuration/configuration.js diff --git a/src/javascript/configuration/configuration.js b/src/javascript/configuration/configuration.js new file mode 100644 index 0000000..7048301 --- /dev/null +++ b/src/javascript/configuration/configuration.js @@ -0,0 +1,39 @@ +import { assigned } from "../utils/helpers"; + +class Configuration { + constructor() { + // website + this.websiteDisplayQuickSearch = true; + this.websiteShowNotificationsCountInTab = true; + this.websiteHideUnusedTabs = true; + this.websiteOptimizeListAppearance = true; + + // anime + this.animeLanguageDisplay = true; + + // requests + this.requestBeautifyPage = true; + + // player + this.playerAutoplayAfterScreenshot = true; + + // w2g + this.w2gDisplayCharacterCounter = true; + + this.reloadConfiguration(); + } + + reloadConfiguration() { + + } +} + +let __globalConfig = undefined; + +export function getGlobalConfiguration() { + if (!assigned(__globalConfig)) { + __globalConfig = new Configuration(); + } + + return __globalConfig; +} \ No newline at end of file From f1d96ebcea523fff861a51ee35aa6a9cd3d96e64 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:32:18 +0100 Subject: [PATCH 20/29] #32 Added reload method in the configuration class --- src/javascript/configuration/configuration.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/javascript/configuration/configuration.js b/src/javascript/configuration/configuration.js index 7048301..1a02c28 100644 --- a/src/javascript/configuration/configuration.js +++ b/src/javascript/configuration/configuration.js @@ -1,3 +1,4 @@ +import { getGlobalStorageProvider } from "../browserApi/storageProvider"; import { assigned } from "../utils/helpers"; class Configuration { @@ -24,7 +25,25 @@ class Configuration { } reloadConfiguration() { + // website + getGlobalStorageProvider().getData('websiteDisplayQuickSearch', this.websiteDisplayQuickSearch, value => this.websiteDisplayQuickSearch = value); + getGlobalStorageProvider().getData('websiteShowNotificationsCountInTab', this.websiteShowNotificationsCountInTab, value => this.websiteShowNotificationsCountInTab = value); + getGlobalStorageProvider().getData('websiteHideUnusedTabs', this.websiteHideUnusedTabs, value => this.websiteHideUnusedTabs = value); + getGlobalStorageProvider().getData('websiteOptimizeListAppearance', this.websiteOptimizeListAppearance, value => this.websiteOptimizeListAppearance = value); + // anime + getGlobalStorageProvider().getData('animeLanguageDisplay', this.animeLanguageDisplay, value => this.animeLanguageDisplay = value); + + // requests + getGlobalStorageProvider().getData('requestBeautifyPage', this.requestBeautifyPage, value => this.requestBeautifyPage = value); + + // player + getGlobalStorageProvider().getData('playerAutoplayAfterScreenshot', this.playerAutoplayAfterScreenshot, value => this.playerAutoplayAfterScreenshot = value); + + // w2g + getGlobalStorageProvider().getData('w2gDisplayCharacterCounter', this.w2gDisplayCharacterCounter, value => this.w2gDisplayCharacterCounter = value); + + console.log(this); } } From 1bbca434447ced00b4f5a3e0c2694ff9951fa83d Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:48:27 +0100 Subject: [PATCH 21/29] #32 added options check for all JS enhancements --- src/javascript/enhancements/anilyr.js | 15 +++++++------ src/javascript/enhancements/animeRequests.js | 21 +++++++++++-------- .../enhancements/languageDisplay.js | 15 +++++++------ src/javascript/enhancements/notifications.js | 15 +++++++------ src/javascript/enhancements/quickSearch.js | 15 +++++++++---- .../enhancements/watch2getherChat.js | 10 +++++---- 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/javascript/enhancements/anilyr.js b/src/javascript/enhancements/anilyr.js index f80ebd8..129dbfe 100644 --- a/src/javascript/enhancements/anilyr.js +++ b/src/javascript/enhancements/anilyr.js @@ -1,3 +1,4 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; @@ -5,11 +6,13 @@ const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip'; const PLAYER_ID = 'player'; export function init() { - core.registerScript(node => { - if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { - observeScreenshotTooltip(node); - } - }, "^/anime/[0-9]*/[0-9]*$"); + if (getGlobalConfiguration().playerAutoplayAfterScreenshot) { + core.registerScript(node => { + if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { + observeScreenshotTooltip(node); + } + }, "^/anime/[0-9]*/[0-9]*$"); + } } function observeScreenshotTooltip(tooltip) { @@ -18,7 +21,7 @@ function observeScreenshotTooltip(tooltip) { // Switched to invisible if (!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') { let player = findPlayer(); - if(typeof player !== 'undefined'){ + if (typeof player !== 'undefined') { resumePlayer(player); } } diff --git a/src/javascript/enhancements/animeRequests.js b/src/javascript/enhancements/animeRequests.js index 171f191..b73ad66 100644 --- a/src/javascript/enhancements/animeRequests.js +++ b/src/javascript/enhancements/animeRequests.js @@ -1,16 +1,19 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as color from '../utils/colors'; import * as helper from '../utils/helpers'; export function init() { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - changeFollowedStarColor(node); - changeBorderColorOwnRequests(node); - removeUnknownUsers(node); - } - }, "/requests"); + if (getGlobalConfiguration().requestBeautifyPage) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + changeFollowedStarColor(node); + changeBorderColorOwnRequests(node); + removeUnknownUsers(node); + } + }, "/requests"); + } } function changeFollowedStarColor(node) { @@ -71,7 +74,7 @@ function removeUnknownUsers(node) { let parsedDocument = parser.parseFromString(profileData, 'text/html'); lowerDiv.innerHTML = ''; - while(parsedDocument.body.hasChildNodes()){ + while (parsedDocument.body.hasChildNodes()) { lowerDiv.appendChild(parsedDocument.body.removeChild(parsedDocument.body.firstChild)); } } diff --git a/src/javascript/enhancements/languageDisplay.js b/src/javascript/enhancements/languageDisplay.js index 124431e..dddd1d9 100644 --- a/src/javascript/enhancements/languageDisplay.js +++ b/src/javascript/enhancements/languageDisplay.js @@ -1,13 +1,16 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; export function init() { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - updateLanguageDisplay(node) - } - }, "^/anime/[0-9]*$"); + if (getGlobalConfiguration().animeLanguageDisplay) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + updateLanguageDisplay(node) + } + }, "^/anime/[0-9]*$"); + } } function updateLanguageDisplay(node) { diff --git a/src/javascript/enhancements/notifications.js b/src/javascript/enhancements/notifications.js index e97e530..34330e3 100644 --- a/src/javascript/enhancements/notifications.js +++ b/src/javascript/enhancements/notifications.js @@ -1,14 +1,17 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; export function init() { - core.runAfterLoad(() => { - updateNotificationsInTitle(); - }, ".*"); + if (getGlobalConfiguration().websiteShowNotificationsCountInTab) { + core.runAfterLoad(() => { + updateNotificationsInTitle(); + }, ".*"); - core.runAfterLocationChange(() => { - updateNotificationsInTitle(); - }, ".*"); + core.runAfterLocationChange(() => { + updateNotificationsInTitle(); + }, ".*"); + } } function getNotificationCount() { diff --git a/src/javascript/enhancements/quickSearch.js b/src/javascript/enhancements/quickSearch.js index 95b31d5..92bc5df 100644 --- a/src/javascript/enhancements/quickSearch.js +++ b/src/javascript/enhancements/quickSearch.js @@ -1,3 +1,4 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; @@ -5,9 +6,15 @@ const quickSearchID = 'ea-quickSearch'; const quickSearchLink = 'ea-quickSearchLink'; export function init() { - core.runAfterLoad(() => { - initSearch(); - }, ".*"); + let config = getGlobalConfiguration(); + console.log(config); + console.log(config.websiteDisplayQuickSearch); + console.log(getGlobalConfiguration().websiteDisplayQuickSearch) + if (getGlobalConfiguration().websiteDisplayQuickSearch) { + core.runAfterLoad(() => { + initSearch(); + }, ".*"); + } } function initSearch() { @@ -68,7 +75,7 @@ function handleSearchForShiftF(event) { if (document.activeElement instanceof HTMLInputElement || document.activeElement.isContentEditable) { return; } - + if (event.code === 'KeyF') { event.preventDefault(); document.getElementById(quickSearchID).focus(); diff --git a/src/javascript/enhancements/watch2getherChat.js b/src/javascript/enhancements/watch2getherChat.js index c173f87..96944eb 100644 --- a/src/javascript/enhancements/watch2getherChat.js +++ b/src/javascript/enhancements/watch2getherChat.js @@ -1,12 +1,14 @@ import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; import { v4 as uuidv4 } from 'uuid'; +import { getGlobalConfiguration } from '../configuration/configuration'; export function init() { - // UPS // runAfterLoad is not what we want...wait for runAfterLocationChange.... - core.runAfterLocationChange(() => { - manipulateChatInput(); - }, "^/watch2gether/.*$"); + if (getGlobalConfiguration().w2gDisplayCharacterCounter) { + core.runAfterLocationChange(() => { + manipulateChatInput(); + }, "^/watch2gether/.*$"); + } } function manipulateChatInput() { From d0ace4b1d2d5cfe6d1d8a16d00dbdcb63f1f8b09 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 18:23:00 +0100 Subject: [PATCH 22/29] #32 Changed Configuration adapter and switched to callbacks where the configuration is used --- src/javascript/configuration/configuration.js | 65 ++++++++----------- src/javascript/enhancements/anilyr.js | 18 ++--- src/javascript/enhancements/animeRequests.js | 24 +++---- .../enhancements/languageDisplay.js | 20 +++--- src/javascript/enhancements/notifications.js | 20 +++--- src/javascript/enhancements/quickSearch.js | 18 +++-- .../enhancements/watch2getherChat.js | 15 +++-- 7 files changed, 88 insertions(+), 92 deletions(-) diff --git a/src/javascript/configuration/configuration.js b/src/javascript/configuration/configuration.js index 1a02c28..ec02001 100644 --- a/src/javascript/configuration/configuration.js +++ b/src/javascript/configuration/configuration.js @@ -1,49 +1,36 @@ import { getGlobalStorageProvider } from "../browserApi/storageProvider"; import { assigned } from "../utils/helpers"; +// website +export const SETTINGS_websiteDisplayQuickSearch = 'websiteDisplayQuickSearch'; // +export const SETTINGS_websiteShowNotificationsCountInTab = 'websiteShowNotificationsCountInTab'; // +export const SETTINGS_websiteHideUnusedTabs = 'websiteHideUnusedTabs'; +export const SETTINGS_websiteOptimizeListAppearance = 'websiteOptimizeListAppearance'; +// anime +export const SETTINGS_animeLanguageDisplay = 'animeLanguageDisplay'; // +// requests +export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage'; // +// player +export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot'; // +// w2g +export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter'; // + class Configuration { constructor() { - // website - this.websiteDisplayQuickSearch = true; - this.websiteShowNotificationsCountInTab = true; - this.websiteHideUnusedTabs = true; - this.websiteOptimizeListAppearance = true; - - // anime - this.animeLanguageDisplay = true; - - // requests - this.requestBeautifyPage = true; - - // player - this.playerAutoplayAfterScreenshot = true; - - // w2g - this.w2gDisplayCharacterCounter = true; - - this.reloadConfiguration(); + this.settingsCache = new Map(); } - reloadConfiguration() { - // website - getGlobalStorageProvider().getData('websiteDisplayQuickSearch', this.websiteDisplayQuickSearch, value => this.websiteDisplayQuickSearch = value); - getGlobalStorageProvider().getData('websiteShowNotificationsCountInTab', this.websiteShowNotificationsCountInTab, value => this.websiteShowNotificationsCountInTab = value); - getGlobalStorageProvider().getData('websiteHideUnusedTabs', this.websiteHideUnusedTabs, value => this.websiteHideUnusedTabs = value); - getGlobalStorageProvider().getData('websiteOptimizeListAppearance', this.websiteOptimizeListAppearance, value => this.websiteOptimizeListAppearance = value); - - // anime - getGlobalStorageProvider().getData('animeLanguageDisplay', this.animeLanguageDisplay, value => this.animeLanguageDisplay = value); - - // requests - getGlobalStorageProvider().getData('requestBeautifyPage', this.requestBeautifyPage, value => this.requestBeautifyPage = value); - - // player - getGlobalStorageProvider().getData('playerAutoplayAfterScreenshot', this.playerAutoplayAfterScreenshot, value => this.playerAutoplayAfterScreenshot = value); - - // w2g - getGlobalStorageProvider().getData('w2gDisplayCharacterCounter', this.w2gDisplayCharacterCounter, value => this.w2gDisplayCharacterCounter = value); - - console.log(this); + getProperty(key, callback) { + if (this.settingsCache.has(key)) { + callback(this.settingsCache.get(key)); + } + else { + // OOOPS // currently all settings are default true. This isn´t a problem but there should be much better soloutions after migration to typescript.... + let value = getGlobalStorageProvider().getData(key, true, value => { + this.settingsCache.set(key, value); + callback(value); + }); + } } } diff --git a/src/javascript/enhancements/anilyr.js b/src/javascript/enhancements/anilyr.js index 129dbfe..b8036f2 100644 --- a/src/javascript/enhancements/anilyr.js +++ b/src/javascript/enhancements/anilyr.js @@ -1,4 +1,4 @@ -import { getGlobalConfiguration } from '../configuration/configuration'; +import { getGlobalConfiguration, SETTINGS_playerAutoplayAfterScreenshot } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; @@ -6,13 +6,15 @@ const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip'; const PLAYER_ID = 'player'; export function init() { - if (getGlobalConfiguration().playerAutoplayAfterScreenshot) { - core.registerScript(node => { - if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { - observeScreenshotTooltip(node); - } - }, "^/anime/[0-9]*/[0-9]*$"); - } + getGlobalConfiguration().getProperty(SETTINGS_playerAutoplayAfterScreenshot, value => { + if (value) { + core.registerScript(node => { + if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { + observeScreenshotTooltip(node); + } + }, "^/anime/[0-9]*/[0-9]*$"); + } + }); } function observeScreenshotTooltip(tooltip) { diff --git a/src/javascript/enhancements/animeRequests.js b/src/javascript/enhancements/animeRequests.js index b73ad66..ce86be0 100644 --- a/src/javascript/enhancements/animeRequests.js +++ b/src/javascript/enhancements/animeRequests.js @@ -1,19 +1,21 @@ -import { getGlobalConfiguration } from '../configuration/configuration'; +import { getGlobalConfiguration, SETTINGS_requestBeautifyPage } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as color from '../utils/colors'; import * as helper from '../utils/helpers'; export function init() { - if (getGlobalConfiguration().requestBeautifyPage) { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - changeFollowedStarColor(node); - changeBorderColorOwnRequests(node); - removeUnknownUsers(node); - } - }, "/requests"); - } + getGlobalConfiguration().getProperty(SETTINGS_requestBeautifyPage, value => { + if (value) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + changeFollowedStarColor(node); + changeBorderColorOwnRequests(node); + removeUnknownUsers(node); + } + }, "/requests"); + } + }); } function changeFollowedStarColor(node) { diff --git a/src/javascript/enhancements/languageDisplay.js b/src/javascript/enhancements/languageDisplay.js index dddd1d9..cd9bf09 100644 --- a/src/javascript/enhancements/languageDisplay.js +++ b/src/javascript/enhancements/languageDisplay.js @@ -1,16 +1,20 @@ -import { getGlobalConfiguration } from '../configuration/configuration'; +import { getGlobalConfiguration, SETTINGS_animeLanguageDisplay } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; export function init() { - if (getGlobalConfiguration().animeLanguageDisplay) { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - updateLanguageDisplay(node) + getGlobalConfiguration().getProperty(SETTINGS_animeLanguageDisplay, value => { + if (value) { + if (getGlobalConfiguration().animeLanguageDisplay) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + updateLanguageDisplay(node) + } + }, "^/anime/[0-9]*$"); } - }, "^/anime/[0-9]*$"); - } + } + }); } function updateLanguageDisplay(node) { diff --git a/src/javascript/enhancements/notifications.js b/src/javascript/enhancements/notifications.js index 34330e3..10df5ff 100644 --- a/src/javascript/enhancements/notifications.js +++ b/src/javascript/enhancements/notifications.js @@ -1,17 +1,19 @@ -import { getGlobalConfiguration } from '../configuration/configuration'; +import { getGlobalConfiguration, SETTINGS_websiteShowNotificationsCountInTab } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; export function init() { - if (getGlobalConfiguration().websiteShowNotificationsCountInTab) { - core.runAfterLoad(() => { - updateNotificationsInTitle(); - }, ".*"); + getGlobalConfiguration().getProperty(SETTINGS_websiteShowNotificationsCountInTab, value => { + if (value) { + core.runAfterLoad(() => { + updateNotificationsInTitle(); + }, ".*"); - core.runAfterLocationChange(() => { - updateNotificationsInTitle(); - }, ".*"); - } + core.runAfterLocationChange(() => { + updateNotificationsInTitle(); + }, ".*"); + } + }); } function getNotificationCount() { diff --git a/src/javascript/enhancements/quickSearch.js b/src/javascript/enhancements/quickSearch.js index 92bc5df..dddf15d 100644 --- a/src/javascript/enhancements/quickSearch.js +++ b/src/javascript/enhancements/quickSearch.js @@ -1,4 +1,4 @@ -import { getGlobalConfiguration } from '../configuration/configuration'; +import { getGlobalConfiguration, SETTINGS_websiteDisplayQuickSearch } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; @@ -6,15 +6,13 @@ const quickSearchID = 'ea-quickSearch'; const quickSearchLink = 'ea-quickSearchLink'; export function init() { - let config = getGlobalConfiguration(); - console.log(config); - console.log(config.websiteDisplayQuickSearch); - console.log(getGlobalConfiguration().websiteDisplayQuickSearch) - if (getGlobalConfiguration().websiteDisplayQuickSearch) { - core.runAfterLoad(() => { - initSearch(); - }, ".*"); - } + getGlobalConfiguration().getProperty(SETTINGS_websiteDisplayQuickSearch, value => { + if (value) { + core.runAfterLoad(() => { + initSearch(); + }, ".*"); + } + }); } function initSearch() { diff --git a/src/javascript/enhancements/watch2getherChat.js b/src/javascript/enhancements/watch2getherChat.js index 96944eb..a3e5dc6 100644 --- a/src/javascript/enhancements/watch2getherChat.js +++ b/src/javascript/enhancements/watch2getherChat.js @@ -1,14 +1,15 @@ import * as core from '../utils/aniwatchCore'; -import * as helper from '../utils/helpers'; import { v4 as uuidv4 } from 'uuid'; -import { getGlobalConfiguration } from '../configuration/configuration'; +import { getGlobalConfiguration, SETTINGS_w2gDisplayCharacterCounter } from '../configuration/configuration'; export function init() { - if (getGlobalConfiguration().w2gDisplayCharacterCounter) { - core.runAfterLocationChange(() => { - manipulateChatInput(); - }, "^/watch2gether/.*$"); - } + getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => { + if (value) { + core.runAfterLocationChange(() => { + manipulateChatInput(); + }, "^/watch2gether/.*$"); + } + }); } function manipulateChatInput() { From 4d809dae12de1661350e3377e28aa8f722ef8fdc Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 18:47:58 +0100 Subject: [PATCH 23/29] #32 Implemented settings for CSS enhancements --- src/javascript/app.js | 5 ++ src/javascript/configuration/configuration.js | 13 ++-- .../enhancements/cssEnhancements.js | 69 +++++++++++++++++++ src/stylesheets/enhancements/_lists.scss | 2 +- src/stylesheets/enhancements/_tabs.scss | 2 +- 5 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 src/javascript/enhancements/cssEnhancements.js diff --git a/src/javascript/app.js b/src/javascript/app.js index 8b14f9c..d34e051 100644 --- a/src/javascript/app.js +++ b/src/javascript/app.js @@ -9,6 +9,8 @@ import { init as languageDisplay } from './enhancements/languageDisplay'; import { init as notifications } from './enhancements/notifications'; import { init as quickSearch } from './enhancements/quickSearch'; import { init as watch2getherChat } from './enhancements/watch2getherChat'; +// css +import { init as cssEnhancements } from './enhancements/cssEnhancements'; // core initCore(); @@ -23,3 +25,6 @@ languageDisplay(); notifications(); quickSearch(); watch2getherChat(); + +// css +cssEnhancements(); \ No newline at end of file diff --git a/src/javascript/configuration/configuration.js b/src/javascript/configuration/configuration.js index ec02001..3e16999 100644 --- a/src/javascript/configuration/configuration.js +++ b/src/javascript/configuration/configuration.js @@ -2,19 +2,18 @@ import { getGlobalStorageProvider } from "../browserApi/storageProvider"; import { assigned } from "../utils/helpers"; // website -export const SETTINGS_websiteDisplayQuickSearch = 'websiteDisplayQuickSearch'; // -export const SETTINGS_websiteShowNotificationsCountInTab = 'websiteShowNotificationsCountInTab'; // +export const SETTINGS_websiteDisplayQuickSearch = 'websiteDisplayQuickSearch'; +export const SETTINGS_websiteShowNotificationsCountInTab = 'websiteShowNotificationsCountInTab'; export const SETTINGS_websiteHideUnusedTabs = 'websiteHideUnusedTabs'; export const SETTINGS_websiteOptimizeListAppearance = 'websiteOptimizeListAppearance'; // anime -export const SETTINGS_animeLanguageDisplay = 'animeLanguageDisplay'; // +export const SETTINGS_animeLanguageDisplay = 'animeLanguageDisplay'; // requests -export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage'; // +export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage'; // player -export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot'; // +export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot'; // w2g -export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter'; // - +export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter'; class Configuration { constructor() { this.settingsCache = new Map(); diff --git a/src/javascript/enhancements/cssEnhancements.js b/src/javascript/enhancements/cssEnhancements.js new file mode 100644 index 0000000..1e01766 --- /dev/null +++ b/src/javascript/enhancements/cssEnhancements.js @@ -0,0 +1,69 @@ +import { getGlobalConfiguration, SETTINGS_websiteHideUnusedTabs, SETTINGS_websiteOptimizeListAppearance } from '../configuration/configuration'; +import * as core from '../utils/aniwatchCore'; +import * as helper from '../utils/helpers'; + +export function init() { + getGlobalConfiguration().getProperty(SETTINGS_websiteHideUnusedTabs, value => { + // if disabled, add class to avoid our css optimizations + if (!value) { + let disableFunc = node => { + if (helper.isHtmlElement(node)) { + let disableNode = node => { + node.classList.add('awp-hide-unused-disabled') + } + + if (node.tagName === 'MD-TAB-ITEM') { + disableNode(node); + } + else { + node.querySelectorAll('md-tab-item').forEach(node => disableNode(node)); + } + } + }; + + core.registerScript(node => { + disableFunc(node); + }, ".*"); + + core.runAfterLoad(() => { + disableFunc(document.body); + }, ".*"); + + core.runAfterLocationChange(() => { + disableFunc(document.body); + }, ".*"); + } + }); + + getGlobalConfiguration().getProperty(SETTINGS_websiteOptimizeListAppearance, value => { + // if disabled, add class to avoid our css optimizations + if (!value) { + let disableFunc = node => { + if (helper.isHtmlElement(node)) { + let disableNode = node => { + node.classList.add('awp-list-disabled') + } + + if (node.tagName === 'MD-LIST-ITEM') { + disableNode(node); + } + else { + node.querySelectorAll('md-list-item').forEach(node => disableNode(node)); + } + } + } + + core.registerScript(node => { + disableFunc(node); + }, ".*"); + + core.runAfterLoad(() => { + disableFunc(document.body); + }, ".*"); + + core.runAfterLocationChange(() => { + disableFunc(document.body); + }, ".*"); + } + }); +} \ No newline at end of file diff --git a/src/stylesheets/enhancements/_lists.scss b/src/stylesheets/enhancements/_lists.scss index 078205e..3edef41 100644 --- a/src/stylesheets/enhancements/_lists.scss +++ b/src/stylesheets/enhancements/_lists.scss @@ -1,5 +1,5 @@ md-list-item { - &:not(:last-child) { + &:not(:last-child):not(.awp-list-disabled) { border-bottom: 1px solid $gray; } } diff --git a/src/stylesheets/enhancements/_tabs.scss b/src/stylesheets/enhancements/_tabs.scss index 899947a..3965c1f 100644 --- a/src/stylesheets/enhancements/_tabs.scss +++ b/src/stylesheets/enhancements/_tabs.scss @@ -1,6 +1,6 @@ md-tab-item { // hide disabled tabs - &.md-disabled { + &.md-disabled:not(.awp-hide-unused-disabled) { display: none; } } From bdd94e030af8f0ac5da252db84c3be6221bce824 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 8 Nov 2020 12:32:45 +0100 Subject: [PATCH 24/29] #32 reduced i statements for css disable --- src/javascript/enhancements/cssEnhancements.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/javascript/enhancements/cssEnhancements.js b/src/javascript/enhancements/cssEnhancements.js index 1e01766..ce62948 100644 --- a/src/javascript/enhancements/cssEnhancements.js +++ b/src/javascript/enhancements/cssEnhancements.js @@ -28,10 +28,6 @@ export function init() { core.runAfterLoad(() => { disableFunc(document.body); }, ".*"); - - core.runAfterLocationChange(() => { - disableFunc(document.body); - }, ".*"); } }); @@ -60,10 +56,6 @@ export function init() { core.runAfterLoad(() => { disableFunc(document.body); }, ".*"); - - core.runAfterLocationChange(() => { - disableFunc(document.body); - }, ".*"); } }); } \ No newline at end of file From bce216205f6805165d444fd61139d01f82a7be49 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 8 Nov 2020 13:01:05 +0100 Subject: [PATCH 25/29] #32 Added implementation for firefox api --- src/javascript/browserApi/storageProvider.js | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/javascript/browserApi/storageProvider.js b/src/javascript/browserApi/storageProvider.js index 06d621a..cae3bf6 100644 --- a/src/javascript/browserApi/storageProvider.js +++ b/src/javascript/browserApi/storageProvider.js @@ -32,13 +32,32 @@ class StorageProviderChromium { class StorageProviderFirefox { - setData(key, value, callback) { + setData(key, value) { + let obj = {}; + obj[key] = value; + + this.getStorage().set(obj); } getData(key, defaultValue, callback) { + let promise = this.getStorage().get(key); + + promise.then(items => { + if (assigned(items) && assigned(items[key])) { + callback(items[key]); + } + else { + callback(defaultValue); + } + }); } getStorage() { + if (assigned(browser.storage.sync)) { + return browser.storage.sync; + } + + return browser.storage.local; } } From 0cae9dd945dbf3556b23c01de7ff24b01ea1d47f Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 8 Nov 2020 13:11:28 +0100 Subject: [PATCH 26/29] #32 Settings open in tab --- src/manifests/chrome.manifest.json | 2 +- src/manifests/firefox.manifest.json | 2 +- src/manifests/manifest.template.json | 2 +- src/manifests/opera.manifest.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/manifests/chrome.manifest.json b/src/manifests/chrome.manifest.json index 0d0b03b..8345845 100644 --- a/src/manifests/chrome.manifest.json +++ b/src/manifests/chrome.manifest.json @@ -17,7 +17,7 @@ }, "options_ui": { "page": "html/settings.html", - "open_in_tab": true + "open_in_tab": false }, "content_scripts": [ { diff --git a/src/manifests/firefox.manifest.json b/src/manifests/firefox.manifest.json index efd0708..a75dd90 100644 --- a/src/manifests/firefox.manifest.json +++ b/src/manifests/firefox.manifest.json @@ -17,7 +17,7 @@ }, "options_ui": { "page": "html/settings.html", - "open_in_tab": true + "open_in_tab": false }, "content_scripts": [ { diff --git a/src/manifests/manifest.template.json b/src/manifests/manifest.template.json index 69f1d22..dd42d6a 100644 --- a/src/manifests/manifest.template.json +++ b/src/manifests/manifest.template.json @@ -21,7 +21,7 @@ }, "options_ui": { "page": "html/settings.html", - "open_in_tab": true + "open_in_tab": false }, "content_scripts": [ { diff --git a/src/manifests/opera.manifest.json b/src/manifests/opera.manifest.json index dabadbf..66477ee 100644 --- a/src/manifests/opera.manifest.json +++ b/src/manifests/opera.manifest.json @@ -18,7 +18,7 @@ }, "options_ui": { "page": "html/settings.html", - "open_in_tab": true + "open_in_tab": false }, "content_scripts": [ { From 10e584bfa969e152b97f1b1d30ba2b85653f68e7 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 8 Nov 2020 13:11:52 +0100 Subject: [PATCH 27/29] #32 Added version information and changelog hyperlink into settings --- src/html/settings.html | 2 ++ src/javascript/settings.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/html/settings.html b/src/html/settings.html index 8422a61..b63bf93 100644 --- a/src/html/settings.html +++ b/src/html/settings.html @@ -47,6 +47,8 @@
Please reload aniwatch website after you changed the settings. +
+ - Changelogs diff --git a/src/javascript/settings.js b/src/javascript/settings.js index 8441fa2..86e4208 100644 --- a/src/javascript/settings.js +++ b/src/javascript/settings.js @@ -42,4 +42,7 @@ onReady(() => { // try restore options restoreOptions(); + + // update version label + document.getElementById('version').innerText = `v${chrome.runtime.getManifest().version}` }); \ No newline at end of file From 483ea7f96e8232e237dd3ad254c67a52e6eb3f36 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 8 Nov 2020 13:18:41 +0100 Subject: [PATCH 28/29] #32 Fixed issues remarked by scrutinizer-ci * unused variable * explicit unedfined assignments --- src/javascript/browserApi/storageProvider.js | 2 +- src/javascript/configuration/configuration.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/javascript/browserApi/storageProvider.js b/src/javascript/browserApi/storageProvider.js index cae3bf6..0f84b1d 100644 --- a/src/javascript/browserApi/storageProvider.js +++ b/src/javascript/browserApi/storageProvider.js @@ -61,7 +61,7 @@ class StorageProviderFirefox { } } -let __storageProvieder = undefined; +let __storageProvieder; function createStorageProvider() { // chrome based browser diff --git a/src/javascript/configuration/configuration.js b/src/javascript/configuration/configuration.js index 3e16999..23ad4fd 100644 --- a/src/javascript/configuration/configuration.js +++ b/src/javascript/configuration/configuration.js @@ -25,7 +25,7 @@ class Configuration { } else { // OOOPS // currently all settings are default true. This isn´t a problem but there should be much better soloutions after migration to typescript.... - let value = getGlobalStorageProvider().getData(key, true, value => { + getGlobalStorageProvider().getData(key, true, value => { this.settingsCache.set(key, value); callback(value); }); @@ -33,7 +33,7 @@ class Configuration { } } -let __globalConfig = undefined; +let __globalConfig; export function getGlobalConfiguration() { if (!assigned(__globalConfig)) { From 51b943bc0fe098c60ed9a38cb9ff16daa8b7cc3b Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 8 Nov 2020 13:25:55 +0100 Subject: [PATCH 29/29] #32 Fixed wrong implementation of settings check for language display --- src/javascript/enhancements/languageDisplay.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/javascript/enhancements/languageDisplay.js b/src/javascript/enhancements/languageDisplay.js index cd9bf09..e96eef3 100644 --- a/src/javascript/enhancements/languageDisplay.js +++ b/src/javascript/enhancements/languageDisplay.js @@ -5,14 +5,12 @@ import * as helper from '../utils/helpers'; export function init() { getGlobalConfiguration().getProperty(SETTINGS_animeLanguageDisplay, value => { if (value) { - if (getGlobalConfiguration().animeLanguageDisplay) { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - updateLanguageDisplay(node) - } - }, "^/anime/[0-9]*$"); - } + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + updateLanguageDisplay(node) + } + }, "^/anime/[0-9]*$"); } }); }