More cleanup (some marketplace stuff broken, will fix later)

This commit is contained in:
David Ralph
2020-11-04 12:01:18 +00:00
parent c0cced4f5d
commit 3b52010213
11 changed files with 176 additions and 220 deletions

View File

@@ -10,7 +10,6 @@ export default function hexToRgb(value) {
if (valid) {
if (value[0] === '#') value = value.slice(1, value.length);
if (value.length === 3) value = value.replace(regexp, '$1$1$2$2$3$3');
const red = parseInt(value.substr(0, 2), 16);

View File

@@ -1,16 +1,14 @@
export default function rgbToHSv({ red, green, blue }) {
let rr;
let gg;
let bb;
let h;
let s;
let rr, gg, bb, h, s;
const rabs = red / 255;
const gabs = green / 255;
const babs = blue / 255;
const v = Math.max(rabs, gabs, babs);
const diff = v - Math.min(rabs, gabs, babs);
const diffc = c => (v - c) / 6 / diff + 1 / 2;
if (diff === 0) {
h = 0;
s = 0;
@@ -20,18 +18,11 @@ export default function rgbToHSv({ red, green, blue }) {
gg = diffc(gabs);
bb = diffc(babs);
if (rabs === v) {
h = bb - gg;
} else if (gabs === v) {
h = (1 / 3) + rr - bb;
} else if (babs === v) {
h = (2 / 3) + gg - rr;
}
if (h < 0) {
h += 1;
} else if (h > 1) {
h -= 1;
}
if (rabs === v) h = bb - gg;
else if (gabs === v) h = (1 / 3) + rr - bb;
else if (babs === v) h = (2 / 3) + gg - rr;
if (h < 0) h += 1;
else if (h > 1) h -= 1;
}
return {

View File

@@ -10,9 +10,7 @@ export default function setRGBA(red, green, blue, alpha) {
blue: blue | 0,
};
if (isValidRGBValue(alpha) === true) {
color.alpha = alpha | 0;
}
if (isValidRGBValue(alpha) === true) color.alpha = alpha | 0;
// RGBToHSL(color.r, color.g, color.b);

View File

@@ -7,39 +7,31 @@ export default class MarketplaceFunctions {
}
static uninstall(name, type) {
let installed = JSON.parse(localStorage.getItem('installed'));
const uninstallStuff = () => {
for (let i = 0; i < installed.length; i++) {
if (installed[i].name === name) {
installed.splice(i, 1);
break;
}
}
localStorage.setItem('installed', JSON.stringify(installed));
};
switch (type) {
case 'settings':
const oldSettings = JSON.parse(localStorage.getItem('backup_settings'));
localStorage.clear();
oldSettings.forEach(item => localStorage.setItem(item.name, item.value));
uninstallStuff();
break;
case 'quote_packs':
localStorage.removeItem('quote_packs');
localStorage.removeItem('quote_api');
uninstallStuff();
break;
localStorage.removeItem('quote_packs');
localStorage.removeItem('quote_api');
break;
default:
try {
localStorage.removeItem(type);
uninstallStuff();
} catch (e) {
try { localStorage.removeItem(type); }
catch (e) {
toast('Failed to uninstall addon, check the console');
console.error(e);
}
}
}
let installed = JSON.parse(localStorage.getItem('installed'));
for (let i = 0; i < installed.length; i++) {
if (installed[i].name === name) {
installed.splice(i, 1);
break;
}
}
localStorage.setItem('installed', JSON.stringify(installed));
}
static install(type, input, sideload) {
@@ -54,9 +46,6 @@ export default class MarketplaceFunctions {
case 'photo_packs':
localStorage.setItem('photo_packs', JSON.stringify(input.photos));
break;
case 'theme':
localStorage.setItem('theme', input.theme);
break;
case 'quote_packs':
if (input.quote_api) localStorage.setItem('quote_api', JSON.stringify(input.quote_api));
localStorage.setItem('quote_packs', JSON.stringify(input.quotes));