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
+
+
+
+
+
+
+
+
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 @@
-
-