From 2c45c6ba88923776c6bb549520b87c99df38a7a7 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:23:12 +0100 Subject: [PATCH] #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);