blob: c56ab57a66ffc4b22b184c0bc786a41018c8761e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import { getButtons } from "./buttons";
import { extConfig, isMobile, isLikesDisabled } from "./state";
import { cLog, getColorFromTheme } from "./utils";
function createRateBar(likes, dislikes) {
if (!isLikesDisabled()) {
let rateBar = document.getElementById("ryd-bar-container");
const widthPx =
getButtons().children[0].clientWidth +
getButtons().children[1].clientWidth +
8;
const widthPercent =
likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
if (!rateBar && !isMobile()) {
let colorLikeStyle = "";
let colorDislikeStyle = "";
if (extConfig.coloredBar) {
colorLikeStyle = "; background-color: " + getColorFromTheme(true);
colorDislikeStyle = "; background-color: " + getColorFromTheme(false);
}
(
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
id="ryd-bar-container"
style="width: 100%; height: 2px;${colorDislikeStyle}"
>
<div
id="ryd-bar"
style="width: ${widthPercent}%; height: 100%${colorLikeStyle}"
></div>
</div>
</div>
<tp-yt-paper-tooltip position="top" id="ryd-dislike-tooltip" class="style-scope ytd-sentiment-bar-renderer" role="tooltip" tabindex="-1">
<!--css-build:shady-->${likes.toLocaleString()} / ${dislikes.toLocaleString()}
</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()} / ${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");
if(ratebar) {
ratebar.parentNode.removeChild(ratebar);
}
}
}
export { createRateBar };
|