Merge issues fixed, core reformatted with prettier

This commit is contained in:
Dmitrii Selivanov committed 2022-03-20 23:40:46 +03:00
1 parent 6894a706aa
commit b7029ce426
14 files changed
+315 -275

No files matched your search

+30 -30
View File
@@ -1,9 +1,6 @@
import { getButtons } from "./buttons";
import { likesDisabledState, extConfig } from "./state";
import {
cLog,
getColorFromTheme,
} from "./utils";
import { cLog, getColorFromTheme } from "./utils";
import { isMobile, likesDisabledState } from "./state";
import { cLog } from "./utils";
function createRateBar(likes, dislikes) {
@@ -18,22 +15,21 @@ function createRateBar(likes, dislikes) {
const widthPercent =
likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
if (!rateBar) {
let colorLikeStyle = '';
let colorDislikeStyle = '';
let colorLikeStyle = "";
let colorDislikeStyle = "";
if (extConfig.coloredBar) {
colorLikeStyle = '; background-color: ' + getColorFromTheme(true);
colorDislikeStyle = '; background-color: ' + getColorFromTheme(false);
colorLikeStyle = "; background-color: " + getColorFromTheme(true);
colorDislikeStyle = "; background-color: " + getColorFromTheme(false);
}
if (!rateBar && !isMobile()) {
(
document.getElementById("menu-container") ||
document.querySelector("ytm-slim-video-action-bar-renderer")
).insertAdjacentHTML(
"beforeend",
`
if (!rateBar && !isMobile()) {
(
document.getElementById("menu-container") ||
document.querySelector("ytm-slim-video-action-bar-renderer")
).insertAdjacentHTML(
"beforeend",
`
<div class="ryd-tooltip" style="width: ${widthPx}px">
<div class="ryd-tooltip-bar-container">
<div
@@ -51,22 +47,26 @@ function createRateBar(likes, dislikes) {
</tp-yt-paper-tooltip>
</div>
`
);
} else {
document.getElementById("ryd-bar-container").style.width = widthPx + "px";
document.getElementById("ryd-bar").style.width = widthPercent + "%";
document.querySelector(
"#ryd-dislike-tooltip > #tooltip"
).innerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}`;
if (extConfig.coloredBar) {
document.getElementById("ryd-bar-container").style.backgroundColor = getColorFromTheme(false);
document.getElementById("ryd-bar").style.backgroundColor = getColorFromTheme(true);
);
} else {
document.getElementById("ryd-bar-container").style.width =
widthPx + "px";
document.getElementById("ryd-bar").style.width = widthPercent + "%";
document.querySelector(
"#ryd-dislike-tooltip > #tooltip"
).innerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}`;
if (extConfig.coloredBar) {
document.getElementById("ryd-bar-container").style.backgroundColor =
getColorFromTheme(false);
document.getElementById("ryd-bar").style.backgroundColor =
getColorFromTheme(true);
}
}
} else {
cLog("removing bar");
let ratebar = document.getElementById("ryd-bar-container");
ratebar.parentNode.removeChild(ratebar);
}
} else {
cLog("removing bar");
let ratebar = document.getElementById("ryd-bar-container");
ratebar.parentNode.removeChild(ratebar);
}
}
+8 -4
View File
@@ -3,12 +3,16 @@ import { isInViewport } from "./utils";
function getButtons() {
//--- If Watching Youtube Shorts: ---//
if(isShorts()) {
let elements=document.querySelectorAll(isMobile() ? "ytm-like-button-renderer" : "#like-button > ytd-like-button-renderer");
for(let element of elements) {
if (isShorts()) {
let elements = document.querySelectorAll(
isMobile()
? "ytm-like-button-renderer"
: "#like-button > ytd-like-button-renderer"
);
for (let element of elements) {
//Youtube Shorts can have multiple like/dislike buttons when scrolling through videos
//However, only one of them should be visible (no matter how you zoom)
if(isInViewport(element)) {
if (isInViewport(element)) {
return element;
}
}
+7 -11
View File
@@ -111,20 +111,17 @@ function storageChangeHandler(changes, area) {
handleDisableVoteSubmissionChangeEvent(
changes.disableVoteSubmission.newValue
);
}
if (changes.coloredThumbs !== undefined) {
handleColoredThumbsChangeEvent(
changes.coloredThumbs.newValue
);
handleColoredThumbsChangeEvent(changes.coloredThumbs.newValue);
}
if (changes.coloredBar !== undefined) {
handleColoredBarChangeEvent(
changes.coloredBar.newValue
);
handleColoredBarChangeEvent(changes.coloredBar.newValue);
}
if (changes.colorTheme !== undefined) {
handleColorThemeChangeEvent(
changes.colorTheme.newValue
);
handleColorThemeChangeEvent(changes.colorTheme.newValue);
}
if (changes.numberDisplayRoundDown !== undefined) {
handleNumberDisplayRoundDownChangeEvent(
changes.numberDisplayRoundDown.newValue
@@ -139,7 +136,6 @@ function handleDisableVoteSubmissionChangeEvent(value) {
extConfig.disableVoteSubmission = value;
}
function handleColoredThumbsChangeEvent(value) {
extConfig.coloredThumbs = value;
}
@@ -151,7 +147,7 @@ function handleColoredBarChangeEvent(value) {
function handleColorThemeChangeEvent(value) {
extConfig.colorTheme = value;
}
function handleNumberDisplayFormatChangeEvent(value) {
extConfig.numberDisplayFormat = value;
}
+22 -23
View File
@@ -1,6 +1,6 @@
import { getLikeButton, getDislikeButton, getButtons } from "./buttons";
import { createRateBar } from "./bar";
import {
import {
getBrowser,
getVideoId,
cLog,
@@ -22,7 +22,7 @@ let extConfig = {
coloredThumbs: false,
coloredBar: false,
colorTheme: "classic",
numberDisplayFormat: 'compactShort',
numberDisplayFormat: "compactShort",
numberDisplayRoundDown: true,
};
@@ -39,7 +39,7 @@ function isMobile() {
}
function isShorts() {
return location.pathname.startsWith("/shorts")
return location.pathname.startsWith("/shorts");
}
function isVideoLiked() {
@@ -100,7 +100,7 @@ function setDislikes(dislikesCount) {
}
function getLikeCountFromButton() {
if(isShorts()) {
if (isShorts()) {
//Youtube Shorts don't work with this query. It's not nessecary; we can skip it and still see the results.
//It should be possible to fix this function, but it's not critical to showing the dislike count.
return 0;
@@ -183,26 +183,26 @@ function initializeDisableVoteSubmission() {
});
}
function initializeColoredThumbs() {
getBrowser().storage.sync.get(['coloredThumbs'], (res) => {
getBrowser().storage.sync.get(["coloredThumbs"], (res) => {
if (res.coloredThumbs === undefined) {
getBrowser().storage.sync.set({coloredThumbs: false});
}
else {
getBrowser().storage.sync.set({ coloredThumbs: false });
} else {
extConfig.coloredThumbs = res.coloredThumbs;
}
});
}
function initializeColoredBar() {
getBrowser().storage.sync.get(['coloredBar'], (res) => {
getBrowser().storage.sync.get(["coloredBar"], (res) => {
if (res.coloredBar === undefined) {
getBrowser().storage.sync.set({coloredBar: false});
}
else {
getBrowser().storage.sync.set({ coloredBar: false });
} else {
extConfig.coloredBar = res.coloredBar;
}
});
}
function initializeNumberDisplayRoundDown() {
getBrowser().storage.sync.get(["numberDisplayRoundDown"], (res) => {
if (res.numberDisplayRoundDown === undefined) {
@@ -213,22 +213,21 @@ function initializeNumberDisplayRoundDown() {
});
}
function initializeColorTheme() {
getBrowser().storage.sync.get(['colorTheme'], (res) => {
getBrowser().storage.sync.get(["colorTheme"], (res) => {
if (res.colorTheme === undefined) {
getBrowser().storage.sync.set({colorTheme: false});
}
else {
getBrowser().storage.sync.set({ colorTheme: false });
} else {
extConfig.colorTheme = res.colorTheme;
}
}
});
}
function initializeNumberDisplayFormat() {
getBrowser().storage.sync.get(['numberDisplayFormat'], (res) => {
getBrowser().storage.sync.get(["numberDisplayFormat"], (res) => {
if (res.numberDisplayFormat === undefined) {
getBrowser().storage.sync.set({ numberDisplayFormat: 'compactShort' });
}
else {
getBrowser().storage.sync.set({ numberDisplayFormat: "compactShort" });
} else {
extConfig.numberDisplayFormat = res.numberDisplayFormat;
}
});
+40 -34
View File
@@ -1,6 +1,4 @@
import {
extConfig,
} from "./state";
import { extConfig } from "./state";
function roundDown(num) {
if (num < 1000) return num;
@@ -19,35 +17,37 @@ function numberFormat(numberState) {
?.getAttribute("href")
)?.searchParams?.get("locale");
} catch {}
let numberDisplay;
if (extConfig.numberDisplayRoundDown === false) {
numberDisplay = numberState;
} else {
numberDisplay = roundDown(numberState);
}
return getNumberFormatter(extConfig.numberDisplayFormat).format(numberDisplay);
return getNumberFormatter(extConfig.numberDisplayFormat).format(
numberDisplay
);
}
function getNumberFormatter(optionSelect) {
let formatterNotation;
let formatterCompactDisplay;
switch(optionSelect) {
case 'compactLong':
formatterNotation = 'compact';
formatterCompactDisplay = 'long';
switch (optionSelect) {
case "compactLong":
formatterNotation = "compact";
formatterCompactDisplay = "long";
break;
case 'standard':
formatterNotation = 'standard';
formatterCompactDisplay = 'short';
case "standard":
formatterNotation = "standard";
formatterCompactDisplay = "short";
break;
case 'compactShort':
case "compactShort":
default:
formatterNotation = 'compact';
formatterCompactDisplay = 'short';
formatterNotation = "compact";
formatterCompactDisplay = "short";
}
const formatter = Intl.NumberFormat(
document.documentElement.lang || userLocales || navigator.language,
{
@@ -90,10 +90,10 @@ function isInViewport(element) {
const height = innerHeight || document.documentElement.clientHeight;
const width = innerWidth || document.documentElement.clientWidth;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= height &&
rect.right <= width
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= height &&
rect.right <= width
);
}
@@ -115,30 +115,29 @@ function cLog(message, writer) {
}
}
function getColorFromTheme(voteIsLike) {
let colorString;
switch(extConfig.colorTheme) {
case 'accessible':
switch (extConfig.colorTheme) {
case "accessible":
if (voteIsLike === true) {
colorString = 'dodgerblue';
colorString = "dodgerblue";
} else {
colorString = 'gold';
colorString = "gold";
}
break;
case 'neon':
case "neon":
if (voteIsLike === true) {
colorString = 'aqua';
colorString = "aqua";
} else {
colorString = 'magenta';
colorString = "magenta";
}
break;
case 'classic':
case "classic":
default:
if (voteIsLike === true) {
colorString = 'lime';
colorString = "lime";
} else {
colorString = 'red';
colorString = "red";
}
}
return colorString;
@@ -151,5 +150,12 @@ export {
isVideoLoaded,
cLog,
getColorFromTheme,
}
export { numberFormat, getBrowser, getVideoId, isInViewport, isVideoLoaded, cLog }
};
export {
numberFormat,
getBrowser,
getVideoId,
isInViewport,
isVideoLoaded,
cLog,
};