#32 Moved around some of the files and cleaned old and deprecated files from first draft

This commit is contained in:
Serraniel 2020-11-07 17:23:12 +01:00
parent b4a18cdc4d
commit 2c45c6ba88
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
4 changed files with 1 additions and 177 deletions

View file

@ -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"';

View file

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

View file

@ -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);