mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-26 08:13:00 +01:00
Add custom number formats
Fix Issues #201 #364 #407 Using plugin options (Issue #387)
This commit is contained in:
1 parent
510c083c77
commit
a2bc4ca92e
6 files changed
+224
-5
No files matched your search
@@ -5,10 +5,12 @@ let api;
|
||||
|
||||
/** stores extension's global config */
|
||||
let extConfig = {
|
||||
disableVoteSubmission: false
|
||||
disableVoteSubmission: false,
|
||||
// coloredThumbs: false,
|
||||
// coloredBar: false,
|
||||
}
|
||||
numberDisplayFormat: 'compactShort', // compactShort, compactLong, standard
|
||||
numberDisplayRoundDown: true, // locale 'de' shows exact numbers by default
|
||||
};
|
||||
|
||||
if (isChrome()) api = chrome;
|
||||
else if (isFirefox()) api = browser;
|
||||
@@ -235,6 +237,14 @@ function storageChangeHandler(changes, area) {
|
||||
if (changes.disableVoteSubmission !== undefined) {
|
||||
handleDisableVoteSubmissionChangeEvent(changes.disableVoteSubmission.newValue);
|
||||
}
|
||||
if (changes.numberDisplayRoundDown !== undefined) {
|
||||
handleNumberDisplayRoundDownChangeEvent(
|
||||
changes.numberDisplayRoundDown.newValue
|
||||
);
|
||||
}
|
||||
if (changes.numberDisplayFormat !== undefined) {
|
||||
handleNumberDisplayFormatChangeEvent(changes.numberDisplayFormat.newValue);
|
||||
}
|
||||
}
|
||||
|
||||
function handleDisableVoteSubmissionChangeEvent(value) {
|
||||
@@ -246,6 +256,14 @@ function handleDisableVoteSubmissionChangeEvent(value) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleNumberDisplayFormatChangeEvent(value) {
|
||||
extConfig.numberDisplayFormat = value;
|
||||
}
|
||||
|
||||
function handleNumberDisplayRoundDownChangeEvent(value) {
|
||||
extConfig.numberDisplayRoundDown = value;
|
||||
}
|
||||
|
||||
function changeIcon(iconName) {
|
||||
if (api.action !== undefined) api.action.setIcon({path: "/icons/" + iconName});
|
||||
else if (api.browserAction !== undefined) api.browserAction.setIcon({path: "/icons/" + iconName});
|
||||
@@ -256,6 +274,8 @@ api.storage.onChanged.addListener(storageChangeHandler);
|
||||
|
||||
function initExtConfig() {
|
||||
initializeDisableVoteSubmission();
|
||||
initializeNumberDisplayFormat();
|
||||
initializeNumberDisplayRoundDown();
|
||||
}
|
||||
|
||||
function initializeDisableVoteSubmission() {
|
||||
@@ -270,6 +290,26 @@ function initializeDisableVoteSubmission() {
|
||||
});
|
||||
}
|
||||
|
||||
function initializeNumberDisplayRoundDown() {
|
||||
api.storage.sync.get(['numberDisplayRoundDown'], (res) => {
|
||||
if (res.numberDisplayRoundDown === undefined) {
|
||||
api.storage.sync.set({numberDisplayRoundDown: true});
|
||||
} else {
|
||||
extConfig.numberDisplayRoundDown = res.numberDisplayRoundDown;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initializeNumberDisplayFormat() {
|
||||
api.storage.sync.get(['numberDisplayFormat'], (res) => {
|
||||
if (res.numberDisplayFormat === undefined) {
|
||||
api.storage.sync.set({ numberDisplayFormat: 'compactShort' });
|
||||
} else {
|
||||
extConfig.numberDisplayFormat = res.numberDisplayFormat;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isChrome() {
|
||||
return typeof chrome !== "undefined" && typeof chrome.runtime !== "undefined";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user