mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-02 10:52:20 +01:00
finish implementation
This commit is contained in:
1 parent
3cd5b93b56
commit
54e9267655
5 files changed
+111
-17
No files matched your search
@@ -77,19 +77,29 @@
|
|||||||
<span class="slider" />
|
<span class="slider" />
|
||||||
<span class="switchLabel">Disable vote submission</span>
|
<span class="switchLabel">Disable vote submission</span>
|
||||||
</label>
|
</label>
|
||||||
<label class="switch">
|
<br />
|
||||||
|
<label class="switch" data-hover="Use custom colors in new pages.">
|
||||||
<input type="checkbox" id="colored_bar" />
|
<input type="checkbox" id="colored_bar" />
|
||||||
<span class="slider" />
|
<span class="slider" />
|
||||||
<span class="switchLabel">Colorize ratio bar</span>
|
<span class="switchLabel">Colorize ratio bar</span>
|
||||||
</label>
|
</label>
|
||||||
<br />
|
<br />
|
||||||
<label class="switch">
|
<label class="switch" data-hover="Use custom colors in new pages.">
|
||||||
<input type="checkbox" id="color_thumbs" />
|
<input type="checkbox" id="colored_thumbs" />
|
||||||
<span class="slider" />
|
<span class="slider" />
|
||||||
<span class="switchLabel">Colorize thumbs</span>
|
<span class="switchLabel">Colorize thumbs</span>
|
||||||
</label>
|
</label>
|
||||||
<br />
|
<br />
|
||||||
<!-- TODO: color theme menu select -->
|
<div class="custom-select">
|
||||||
|
<label for="color_theme">Color theme:</label>
|
||||||
|
<select name="color_theme" id="color_theme">
|
||||||
|
<option value="classic" id="color_theme_classic">Classic</option>
|
||||||
|
<option value="accessible" id="color_theme_accessible">Accessible</option>
|
||||||
|
<option value="neon" id="color_theme_neon">Neon</option>
|
||||||
|
</select>
|
||||||
|
<span id="color_theme_example_like" style="display: inline-block; vertical-align: text-top; width: 1em; height: 1em;"> </span>
|
||||||
|
<span id="color_theme_example_dislike" style="display: inline-block; vertical-align: text-top; width: 1em; height: 1em;"> </span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- <br />
|
<!-- <br />
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ document
|
|||||||
document
|
document
|
||||||
.getElementById("color_theme")
|
.getElementById("color_theme")
|
||||||
.addEventListener("click", (ev) => {
|
.addEventListener("click", (ev) => {
|
||||||
chrome.storage.sync.set({ colorTheme: ev.target.checked });
|
chrome.storage.sync.set({ colorTheme: ev.target.value });
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Advanced Toggle */
|
/* Advanced Toggle */
|
||||||
@@ -167,7 +167,8 @@ function handleColoredBarChangeEvent(value) {
|
|||||||
|
|
||||||
function handleColorThemeChangeEvent(value) {
|
function handleColorThemeChangeEvent(value) {
|
||||||
config.colorTheme = value;
|
config.colorTheme = value;
|
||||||
// TODO: check selected menu item
|
document.getElementById("color_theme_example_like").style.backgroundColor = getColorFromTheme(value, true);
|
||||||
|
document.getElementById("color_theme_example_dislike").style.backgroundColor = getColorFromTheme(value, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
(async function getStatus() {
|
(async function getStatus() {
|
||||||
@@ -190,6 +191,34 @@ function handleColorThemeChangeEvent(value) {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
function getColorFromTheme(colorTheme, voteIsLike) {
|
||||||
|
let colorString;
|
||||||
|
switch(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* popup-script.js
|
/* popup-script.js
|
||||||
document.querySelector('#login')
|
document.querySelector('#login')
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { getButtons } from "./buttons";
|
import { getButtons } from "./buttons";
|
||||||
import { likesDisabledState, extConfig } from "./state";
|
import { likesDisabledState, extConfig } from "./state";
|
||||||
import { cLog } from "./utils";
|
import {
|
||||||
|
cLog,
|
||||||
|
getColorFromTheme,
|
||||||
|
} from "./utils";
|
||||||
|
|
||||||
function createRateBar(likes, dislikes) {
|
function createRateBar(likes, dislikes) {
|
||||||
if (!likesDisabledState) {
|
if (!likesDisabledState) {
|
||||||
@@ -15,6 +18,12 @@ function createRateBar(likes, dislikes) {
|
|||||||
likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
|
likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
|
||||||
|
|
||||||
if (!rateBar) {
|
if (!rateBar) {
|
||||||
|
let colorLikeStyle = '';
|
||||||
|
let colorDislikeStyle = '';
|
||||||
|
if (extConfig.coloredBar) {
|
||||||
|
colorLikeStyle = '; background-color: ' + getColorFromTheme(true);
|
||||||
|
colorDislikeStyle = '; background-color: ' + getColorFromTheme(false);
|
||||||
|
}
|
||||||
(
|
(
|
||||||
document.getElementById("menu-container") ||
|
document.getElementById("menu-container") ||
|
||||||
document.querySelector("ytm-slim-video-action-bar-renderer")
|
document.querySelector("ytm-slim-video-action-bar-renderer")
|
||||||
@@ -25,11 +34,11 @@ function createRateBar(likes, dislikes) {
|
|||||||
<div class="ryd-tooltip-bar-container">
|
<div class="ryd-tooltip-bar-container">
|
||||||
<div
|
<div
|
||||||
id="ryd-bar-container"
|
id="ryd-bar-container"
|
||||||
style="width: 100%; height: 2px;"
|
style="width: 100%; height: 2px;${colorDislikeStyle}"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
id="ryd-bar"
|
id="ryd-bar"
|
||||||
style="width: ${widthPercent}%; height: 100%"
|
style="width: ${widthPercent}%; height: 100%${colorLikeStyle}"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -45,12 +54,11 @@ function createRateBar(likes, dislikes) {
|
|||||||
document.querySelector(
|
document.querySelector(
|
||||||
"#ryd-dislike-tooltip > #tooltip"
|
"#ryd-dislike-tooltip > #tooltip"
|
||||||
).innerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()}`;
|
).innerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()}`;
|
||||||
|
if (extConfig.coloredBar) {
|
||||||
|
document.getElementById("ryd-bar-container").style.backgroundColor = getColorFromTheme(true);
|
||||||
|
document.getElementById("ryd-bar").style.backgroundColor = getColorFromTheme(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extConfig.coloredBar) {
|
|
||||||
// TODO: colorize bar
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cLog("removing bar");
|
cLog("removing bar");
|
||||||
let ratebar = document.getElementById("ryd-bar-container");
|
let ratebar = document.getElementById("ryd-bar-container");
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { getLikeButton, getDislikeButton, getButtons } from "./buttons";
|
import { getLikeButton, getDislikeButton, getButtons } from "./buttons";
|
||||||
import { createRateBar } from "./bar";
|
import { createRateBar } from "./bar";
|
||||||
import { getBrowser, getVideoId, cLog, numberFormat } from "./utils";
|
import {
|
||||||
|
getBrowser,
|
||||||
|
getVideoId,
|
||||||
|
cLog,
|
||||||
|
numberFormat,
|
||||||
|
getColorFromTheme,
|
||||||
|
} from "./utils";
|
||||||
import { sendVideoIds } from "./events";
|
import { sendVideoIds } from "./events";
|
||||||
|
|
||||||
//TODO: Do not duplicate here and in ryd.background.js
|
//TODO: Do not duplicate here and in ryd.background.js
|
||||||
@@ -102,7 +108,8 @@ function processResponse(response, storedData) {
|
|||||||
storedData.likes = getLikeCountFromButton() || parseInt(response.likes);
|
storedData.likes = getLikeCountFromButton() || parseInt(response.likes);
|
||||||
createRateBar(storedData.likes, storedData.dislikes);
|
createRateBar(storedData.likes, storedData.dislikes);
|
||||||
if (extConfig.coloredThumbs === true) {
|
if (extConfig.coloredThumbs === true) {
|
||||||
// TODO: colorize thumbs
|
getLikeButton().style.color = getColorFromTheme(true);
|
||||||
|
getDislikeButton().style.color = getColorFromTheme(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +170,39 @@ function initializeDisableVoteSubmission() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initializeColoredThumbs() {
|
||||||
|
getBrowser().storage.sync.get(['coloredThumbs'], (res) => {
|
||||||
|
if (res.coloredThumbs === undefined) {
|
||||||
|
getBrowser().storage.sync.set({coloredThumbs: false});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
extConfig.coloredThumbs = res.coloredThumbs;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeColoredBar() {
|
||||||
|
getBrowser().storage.sync.get(['coloredBar'], (res) => {
|
||||||
|
if (res.coloredBar === undefined) {
|
||||||
|
getBrowser().storage.sync.set({coloredBar: false});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
extConfig.coloredBar = res.coloredBar;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeColorTheme() {
|
||||||
|
getBrowser().storage.sync.get(['colorTheme'], (res) => {
|
||||||
|
if (res.colorTheme === undefined) {
|
||||||
|
getBrowser().storage.sync.set({colorTheme: false});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
extConfig.colorTheme = res.colorTheme;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
isMobile,
|
isMobile,
|
||||||
isVideoDisliked,
|
isVideoDisliked,
|
||||||
|
|||||||
@@ -99,4 +99,11 @@ function getColorFromTheme(voteIsLike) {
|
|||||||
return colorString;
|
return colorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { numberFormat, getBrowser, getVideoId, isVideoLoaded, cLog }
|
export {
|
||||||
|
numberFormat,
|
||||||
|
getBrowser,
|
||||||
|
getVideoId,
|
||||||
|
isVideoLoaded,
|
||||||
|
cLog,
|
||||||
|
getColorFromTheme,
|
||||||
|
}
|
||||||
Reference in new issue
Block a user