cherry pick from previously broken and abandoned branch

colorize buttons and ratio bar

Resolves #218
Using user options (#387)

edit color schemes

logistics for the added options

handles storage, change, initialize
This commit is contained in:
Yvon Cui committed 2022-01-18 09:54:17 -05:00
1 parent 510c083c77
commit b476c60fe0
7 files changed
+210 -8

No files matched your search

+61 -3
View File
@@ -5,9 +5,10 @@ let api;
/** stores extension's global config */
let extConfig = {
disableVoteSubmission: false
// coloredThumbs: false,
// coloredBar: false,
disableVoteSubmission: false,
coloredThumbs: false,
coloredBar: false,
colorTheme: "classic", // classic, accessible, neon
}
if (isChrome()) api = chrome;
@@ -235,6 +236,15 @@ function storageChangeHandler(changes, area) {
if (changes.disableVoteSubmission !== undefined) {
handleDisableVoteSubmissionChangeEvent(changes.disableVoteSubmission.newValue);
}
if (changes.coloredThumbs !== undefined) {
handleColoredThumbsChangeEvent(changes.coloredThumbs.newValue);
}
if (changes.coloredBar !== undefined) {
handleColoredBarChangeEvent(changes.coloredBar.newValue);
}
if (changes.colorTheme !== undefined) {
handleColorThemeChangeEvent(changes.colorTheme.newValue);
}
}
function handleDisableVoteSubmissionChangeEvent(value) {
@@ -252,10 +262,25 @@ function changeIcon(iconName) {
else console.log('changing icon is not supported');
}
function handleColoredThumbsChangeEvent(value) {
extConfig.coloredThumbs = value;
}
function handleColoredBarChangeEvent(value) {
extConfig.coloredBar = value;
}
function handleColorThemeChangeEvent(value) {
extConfig.colorTheme = value;
}
api.storage.onChanged.addListener(storageChangeHandler);
function initExtConfig() {
initializeDisableVoteSubmission();
initializeColoredThumbs();
initializeColoredBar();
initializeColorTheme();
}
function initializeDisableVoteSubmission() {
@@ -270,6 +295,39 @@ function initializeDisableVoteSubmission() {
});
}
function initializeColoredThumbs() {
api.storage.sync.get(['coloredThumbs'], (res) => {
if (res.coloredThumbs === undefined) {
api.storage.sync.set({coloredThumbs: false});
}
else {
extConfig.coloredThumbs = res.coloredThumbs;
}
});
}
function initializeColoredBar() {
api.storage.sync.get(['coloredBar'], (res) => {
if (res.coloredBar === undefined) {
api.storage.sync.set({coloredBar: false});
}
else {
extConfig.coloredBar = res.coloredBar;
}
});
}
function initializeColorTheme() {
api.storage.sync.get(['colorTheme'], (res) => {
if (res.colorTheme === undefined) {
api.storage.sync.set({colorTheme: false});
}
else {
extConfig.colorTheme = res.colorTheme;
}
});
}
function isChrome() {
return typeof chrome !== "undefined" && typeof chrome.runtime !== "undefined";
}