Merge pull request #771 from ErykDarnowski/fix-like-dislike-bar-offset

Fix like/dislike ratio bar offset
This commit is contained in:
Dmitrii Selivanov authored and GitHub committed 2022-11-10 15:10:12 +01:00
commit e971c0da50
2 files changed
+21 -10

No files matched your search

+12 -4
View File
@@ -1,9 +1,10 @@
import { getButtons, getDislikeButton, getLikeButton } from './buttons'; import { getButtons, getDislikeButton, getLikeButton } from "./buttons";
import { import {
extConfig, extConfig,
isMobile, isMobile,
isLikesDisabled, isLikesDisabled,
isNewDesign, isNewDesign,
isRoundedDesign,
isShorts, isShorts,
} from "./state"; } from "./state";
import { cLog, getColorFromTheme } from "./utils"; import { cLog, getColorFromTheme } from "./utils";
@@ -15,7 +16,7 @@ function createRateBar(likes, dislikes) {
const widthPx = const widthPx =
getLikeButton().clientWidth + getLikeButton().clientWidth +
getDislikeButton().clientWidth + getDislikeButton().clientWidth +
8; (isRoundedDesign() ? 0 : 8);
const widthPercent = const widthPercent =
likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50; likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
@@ -78,15 +79,22 @@ function createRateBar(likes, dislikes) {
<!--css-build:shady-->${tooltipInnerHTML} <!--css-build:shady-->${tooltipInnerHTML}
</tp-yt-paper-tooltip> </tp-yt-paper-tooltip>
</div> </div>
` `
); );
// Add border between info and comments
if (isNewDesign()) { if (isNewDesign()) {
// Add border between info and comments
let descriptionAndActionsElement = document.getElementById("top-row"); let descriptionAndActionsElement = document.getElementById("top-row");
descriptionAndActionsElement.style.borderBottom = descriptionAndActionsElement.style.borderBottom =
"1px solid var(--yt-spec-10-percent-layer)"; "1px solid var(--yt-spec-10-percent-layer)";
descriptionAndActionsElement.style.paddingBottom = "10px"; descriptionAndActionsElement.style.paddingBottom = "10px";
// Fix like/dislike ratio bar offset in new UI
document.getElementById("actions-inner").style.width = "revert";
if (isRoundedDesign()) {
document.getElementById("actions").style.flexDirection =
"row-reverse";
}
} }
} else { } else {
document.getElementById("ryd-bar-container").style.width = document.getElementById("ryd-bar-container").style.width =
+9 -6
View File
@@ -51,6 +51,10 @@ function isNewDesign() {
return document.getElementById("comment-teaser") !== null; return document.getElementById("comment-teaser") !== null;
} }
function isRoundedDesign() {
return document.getElementById("segmented-like-button") !== null;
}
let mutationObserver = new Object(); let mutationObserver = new Object();
if (isShorts() && mutationObserver.exists !== true) { if (isShorts() && mutationObserver.exists !== true) {
@@ -96,9 +100,7 @@ function isLikesDisabled() {
getButtons().children[0].querySelector(".button-renderer-text").innerText getButtons().children[0].querySelector(".button-renderer-text").innerText
); );
} }
return /^\D*$/.test( return /^\D*$/.test(getButtons().children[0].innerText);
getButtons().children[0].innerText
);
} }
function isVideoLiked() { function isVideoLiked() {
@@ -139,6 +141,7 @@ function setLikes(likesCount) {
function setDislikes(dislikesCount) { function setDislikes(dislikesCount) {
cLog(`SET dislikes ${dislikesCount}`) cLog(`SET dislikes ${dislikesCount}`)
getDislikeTextContainer()?.removeAttribute("is-empty");
getDislikeTextContainer()?.removeAttribute('is-empty'); getDislikeTextContainer()?.removeAttribute('is-empty');
if (!isLikesDisabled()) { if (!isLikesDisabled()) {
if (isMobile()) { if (isMobile()) {
@@ -167,6 +170,7 @@ function getLikeCountFromButton() {
//It should be possible to fix this function, but it's not critical to showing the dislike count. //It should be possible to fix this function, but it's not critical to showing the dislike count.
return false; return false;
} }
let likeButton = getLikeButton() let likeButton = getLikeButton()
.querySelector("yt-formatted-string#text") ?? .querySelector("yt-formatted-string#text") ??
getLikeButton().querySelector("button"); getLikeButton().querySelector("button");
@@ -174,11 +178,9 @@ function getLikeCountFromButton() {
let likesStr = likeButton.getAttribute("aria-label") let likesStr = likeButton.getAttribute("aria-label")
.replace(/\D/g, ""); .replace(/\D/g, "");
return likesStr.length > 0 ? parseInt(likesStr) : false; return likesStr.length > 0 ? parseInt(likesStr) : false;
} } catch {
catch {
return false; return false;
} }
} }
function processResponse(response, storedData) { function processResponse(response, storedData) {
@@ -366,6 +368,7 @@ export {
isVideoDisliked, isVideoDisliked,
isVideoLiked, isVideoLiked,
isNewDesign, isNewDesign,
isRoundedDesign,
getState, getState,
setState, setState,
setInitialState, setInitialState,