mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-29 17:37:54 +01:00
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:
1 parent
510c083c77
commit
b476c60fe0
7 files changed
+210
-8
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { getButtons } from "./buttons";
|
||||
import { likesDisabledState } from "./state";
|
||||
import { likesDisabledState, extConfig } from "./state";
|
||||
import { cLog } from "./utils";
|
||||
|
||||
function createRateBar(likes, dislikes) {
|
||||
@@ -46,6 +46,11 @@ function createRateBar(likes, dislikes) {
|
||||
"#ryd-dislike-tooltip > #tooltip"
|
||||
).innerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()}`;
|
||||
}
|
||||
|
||||
if (extConfig.coloredBar) {
|
||||
// TODO: colorize bar
|
||||
}
|
||||
|
||||
} else {
|
||||
cLog("removing bar");
|
||||
let ratebar = document.getElementById("ryd-bar-container");
|
||||
|
||||
@@ -110,12 +110,39 @@ function storageChangeHandler(changes, area) {
|
||||
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) {
|
||||
extConfig.disableVoteSubmission = value;
|
||||
}
|
||||
|
||||
function handleColoredThumbsChangeEvent(value) {
|
||||
extConfig.coloredThumbs = value;
|
||||
}
|
||||
|
||||
function handleColoredBarChangeEvent(value) {
|
||||
extConfig.coloredBar = value;
|
||||
}
|
||||
|
||||
function handleColorThemeChangeEvent(value) {
|
||||
extConfig.colorTheme = value;
|
||||
}
|
||||
|
||||
export {
|
||||
sendVote,
|
||||
sendVideoIds,
|
||||
|
||||
@@ -13,6 +13,9 @@ const DISLIKES_DISABLED_TEXT = "DISLIKES DISABLED";
|
||||
|
||||
let extConfig = {
|
||||
disableVoteSubmission: false,
|
||||
coloredThumbs: false,
|
||||
coloredBar: false,
|
||||
colorTheme: "classic",
|
||||
};
|
||||
|
||||
let storedData = {
|
||||
@@ -98,6 +101,9 @@ function processResponse(response, storedData) {
|
||||
storedData.dislikes = parseInt(response.dislikes);
|
||||
storedData.likes = getLikeCountFromButton() || parseInt(response.likes);
|
||||
createRateBar(storedData.likes, storedData.dislikes);
|
||||
if (extConfig.coloredThumbs === true) {
|
||||
// TODO: colorize thumbs
|
||||
}
|
||||
}
|
||||
|
||||
async function setState(storedData) {
|
||||
@@ -142,6 +148,9 @@ function setInitialState() {
|
||||
|
||||
function initExtConfig() {
|
||||
initializeDisableVoteSubmission();
|
||||
initializeColoredThumbs();
|
||||
initializeColoredBar();
|
||||
initializeColorTheme();
|
||||
}
|
||||
|
||||
function initializeDisableVoteSubmission() {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
extConfig,
|
||||
} from "./state";
|
||||
|
||||
function roundDown(num) {
|
||||
if (num < 1000) return num;
|
||||
const int = Math.floor(Math.log10(num) - 2);
|
||||
@@ -67,4 +71,32 @@ function cLog(message, writer) {
|
||||
}
|
||||
}
|
||||
|
||||
function getColorFromTheme(voteIsLike) {
|
||||
let colorString;
|
||||
switch(extConfig.colorTheme) {
|
||||
case 'accessible':
|
||||
if (voteIsLike === true) {
|
||||
colorString = 'dodgerblue';
|
||||
} else {
|
||||
colorString = 'gold';
|
||||
}
|
||||
break;
|
||||
case 'neon':
|
||||
if (voteIsLike === true) {
|
||||
colorString = 'aqua';
|
||||
} else {
|
||||
colorString = 'magenta';
|
||||
}
|
||||
break;
|
||||
case 'classic':
|
||||
default:
|
||||
if (voteIsLike === true) {
|
||||
colorString = 'lime';
|
||||
} else {
|
||||
colorString = 'red';
|
||||
}
|
||||
}
|
||||
return colorString;
|
||||
}
|
||||
|
||||
export { numberFormat, getBrowser, getVideoId, isVideoLoaded, cLog }
|
||||
Reference in new issue
Block a user