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,7 +30,7 @@ let likesvalue = 0;
let dislikesvalue = 0; let dislikesvalue = 0;
let isMobile = location.hostname == "m.youtube.com"; let isMobile = location.hostname == "m.youtube.com";
let isShorts = () => location.pathname.startsWith("/shorts") let isShorts = () => location.pathname.startsWith("/shorts");
let mobileDislikes = 0; let mobileDislikes = 0;
function cLog(text, subtext = "") { function cLog(text, subtext = "") {
subtext = subtext.trim() === "" ? "" : `(${subtext})`; subtext = subtext.trim() === "" ? "" : `(${subtext})`;
@@ -42,18 +42,22 @@ function isInViewport(element) {
const height = innerHeight || document.documentElement.clientHeight; const height = innerHeight || document.documentElement.clientHeight;
const width = innerWidth || document.documentElement.clientWidth; const width = innerWidth || document.documentElement.clientWidth;
return ( return (
rect.top >= 0 && rect.top >= 0 &&
rect.left >= 0 && rect.left >= 0 &&
rect.bottom <= height && rect.bottom <= height &&
rect.right <= width rect.right <= width
); );
} }
function getButtons() { function getButtons() {
if(isShorts()) { if (isShorts()) {
let elements=document.querySelectorAll(isMobile ? "ytm-like-button-renderer" : "#like-button > ytd-like-button-renderer"); let elements = document.querySelectorAll(
for(let element of elements) { isMobile
if(isInViewport(element)) { ? "ytm-like-button-renderer"
: "#like-button > ytd-like-button-renderer"
);
for (let element of elements) {
if (isInViewport(element)) {
return element; return element;
} }
} }
@@ -116,10 +120,10 @@ function checkForUserAvatarButton() {
if (isMobile) { if (isMobile) {
return; return;
} }
if (document.querySelector('#avatar-btn')) { if (document.querySelector("#avatar-btn")) {
return true return true;
} else { } else {
return false return false;
} }
} }
@@ -235,7 +239,6 @@ function createRateBar(likes, dislikes) {
} }
} }
function setState() { function setState() {
cLog("Fetching votes..."); cLog("Fetching votes...");
let statsSet = false; let statsSet = false;
@@ -262,17 +265,17 @@ function likeClicked() {
likesvalue--; likesvalue--;
createRateBar(likesvalue, dislikesvalue); createRateBar(likesvalue, dislikesvalue);
setDislikes(numberFormat(dislikesvalue)); setDislikes(numberFormat(dislikesvalue));
previousState = 3 previousState = 3;
} else if (previousState == 2) { } else if (previousState == 2) {
likesvalue++; likesvalue++;
dislikesvalue--; dislikesvalue--;
setDislikes(numberFormat(dislikesvalue)) setDislikes(numberFormat(dislikesvalue));
createRateBar(likesvalue, dislikesvalue); createRateBar(likesvalue, dislikesvalue);
previousState = 1 previousState = 1;
} else if (previousState == 3) { } else if (previousState == 3) {
likesvalue++; likesvalue++;
createRateBar(likesvalue, dislikesvalue) createRateBar(likesvalue, dislikesvalue);
previousState = 1 previousState = 1;
} }
} }
} }
@@ -283,18 +286,18 @@ function dislikeClicked() {
dislikesvalue++; dislikesvalue++;
setDislikes(numberFormat(dislikesvalue)); setDislikes(numberFormat(dislikesvalue));
createRateBar(likesvalue, dislikesvalue); createRateBar(likesvalue, dislikesvalue);
previousState = 2 previousState = 2;
} else if (previousState == 2) { } else if (previousState == 2) {
dislikesvalue--; dislikesvalue--;
setDislikes(numberFormat(dislikesvalue)); setDislikes(numberFormat(dislikesvalue));
createRateBar(likesvalue, dislikesvalue); createRateBar(likesvalue, dislikesvalue);
previousState = 3 previousState = 3;
} else if (previousState == 1) { } else if (previousState == 1) {
likesvalue--; likesvalue--;
dislikesvalue++; dislikesvalue++;
setDislikes(numberFormat(dislikesvalue)); setDislikes(numberFormat(dislikesvalue));
createRateBar(likesvalue, dislikesvalue); createRateBar(likesvalue, dislikesvalue);
previousState = 2 previousState = 2;
} }
} }
} }
@@ -359,7 +362,7 @@ function setEventListeners(evt) {
function checkForJS_Finish(check) { function checkForJS_Finish(check) {
console.log(); console.log();
if (isShorts() || getButtons()?.offsetParent && isVideoLoaded()) { if (isShorts() || (getButtons()?.offsetParent && isVideoLoaded())) {
const buttons = getButtons(); const buttons = getButtons();
if (!window.returnDislikeButtonlistenersSet) { if (!window.returnDislikeButtonlistenersSet) {
@@ -369,7 +372,9 @@ function setEventListeners(evt) {
buttons.children[1].addEventListener("click", dislikeClicked); buttons.children[1].addEventListener("click", dislikeClicked);
buttons.children[0].addEventListener("touchstart", likeClicked); buttons.children[0].addEventListener("touchstart", likeClicked);
buttons.children[1].addEventListener("touchstart", dislikeClicked); buttons.children[1].addEventListener("touchstart", dislikeClicked);
} catch { return } //Don't spam errors into the console } catch {
return;
} //Don't spam errors into the console
window.returnDislikeButtonlistenersSet = true; window.returnDislikeButtonlistenersSet = true;
} }
setInitialState(); setInitialState();
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "__MSG_extensionName__", "name": "__MSG_extensionName__",
"description": "__MSG_extensionDesc__", "description": "__MSG_extensionDesc__",
"default_locale": "en", "default_locale": "en",
"version": "2.1.0.4", "version": "2.1.0.3",
"manifest_version": 3, "manifest_version": 3,
"background": { "background": {
"service_worker": "ryd.background.js" "service_worker": "ryd.background.js"
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "__MSG_extensionName__", "name": "__MSG_extensionName__",
"description": "__MSG_extensionDesc__", "description": "__MSG_extensionDesc__",
"default_locale": "en", "default_locale": "en",
"version": "2.1.0.4", "version": "2.1.0.3",
"manifest_version": 2, "manifest_version": 2,
"background": { "background": {
"scripts": ["ryd.background.js"] "scripts": ["ryd.background.js"]
+6 -6
View File
@@ -43,7 +43,7 @@ button:hover {
} }
#ext-version { #ext-version {
padding: .25rem .5rem; padding: 0.25rem 0.5rem;
} }
#ext-update { #ext-update {
@@ -51,21 +51,21 @@ button:hover {
color: var(--white); color: var(--white);
text-decoration: none; text-decoration: none;
background: var(--primary); background: var(--primary);
border-radius: .25rem; border-radius: 0.25rem;
} }
#ext-update:hover { #ext-update:hover {
text-decoration: underline; text-decoration: underline;
} }
#ext { #ext {
padding: .25rem 0; padding: 0.25rem 0;
z-index: 69; z-index: 69;
position: fixed; position: fixed;
background: var(--secondary); background: var(--secondary);
margin: 0; margin: 0;
bottom: 1.15rem; bottom: 1.15rem;
right: 1.15rem; right: 1.15rem;
border-radius: .25rem; border-radius: 0.25rem;
} }
.switch:before { .switch:before {
@@ -73,8 +73,8 @@ button:hover {
visibility: hidden; visibility: hidden;
width: 250px; width: 250px;
background-color: var(--secondary); background-color: var(--secondary);
border-radius: .5rem; border-radius: 0.5rem;
padding: .5rem; padding: 0.5rem;
position: absolute; position: absolute;
z-index: 1; z-index: 1;
+35 -11
View File
@@ -20,16 +20,32 @@
/> />
<path d="m8 12.5 5.1-2.9L8 6.7v5.8z" fill="#fff" /> <path d="m8 12.5 5.1-2.9L8 6.7v5.8z" fill="#fff" />
</svg> </svg>
<h1 style="margin-bottom: 0.75rem" title="__MSG_extensionName__">__MSG_extensionName__</h1> <h1 style="margin-bottom: 0.75rem" title="__MSG_extensionName__">
<p style="color: var(--lightGrey)" title="__MSG_textDeveloper__">__MSG_textDeveloper__</p> __MSG_extensionName__
</h1>
<p style="color: var(--lightGrey)" title="__MSG_textDeveloper__">
__MSG_textDeveloper__
</p>
<button id="link_website" title="__MSG_linkWebsite__">__MSG_linkWebsite__</button> <button id="link_website" title="__MSG_linkWebsite__">
<button id="link_github" >GitHub</button> __MSG_linkWebsite__
</button>
<button id="link_github">GitHub</button>
<button id="link_discord">Discord</button> <button id="link_discord">Discord</button>
<br /> <br />
<button style="margin-top: 0.3rem" id="link_faq" title="__MSG_linkFAQ__">__MSG_linkFAQ__</button> <button style="margin-top: 0.3rem" id="link_faq" title="__MSG_linkFAQ__">
<button style="margin-top: 0.3em" id="link_donate" title="__MSG_linkDonate__">__MSG_linkDonate__</button> __MSG_linkFAQ__
<button style="margin-top: 0.3em" id="link_help" title="__MSG_linkHelp__">__MSG_linkHelp__</button> </button>
<button
style="margin-top: 0.3em"
id="link_donate"
title="__MSG_linkDonate__"
>
__MSG_linkDonate__
</button>
<button style="margin-top: 0.3em" id="link_help" title="__MSG_linkHelp__">
__MSG_linkHelp__
</button>
<br /> <br />
<br /> <br />
@@ -64,18 +80,26 @@
<!-- bottom-right --> <!-- bottom-right -->
<div id="ext"> <div id="ext">
<a href="https://returnyoutubedislike.com/install" target="_blank" id="ext-update"></a> <a
href="https://returnyoutubedislike.com/install"
target="_blank"
id="ext-update"
></a>
<span id="ext-version"></span> <span id="ext-version"></span>
</div> </div>
<!-- dialog box --> <!-- dialog box -->
<fieldset id="advancedSettings"> <fieldset id="advancedSettings">
<legend id="advancedLegend" title="__MSG_legendSettings__">__MSG_legendSettings__</legend> <legend id="advancedLegend" title="__MSG_legendSettings__">
__MSG_legendSettings__
</legend>
<label class="switch" data-hover="__MSG_textSettingsHover__"> <label class="switch" data-hover="__MSG_textSettingsHover__">
<input type="checkbox" id="disable_vote_submission" /> <input type="checkbox" id="disable_vote_submission" />
<span class="slider" /> <span class="slider" />
<span class="switchLabel" title="__MSG_textSettings__">__MSG_textSettings__</span> <span class="switchLabel" title="__MSG_textSettings__"
>__MSG_textSettings__</span
>
</label> </label>
<br /> <br />
<label class="switch" data-hover="Use custom colors in new pages."> <label class="switch" data-hover="Use custom colors in new pages.">
@@ -119,7 +143,7 @@
<span id="color_theme_example_like" style="display: inline-block; vertical-align: text-top; width: 1em; height: 1em;">&nbsp;</span> <span id="color_theme_example_like" style="display: inline-block; vertical-align: text-top; width: 1em; height: 1em;">&nbsp;</span>
<span id="color_theme_example_dislike" style="display: inline-block; vertical-align: text-top; width: 1em; height: 1em;">&nbsp;</span> <span id="color_theme_example_dislike" style="display: inline-block; vertical-align: text-top; width: 1em; height: 1em;">&nbsp;</span>
</div> </div>
<!-- <br /> <!-- <br />
<label class="switch"> <label class="switch">
<input type="checkbox" id="star_ratio" /> <input type="checkbox" id="star_ratio" />
+78 -92
View File
@@ -5,10 +5,12 @@ const config = {
coloredThumbs: false, coloredThumbs: false,
coloredBar: false, coloredBar: false,
colorTheme: "classic", colorTheme: "classic",
numberDisplayFormat: 'compactShort', numberDisplayFormat: "compactShort",
numberDisplayRoundDown: true, numberDisplayRoundDown: true,
showAdvancedMessage: '<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor"><rect fill="none" height="24" width="24"/><path d="M19.5,12c0-0.23-0.01-0.45-0.03-0.68l1.86-1.41c0.4-0.3,0.51-0.86,0.26-1.3l-1.87-3.23c-0.25-0.44-0.79-0.62-1.25-0.42 l-2.15,0.91c-0.37-0.26-0.76-0.49-1.17-0.68l-0.29-2.31C14.8,2.38,14.37,2,13.87,2h-3.73C9.63,2,9.2,2.38,9.14,2.88L8.85,5.19 c-0.41,0.19-0.8,0.42-1.17,0.68L5.53,4.96c-0.46-0.2-1-0.02-1.25,0.42L2.41,8.62c-0.25,0.44-0.14,0.99,0.26,1.3l1.86,1.41 C4.51,11.55,4.5,11.77,4.5,12s0.01,0.45,0.03,0.68l-1.86,1.41c-0.4,0.3-0.51,0.86-0.26,1.3l1.87,3.23c0.25,0.44,0.79,0.62,1.25,0.42 l2.15-0.91c0.37,0.26,0.76,0.49,1.17,0.68l0.29,2.31C9.2,21.62,9.63,22,10.13,22h3.73c0.5,0,0.93-0.38,0.99-0.88l0.29-2.31 c0.41-0.19,0.8-0.42,1.17-0.68l2.15,0.91c0.46,0.2,1,0.02,1.25-0.42l1.87-3.23c0.25-0.44,0.14-0.99-0.26-1.3l-1.86-1.41 C19.49,12.45,19.5,12.23,19.5,12z M12.04,15.5c-1.93,0-3.5-1.57-3.5-3.5s1.57-3.5,3.5-3.5s3.5,1.57,3.5,3.5S13.97,15.5,12.04,15.5z"/></svg>', showAdvancedMessage:
hideAdvancedMessage: '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor"><path d="M0 0h24v24H0V0z" fill="none" opacity=".87"/><path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm4.3 14.3c-.39.39-1.02.39-1.41 0L12 13.41 9.11 16.3c-.39.39-1.02.39-1.41 0-.39-.39-.39-1.02 0-1.41L10.59 12 7.7 9.11c-.39-.39-.39-1.02 0-1.41.39-.39 1.02-.39 1.41 0L12 10.59l2.89-2.89c.39-.39 1.02-.39 1.41 0 .39.39.39 1.02 0 1.41L13.41 12l2.89 2.89c.38.38.38 1.02 0 1.41z"/></svg>', '<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor"><rect fill="none" height="24" width="24"/><path d="M19.5,12c0-0.23-0.01-0.45-0.03-0.68l1.86-1.41c0.4-0.3,0.51-0.86,0.26-1.3l-1.87-3.23c-0.25-0.44-0.79-0.62-1.25-0.42 l-2.15,0.91c-0.37-0.26-0.76-0.49-1.17-0.68l-0.29-2.31C14.8,2.38,14.37,2,13.87,2h-3.73C9.63,2,9.2,2.38,9.14,2.88L8.85,5.19 c-0.41,0.19-0.8,0.42-1.17,0.68L5.53,4.96c-0.46-0.2-1-0.02-1.25,0.42L2.41,8.62c-0.25,0.44-0.14,0.99,0.26,1.3l1.86,1.41 C4.51,11.55,4.5,11.77,4.5,12s0.01,0.45,0.03,0.68l-1.86,1.41c-0.4,0.3-0.51,0.86-0.26,1.3l1.87,3.23c0.25,0.44,0.79,0.62,1.25,0.42 l2.15-0.91c0.37,0.26,0.76,0.49,1.17,0.68l0.29,2.31C9.2,21.62,9.63,22,10.13,22h3.73c0.5,0,0.93-0.38,0.99-0.88l0.29-2.31 c0.41-0.19,0.8-0.42,1.17-0.68l2.15,0.91c0.46,0.2,1,0.02,1.25-0.42l1.87-3.23c0.25-0.44,0.14-0.99-0.26-1.3l-1.86-1.41 C19.49,12.45,19.5,12.23,19.5,12z M12.04,15.5c-1.93,0-3.5-1.57-3.5-3.5s1.57-3.5,3.5-3.5s3.5,1.57,3.5,3.5S13.97,15.5,12.04,15.5z"/></svg>',
hideAdvancedMessage:
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor"><path d="M0 0h24v24H0V0z" fill="none" opacity=".87"/><path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm4.3 14.3c-.39.39-1.02.39-1.41 0L12 13.41 9.11 16.3c-.39.39-1.02.39-1.41 0-.39-.39-.39-1.02 0-1.41L10.59 12 7.7 9.11c-.39-.39-.39-1.02 0-1.41.39-.39 1.02-.39 1.41 0L12 10.59l2.89-2.89c.39-.39 1.02-.39 1.41 0 .39.39.39 1.02 0 1.41L13.41 12l2.89 2.89c.38.38.38 1.02 0 1.41z"/></svg>',
links: { links: {
website: "https://returnyoutubedislike.com", website: "https://returnyoutubedislike.com",
@@ -16,67 +18,57 @@ const config = {
discord: "https://discord.gg/mYnESY4Md5", discord: "https://discord.gg/mYnESY4Md5",
donate: "https://returnyoutubedislike.com/donate", donate: "https://returnyoutubedislike.com/donate",
faq: "https://returnyoutubedislike.com/faq", faq: "https://returnyoutubedislike.com/faq",
help: "https://returnyoutubedislike.com/help" help: "https://returnyoutubedislike.com/help",
}, },
}; };
/* Change language */ /* Change language */
function localizeHtmlPage() function localizeHtmlPage() {
{ //Localize by replacing __MSG_***__ meta tags
//Localize by replacing __MSG_***__ meta tags var objects = document.getElementsByTagName("html");
var objects = document.getElementsByTagName('html'); for (var j = 0; j < objects.length; j++) {
for (var j = 0; j < objects.length; j++) var obj = objects[j];
{
var obj = objects[j];
var valStrH = obj.innerHTML.toString(); var valStrH = obj.innerHTML.toString();
var valNewH = valStrH.replace(/__MSG_(\w+)__/g, function(match, v1) var valNewH = valStrH.replace(/__MSG_(\w+)__/g, function (match, v1) {
{ return v1 ? chrome.i18n.getMessage(v1) : "";
return v1 ? chrome.i18n.getMessage(v1) : ""; });
});
if(valNewH != valStrH) if (valNewH != valStrH) {
{ obj.innerHTML = valNewH;
obj.innerHTML = valNewH;
}
} }
}
} }
localizeHtmlPage(); localizeHtmlPage();
/* Links */ /* Links */
createLink(config.links.website,"link_website") createLink(config.links.website, "link_website");
createLink(config.links.github,"link_github") createLink(config.links.github, "link_github");
createLink(config.links.discord,"link_discord") createLink(config.links.discord, "link_discord");
createLink(config.links.faq,"link_faq") createLink(config.links.faq, "link_faq");
createLink(config.links.donate,"link_donate") createLink(config.links.donate, "link_donate");
createLink(config.links.help,"link_help") createLink(config.links.help, "link_help");
function createLink(url,id) { function createLink(url, id) {
document.getElementById(id).addEventListener("click",()=>{ document.getElementById(id).addEventListener("click", () => {
chrome.tabs.create({ url: url}) chrome.tabs.create({ url: url });
}) });
} }
document document
.getElementById("disable_vote_submission") .getElementById("disable_vote_submission")
.addEventListener("click", (ev) => { .addEventListener("click", (ev) => {
chrome.storage.sync.set({ disableVoteSubmission: ev.target.checked }); chrome.storage.sync.set({ disableVoteSubmission: ev.target.checked });
}); });
document document.getElementById("colored_thumbs").addEventListener("click", (ev) => {
.getElementById("colored_thumbs") chrome.storage.sync.set({ coloredThumbs: ev.target.checked });
.addEventListener("click", (ev) => { });
chrome.storage.sync.set({ coloredThumbs: ev.target.checked }); document.getElementById("colored_bar").addEventListener("click", (ev) => {
}); chrome.storage.sync.set({ coloredBar: ev.target.checked });
document });
.getElementById("colored_bar") document.getElementById("color_theme").addEventListener("click", (ev) => {
.addEventListener("click", (ev) => { chrome.storage.sync.set({ colorTheme: ev.target.value });
chrome.storage.sync.set({ coloredBar: ev.target.checked }); });
});
document
.getElementById("color_theme")
.addEventListener("click", (ev) => {
chrome.storage.sync.set({ colorTheme: ev.target.value });
});
document.getElementById("number_round_down").addEventListener("click", (ev) => { document.getElementById("number_round_down").addEventListener("click", (ev) => {
chrome.storage.sync.set({ numberDisplayRoundDown: ev.target.checked }); chrome.storage.sync.set({ numberDisplayRoundDown: ev.target.checked });
@@ -120,7 +112,7 @@ function initConfig() {
function initializeVersionNumber() { function initializeVersionNumber() {
const version = chrome.runtime.getManifest().version; const version = chrome.runtime.getManifest().version;
document.getElementById('ext-version').innerHTML = 'v' + version; document.getElementById("ext-version").innerHTML = "v" + version;
fetch( fetch(
"https://raw.githubusercontent.com/Anarios/return-youtube-dislike/main/Extensions/combined/manifest-chrome.json" "https://raw.githubusercontent.com/Anarios/return-youtube-dislike/main/Extensions/combined/manifest-chrome.json"
@@ -128,12 +120,12 @@ function initializeVersionNumber() {
.then((response) => response.json()) .then((response) => response.json())
.then((json) => { .then((json) => {
if (version !== json.version) { if (version !== json.version) {
document.getElementById('ext-update').innerHTML = chrome.i18n.getMessage("textUpdate") +' v' + json.version; document.getElementById("ext-update").innerHTML =
document.getElementById('ext-update').style.padding = '.25rem .5rem'; chrome.i18n.getMessage("textUpdate") + " v" + json.version;
document.getElementById("ext-update").style.padding = ".25rem .5rem";
} }
}); });
// .catch(console.error); // .catch(console.error);
} }
function initializeDisableVoteSubmission() { function initializeDisableVoteSubmission() {
@@ -142,7 +134,6 @@ function initializeDisableVoteSubmission() {
}); });
} }
function initializeColoredThumbs() { function initializeColoredThumbs() {
chrome.storage.sync.get(["coloredThumbs"], (res) => { chrome.storage.sync.get(["coloredThumbs"], (res) => {
handleColoredThumbsChangeEvent(res.coloredThumbs); handleColoredThumbsChangeEvent(res.coloredThumbs);
@@ -159,7 +150,8 @@ function initializeColorTheme() {
chrome.storage.sync.get(["colorTheme"], (res) => { chrome.storage.sync.get(["colorTheme"], (res) => {
handleColorThemeChangeEvent(res.colorTheme); handleColorThemeChangeEvent(res.colorTheme);
}); });
}
function initializeNumberDisplayRoundDown() { function initializeNumberDisplayRoundDown() {
chrome.storage.sync.get(["numberDisplayRoundDown"], (res) => { chrome.storage.sync.get(["numberDisplayRoundDown"], (res) => {
handleNumberDisplayRoundDownChangeEvent(res.numberDisplayRoundDown); handleNumberDisplayRoundDownChangeEvent(res.numberDisplayRoundDown);
@@ -180,12 +172,12 @@ function updateNumberDisplayFormatContent(roundDown) {
} else { } else {
testValue = 123456; testValue = 123456;
} }
document.getElementById('number_format_compactShort').innerHTML = document.getElementById("number_format_compactShort").innerHTML =
getNumberFormatter('compactShort').format(testValue); getNumberFormatter("compactShort").format(testValue);
document.getElementById('number_format_compactLong').innerHTML = document.getElementById("number_format_compactLong").innerHTML =
getNumberFormatter('compactLong').format(testValue); getNumberFormatter("compactLong").format(testValue);
document.getElementById('number_format_standard').innerHTML = document.getElementById("number_format_standard").innerHTML =
getNumberFormatter('standard').format(testValue); getNumberFormatter("standard").format(testValue);
} }
chrome.storage.onChanged.addListener(storageChangeHandler); chrome.storage.onChanged.addListener(storageChangeHandler);
@@ -197,19 +189,14 @@ function storageChangeHandler(changes, area) {
); );
} }
if (changes.coloredThumbs !== undefined) { if (changes.coloredThumbs !== undefined) {
handleColoredThumbsChangeEvent( handleColoredThumbsChangeEvent(changes.coloredThumbs.newValue);
changes.coloredThumbs.newValue
);
} }
if (changes.coloredBar !== undefined) { if (changes.coloredBar !== undefined) {
handleColoredBarChangeEvent( handleColoredBarChangeEvent(changes.coloredBar.newValue);
changes.coloredBar.newValue
);
} }
if (changes.colorTheme !== undefined) { if (changes.colorTheme !== undefined) {
handleColorThemeChangeEvent( handleColorThemeChangeEvent(changes.colorTheme.newValue);
changes.colorTheme.newValue }
);
if (changes.numberDisplayRoundDown !== undefined) { if (changes.numberDisplayRoundDown !== undefined) {
handleNumberDisplayRoundDownChangeEvent( handleNumberDisplayRoundDownChangeEvent(
changes.numberDisplayRoundDown.newValue changes.numberDisplayRoundDown.newValue
@@ -225,7 +212,6 @@ function handleDisableVoteSubmissionChangeEvent(value) {
document.getElementById("disable_vote_submission").checked = value; document.getElementById("disable_vote_submission").checked = value;
} }
function handleColoredThumbsChangeEvent(value) { function handleColoredThumbsChangeEvent(value) {
config.coloredThumbs = value; config.coloredThumbs = value;
document.getElementById("colored_thumbs").checked = value; document.getElementById("colored_thumbs").checked = value;
@@ -245,8 +231,11 @@ function handleColorThemeChangeEvent(value) {
} }
function updateColorThemePreviewContent(themeName) { function updateColorThemePreviewContent(themeName) {
document.getElementById("color_theme_example_like").style.backgroundColor = getColorFromTheme(themeName, true); document.getElementById("color_theme_example_like").style.backgroundColor =
document.getElementById("color_theme_example_dislike").style.backgroundColor = getColorFromTheme(themeName, false); getColorFromTheme(themeName, true);
document.getElementById("color_theme_example_dislike").style.backgroundColor =
getColorFromTheme(themeName, false);
}
function handleNumberDisplayRoundDownChangeEvent(value) { function handleNumberDisplayRoundDownChangeEvent(value) {
config.numberDisplayRoundDown = value; config.numberDisplayRoundDown = value;
document.getElementById("number_round_down").checked = value; document.getElementById("number_round_down").checked = value;
@@ -262,20 +251,20 @@ function handleNumberDisplayFormatChangeEvent(value) {
function getNumberFormatter(optionSelect) { function getNumberFormatter(optionSelect) {
let formatterNotation; let formatterNotation;
let formatterCompactDisplay; let formatterCompactDisplay;
switch (optionSelect) { switch (optionSelect) {
case 'compactLong': case "compactLong":
formatterNotation = 'compact'; formatterNotation = "compact";
formatterCompactDisplay = 'long'; formatterCompactDisplay = "long";
break; break;
case 'standard': case "standard":
formatterNotation = 'standard'; formatterNotation = "standard";
formatterCompactDisplay = 'short'; formatterCompactDisplay = "short";
break; break;
case 'compactShort': case "compactShort":
default: default:
formatterNotation = 'compact'; formatterNotation = "compact";
formatterCompactDisplay = 'short'; formatterCompactDisplay = "short";
} }
const formatter = Intl.NumberFormat( const formatter = Intl.NumberFormat(
document.documentElement.lang || userLocales || navigator.language, document.documentElement.lang || userLocales || navigator.language,
@@ -307,37 +296,34 @@ function getNumberFormatter(optionSelect) {
} }
})(); })();
function getColorFromTheme(colorTheme, voteIsLike) { function getColorFromTheme(colorTheme, voteIsLike) {
let colorString; let colorString;
switch(colorTheme) { switch (colorTheme) {
case 'accessible': case "accessible":
if (voteIsLike === true) { if (voteIsLike === true) {
colorString = 'dodgerblue'; colorString = "dodgerblue";
} else { } else {
colorString = 'gold'; colorString = "gold";
} }
break; break;
case 'neon': case "neon":
if (voteIsLike === true) { if (voteIsLike === true) {
colorString = 'aqua'; colorString = "aqua";
} else { } else {
colorString = 'magenta'; colorString = "magenta";
} }
break; break;
case 'classic': case "classic":
default: default:
if (voteIsLike === true) { if (voteIsLike === true) {
colorString = 'lime'; colorString = "lime";
} else { } else {
colorString = 'red'; colorString = "red";
} }
} }
return colorString; return colorString;
} }
/* popup-script.js /* popup-script.js
document.querySelector('#login') document.querySelector('#login')
.addEventListener('click', function () { .addEventListener('click', function () {
+3
View File
@@ -1,7 +1,9 @@
# Extension Source # Extension Source
## Guide to Compiling ## Guide to Compiling
## Compiling to Development (Testing) ## Compiling to Development (Testing)
<ol> <ol>
<li>Go to the root directory of the project</li> <li>Go to the root directory of the project</li>
<li>Run <code>npm i</code> to install all project dependancies (if not done so already)</li> <li>Run <code>npm i</code> to install all project dependancies (if not done so already)</li>
@@ -9,6 +11,7 @@
</ol> </ol>
## Compiling to Production (Final Release) ## Compiling to Production (Final Release)
<ol> <ol>
<li>Go to the root directory of the project</li> <li>Go to the root directory of the project</li>
<li>Run <code>npm i</code> to install all project dependancies (if not done so already)</li> <li>Run <code>npm i</code> to install all project dependancies (if not done so already)</li>
+39 -34
View File
@@ -1,6 +1,6 @@
const apiUrl = "https://returnyoutubedislikeapi.com"; const apiUrl = "https://returnyoutubedislikeapi.com";
const voteDisabledIconName = 'icon_hold128.png'; const voteDisabledIconName = "icon_hold128.png";
const defaultIconName = 'icon128.png'; const defaultIconName = "icon128.png";
let api; let api;
/** stores extension's global config */ /** stores extension's global config */
@@ -11,14 +11,14 @@ let extConfig = {
colorTheme: "classic", // classic, accessible, neon colorTheme: "classic", // classic, accessible, neon
// coloredThumbs: false, // coloredThumbs: false,
// coloredBar: false, // coloredBar: false,
numberDisplayFormat: 'compactShort', // compactShort, compactLong, standard numberDisplayFormat: "compactShort", // compactShort, compactLong, standard
numberDisplayRoundDown: true, // locale 'de' shows exact numbers by default numberDisplayRoundDown: true, // locale 'de' shows exact numbers by default
}; };
if (isChrome()) api = chrome; if (isChrome()) api = chrome;
else if (isFirefox()) api = browser; else if (isFirefox()) api = browser;
initExtConfig() initExtConfig();
api.runtime.onMessage.addListener((request, sender, sendResponse) => { api.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.message === "get_auth_token") { if (request.message === "get_auth_token") {
@@ -97,7 +97,7 @@ async function sendVote(videoId, vote) {
await sendVote(videoId, vote); await sendVote(videoId, vote);
return; return;
} }
return response.json() return response.json();
}) })
.then((response) => { .then((response) => {
solvePuzzle(response).then((solvedPuzzle) => { solvePuzzle(response).then((solvedPuzzle) => {
@@ -238,7 +238,9 @@ function generateUserID(length = 36) {
function storageChangeHandler(changes, area) { function storageChangeHandler(changes, area) {
if (changes.disableVoteSubmission !== undefined) { if (changes.disableVoteSubmission !== undefined) {
handleDisableVoteSubmissionChangeEvent(changes.disableVoteSubmission.newValue); handleDisableVoteSubmissionChangeEvent(
changes.disableVoteSubmission.newValue
);
} }
if (changes.coloredThumbs !== undefined) { if (changes.coloredThumbs !== undefined) {
handleColoredThumbsChangeEvent(changes.coloredThumbs.newValue); handleColoredThumbsChangeEvent(changes.coloredThumbs.newValue);
@@ -248,10 +250,11 @@ function storageChangeHandler(changes, area) {
} }
if (changes.colorTheme !== undefined) { if (changes.colorTheme !== undefined) {
handleColorThemeChangeEvent(changes.colorTheme.newValue); handleColorThemeChangeEvent(changes.colorTheme.newValue);
}
if (changes.numberDisplayRoundDown !== undefined) { if (changes.numberDisplayRoundDown !== undefined) {
handleNumberDisplayRoundDownChangeEvent( handleNumberDisplayRoundDownChangeEvent(
changes.numberDisplayRoundDown.newValue changes.numberDisplayRoundDown.newValue
); );
} }
if (changes.numberDisplayFormat !== undefined) { if (changes.numberDisplayFormat !== undefined) {
handleNumberDisplayFormatChangeEvent(changes.numberDisplayFormat.newValue); handleNumberDisplayFormatChangeEvent(changes.numberDisplayFormat.newValue);
@@ -276,9 +279,11 @@ function handleNumberDisplayRoundDownChangeEvent(value) {
} }
function changeIcon(iconName) { function changeIcon(iconName) {
if (api.action !== undefined) api.action.setIcon({path: "/icons/" + iconName}); if (api.action !== undefined)
else if (api.browserAction !== undefined) api.browserAction.setIcon({path: "/icons/" + iconName}); api.action.setIcon({ path: "/icons/" + iconName });
else console.log('changing icon is not supported'); else if (api.browserAction !== undefined)
api.browserAction.setIcon({ path: "/icons/" + iconName });
else console.log("changing icon is not supported");
} }
function handleColoredThumbsChangeEvent(value) { function handleColoredThumbsChangeEvent(value) {
@@ -305,61 +310,59 @@ function initExtConfig() {
} }
function initializeDisableVoteSubmission() { function initializeDisableVoteSubmission() {
api.storage.sync.get(['disableVoteSubmission'], (res) => { api.storage.sync.get(["disableVoteSubmission"], (res) => {
if (res.disableVoteSubmission === undefined) { if (res.disableVoteSubmission === undefined) {
api.storage.sync.set({disableVoteSubmission: false}); api.storage.sync.set({ disableVoteSubmission: false });
} } else {
else {
extConfig.disableVoteSubmission = res.disableVoteSubmission; extConfig.disableVoteSubmission = res.disableVoteSubmission;
if (res.disableVoteSubmission) changeIcon(voteDisabledIconName); if (res.disableVoteSubmission) changeIcon(voteDisabledIconName);
} }
}); });
} }
function initializeColoredThumbs() { function initializeColoredThumbs() {
api.storage.sync.get(['coloredThumbs'], (res) => { api.storage.sync.get(["coloredThumbs"], (res) => {
if (res.coloredThumbs === undefined) { if (res.coloredThumbs === undefined) {
api.storage.sync.set({coloredThumbs: false}); api.storage.sync.set({ coloredThumbs: false });
} } else {
else {
extConfig.coloredThumbs = res.coloredThumbs; extConfig.coloredThumbs = res.coloredThumbs;
} }
});
}
function initializeNumberDisplayRoundDown() { function initializeNumberDisplayRoundDown() {
api.storage.sync.get(['numberDisplayRoundDown'], (res) => { api.storage.sync.get(["numberDisplayRoundDown"], (res) => {
if (res.numberDisplayRoundDown === undefined) { if (res.numberDisplayRoundDown === undefined) {
api.storage.sync.set({numberDisplayRoundDown: true}); api.storage.sync.set({ numberDisplayRoundDown: true });
} else { } else {
extConfig.numberDisplayRoundDown = res.numberDisplayRoundDown; extConfig.numberDisplayRoundDown = res.numberDisplayRoundDown;
} }
}); });
} }
function initializeColoredBar() { function initializeColoredBar() {
api.storage.sync.get(['coloredBar'], (res) => { api.storage.sync.get(["coloredBar"], (res) => {
if (res.coloredBar === undefined) { if (res.coloredBar === undefined) {
api.storage.sync.set({coloredBar: false}); api.storage.sync.set({ coloredBar: false });
} } else {
else {
extConfig.coloredBar = res.coloredBar; extConfig.coloredBar = res.coloredBar;
} }
}); });
} }
function initializeColorTheme() { function initializeColorTheme() {
api.storage.sync.get(['colorTheme'], (res) => { api.storage.sync.get(["colorTheme"], (res) => {
if (res.colorTheme === undefined) { if (res.colorTheme === undefined) {
api.storage.sync.set({colorTheme: false}); api.storage.sync.set({ colorTheme: false });
} } else {
else {
extConfig.colorTheme = res.colorTheme; extConfig.colorTheme = res.colorTheme;
} }
});
}
function initializeNumberDisplayFormat() { function initializeNumberDisplayFormat() {
api.storage.sync.get(['numberDisplayFormat'], (res) => { api.storage.sync.get(["numberDisplayFormat"], (res) => {
if (res.numberDisplayFormat === undefined) { if (res.numberDisplayFormat === undefined) {
api.storage.sync.set({ numberDisplayFormat: 'compactShort' }); api.storage.sync.set({ numberDisplayFormat: "compactShort" });
} else { } else {
extConfig.numberDisplayFormat = res.numberDisplayFormat; extConfig.numberDisplayFormat = res.numberDisplayFormat;
} }
@@ -371,5 +374,7 @@ function isChrome() {
} }
function isFirefox() { function isFirefox() {
return typeof browser !== "undefined" && typeof browser.runtime !== "undefined"; return (
typeof browser !== "undefined" && typeof browser.runtime !== "undefined"
);
} }
+17 -5
View File
@@ -25,18 +25,30 @@ import {
} from "./src/state"; } from "./src/state";
//--- Import Video & Browser Functions ---// //--- Import Video & Browser Functions ---//
import { numberFormat, getBrowser, getVideoId, isVideoLoaded, cLog } from "./src/utils"; import {
numberFormat,
getBrowser,
getVideoId,
isVideoLoaded,
cLog,
} from "./src/utils";
import { createRateBar } from "./src/bar"; import { createRateBar } from "./src/bar";
import { sendVideoIds, sendVote, likeClicked, dislikeClicked, addLikeDislikeEventListener, storageChangeHandler } from "./src/events" import {
sendVideoIds,
sendVote,
likeClicked,
dislikeClicked,
addLikeDislikeEventListener,
storageChangeHandler,
} from "./src/events";
initExtConfig();
initExtConfig()
let jsInitChecktimer = null; let jsInitChecktimer = null;
function setEventListeners(evt) { function setEventListeners(evt) {
function checkForJS_Finish() { function checkForJS_Finish() {
if (isShorts() || getButtons()?.offsetParent && isVideoLoaded()) { if (isShorts() || (getButtons()?.offsetParent && isVideoLoaded())) {
addLikeDislikeEventListener(); addLikeDislikeEventListener();
setInitialState(); setInitialState();
getBrowser().storage.onChanged.addListener(storageChangeHandler); getBrowser().storage.onChanged.addListener(storageChangeHandler);
+30 -30
View File
@@ -1,9 +1,6 @@
import { getButtons } from "./buttons"; import { getButtons } from "./buttons";
import { likesDisabledState, extConfig } from "./state"; import { likesDisabledState, extConfig } from "./state";
import { import { cLog, getColorFromTheme } from "./utils";
cLog,
getColorFromTheme,
} from "./utils";
import { isMobile, likesDisabledState } from "./state"; import { isMobile, likesDisabledState } from "./state";
import { cLog } from "./utils"; import { cLog } from "./utils";
function createRateBar(likes, dislikes) { function createRateBar(likes, dislikes) {
@@ -18,22 +15,21 @@ function createRateBar(likes, dislikes) {
const widthPercent = const widthPercent =
likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50; likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
if (!rateBar) { if (!rateBar) {
let colorLikeStyle = ''; let colorLikeStyle = "";
let colorDislikeStyle = ''; let colorDislikeStyle = "";
if (extConfig.coloredBar) { if (extConfig.coloredBar) {
colorLikeStyle = '; background-color: ' + getColorFromTheme(true); colorLikeStyle = "; background-color: " + getColorFromTheme(true);
colorDislikeStyle = '; background-color: ' + getColorFromTheme(false); colorDislikeStyle = "; background-color: " + getColorFromTheme(false);
} }
if (!rateBar && !isMobile()) { if (!rateBar && !isMobile()) {
( (
document.getElementById("menu-container") || document.getElementById("menu-container") ||
document.querySelector("ytm-slim-video-action-bar-renderer") document.querySelector("ytm-slim-video-action-bar-renderer")
).insertAdjacentHTML( ).insertAdjacentHTML(
"beforeend", "beforeend",
` `
<div class="ryd-tooltip" style="width: ${widthPx}px"> <div class="ryd-tooltip" style="width: ${widthPx}px">
<div class="ryd-tooltip-bar-container"> <div class="ryd-tooltip-bar-container">
<div <div
@@ -51,22 +47,26 @@ function createRateBar(likes, dislikes) {
</tp-yt-paper-tooltip> </tp-yt-paper-tooltip>
</div> </div>
` `
); );
} else { } else {
document.getElementById("ryd-bar-container").style.width = widthPx + "px"; document.getElementById("ryd-bar-container").style.width =
document.getElementById("ryd-bar").style.width = widthPercent + "%"; widthPx + "px";
document.querySelector( document.getElementById("ryd-bar").style.width = widthPercent + "%";
"#ryd-dislike-tooltip > #tooltip" document.querySelector(
).innerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}`; "#ryd-dislike-tooltip > #tooltip"
if (extConfig.coloredBar) { ).innerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}`;
document.getElementById("ryd-bar-container").style.backgroundColor = getColorFromTheme(false); if (extConfig.coloredBar) {
document.getElementById("ryd-bar").style.backgroundColor = getColorFromTheme(true); 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() { function getButtons() {
//--- If Watching Youtube Shorts: ---// //--- If Watching Youtube Shorts: ---//
if(isShorts()) { if (isShorts()) {
let elements=document.querySelectorAll(isMobile() ? "ytm-like-button-renderer" : "#like-button > ytd-like-button-renderer"); let elements = document.querySelectorAll(
for(let element of elements) { 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 //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) //However, only one of them should be visible (no matter how you zoom)
if(isInViewport(element)) { if (isInViewport(element)) {
return element; return element;
} }
} }
+7 -11
View File
@@ -111,20 +111,17 @@ function storageChangeHandler(changes, area) {
handleDisableVoteSubmissionChangeEvent( handleDisableVoteSubmissionChangeEvent(
changes.disableVoteSubmission.newValue changes.disableVoteSubmission.newValue
); );
}
if (changes.coloredThumbs !== undefined) { if (changes.coloredThumbs !== undefined) {
handleColoredThumbsChangeEvent( handleColoredThumbsChangeEvent(changes.coloredThumbs.newValue);
changes.coloredThumbs.newValue
);
} }
if (changes.coloredBar !== undefined) { if (changes.coloredBar !== undefined) {
handleColoredBarChangeEvent( handleColoredBarChangeEvent(changes.coloredBar.newValue);
changes.coloredBar.newValue
);
} }
if (changes.colorTheme !== undefined) { if (changes.colorTheme !== undefined) {
handleColorThemeChangeEvent( handleColorThemeChangeEvent(changes.colorTheme.newValue);
changes.colorTheme.newValue }
);
if (changes.numberDisplayRoundDown !== undefined) { if (changes.numberDisplayRoundDown !== undefined) {
handleNumberDisplayRoundDownChangeEvent( handleNumberDisplayRoundDownChangeEvent(
changes.numberDisplayRoundDown.newValue changes.numberDisplayRoundDown.newValue
@@ -139,7 +136,6 @@ function handleDisableVoteSubmissionChangeEvent(value) {
extConfig.disableVoteSubmission = value; extConfig.disableVoteSubmission = value;
} }
function handleColoredThumbsChangeEvent(value) { function handleColoredThumbsChangeEvent(value) {
extConfig.coloredThumbs = value; extConfig.coloredThumbs = value;
} }
@@ -151,7 +147,7 @@ function handleColoredBarChangeEvent(value) {
function handleColorThemeChangeEvent(value) { function handleColorThemeChangeEvent(value) {
extConfig.colorTheme = value; extConfig.colorTheme = value;
} }
function handleNumberDisplayFormatChangeEvent(value) { function handleNumberDisplayFormatChangeEvent(value) {
extConfig.numberDisplayFormat = value; extConfig.numberDisplayFormat = value;
} }
+22 -23
View File
@@ -1,6 +1,6 @@
import { getLikeButton, getDislikeButton, getButtons } from "./buttons"; import { getLikeButton, getDislikeButton, getButtons } from "./buttons";
import { createRateBar } from "./bar"; import { createRateBar } from "./bar";
import { import {
getBrowser, getBrowser,
getVideoId, getVideoId,
cLog, cLog,
@@ -22,7 +22,7 @@ let extConfig = {
coloredThumbs: false, coloredThumbs: false,
coloredBar: false, coloredBar: false,
colorTheme: "classic", colorTheme: "classic",
numberDisplayFormat: 'compactShort', numberDisplayFormat: "compactShort",
numberDisplayRoundDown: true, numberDisplayRoundDown: true,
}; };
@@ -39,7 +39,7 @@ function isMobile() {
} }
function isShorts() { function isShorts() {
return location.pathname.startsWith("/shorts") return location.pathname.startsWith("/shorts");
} }
function isVideoLiked() { function isVideoLiked() {
@@ -100,7 +100,7 @@ function setDislikes(dislikesCount) {
} }
function getLikeCountFromButton() { 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. //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. //It should be possible to fix this function, but it's not critical to showing the dislike count.
return 0; return 0;
@@ -183,26 +183,26 @@ function initializeDisableVoteSubmission() {
}); });
} }
function initializeColoredThumbs() { function initializeColoredThumbs() {
getBrowser().storage.sync.get(['coloredThumbs'], (res) => { getBrowser().storage.sync.get(["coloredThumbs"], (res) => {
if (res.coloredThumbs === undefined) { if (res.coloredThumbs === undefined) {
getBrowser().storage.sync.set({coloredThumbs: false}); getBrowser().storage.sync.set({ coloredThumbs: false });
} } else {
else {
extConfig.coloredThumbs = res.coloredThumbs; extConfig.coloredThumbs = res.coloredThumbs;
} }
}); });
} }
function initializeColoredBar() { function initializeColoredBar() {
getBrowser().storage.sync.get(['coloredBar'], (res) => { getBrowser().storage.sync.get(["coloredBar"], (res) => {
if (res.coloredBar === undefined) { if (res.coloredBar === undefined) {
getBrowser().storage.sync.set({coloredBar: false}); getBrowser().storage.sync.set({ coloredBar: false });
} } else {
else {
extConfig.coloredBar = res.coloredBar; extConfig.coloredBar = res.coloredBar;
} }
});
}
function initializeNumberDisplayRoundDown() { function initializeNumberDisplayRoundDown() {
getBrowser().storage.sync.get(["numberDisplayRoundDown"], (res) => { getBrowser().storage.sync.get(["numberDisplayRoundDown"], (res) => {
if (res.numberDisplayRoundDown === undefined) { if (res.numberDisplayRoundDown === undefined) {
@@ -213,22 +213,21 @@ function initializeNumberDisplayRoundDown() {
}); });
} }
function initializeColorTheme() { function initializeColorTheme() {
getBrowser().storage.sync.get(['colorTheme'], (res) => { getBrowser().storage.sync.get(["colorTheme"], (res) => {
if (res.colorTheme === undefined) { if (res.colorTheme === undefined) {
getBrowser().storage.sync.set({colorTheme: false}); getBrowser().storage.sync.set({ colorTheme: false });
} } else {
else {
extConfig.colorTheme = res.colorTheme; extConfig.colorTheme = res.colorTheme;
} }
} });
}
function initializeNumberDisplayFormat() { function initializeNumberDisplayFormat() {
getBrowser().storage.sync.get(['numberDisplayFormat'], (res) => { getBrowser().storage.sync.get(["numberDisplayFormat"], (res) => {
if (res.numberDisplayFormat === undefined) { if (res.numberDisplayFormat === undefined) {
getBrowser().storage.sync.set({ numberDisplayFormat: 'compactShort' }); getBrowser().storage.sync.set({ numberDisplayFormat: "compactShort" });
} } else {
else {
extConfig.numberDisplayFormat = res.numberDisplayFormat; extConfig.numberDisplayFormat = res.numberDisplayFormat;
} }
}); });
+40 -34
View File
@@ -1,6 +1,4 @@
import { import { extConfig } from "./state";
extConfig,
} from "./state";
function roundDown(num) { function roundDown(num) {
if (num < 1000) return num; if (num < 1000) return num;
@@ -19,35 +17,37 @@ function numberFormat(numberState) {
?.getAttribute("href") ?.getAttribute("href")
)?.searchParams?.get("locale"); )?.searchParams?.get("locale");
} catch {} } catch {}
let numberDisplay; let numberDisplay;
if (extConfig.numberDisplayRoundDown === false) { if (extConfig.numberDisplayRoundDown === false) {
numberDisplay = numberState; numberDisplay = numberState;
} else { } else {
numberDisplay = roundDown(numberState); numberDisplay = roundDown(numberState);
} }
return getNumberFormatter(extConfig.numberDisplayFormat).format(numberDisplay); return getNumberFormatter(extConfig.numberDisplayFormat).format(
numberDisplay
);
} }
function getNumberFormatter(optionSelect) { function getNumberFormatter(optionSelect) {
let formatterNotation; let formatterNotation;
let formatterCompactDisplay; let formatterCompactDisplay;
switch(optionSelect) { switch (optionSelect) {
case 'compactLong': case "compactLong":
formatterNotation = 'compact'; formatterNotation = "compact";
formatterCompactDisplay = 'long'; formatterCompactDisplay = "long";
break; break;
case 'standard': case "standard":
formatterNotation = 'standard'; formatterNotation = "standard";
formatterCompactDisplay = 'short'; formatterCompactDisplay = "short";
break; break;
case 'compactShort': case "compactShort":
default: default:
formatterNotation = 'compact'; formatterNotation = "compact";
formatterCompactDisplay = 'short'; formatterCompactDisplay = "short";
} }
const formatter = Intl.NumberFormat( const formatter = Intl.NumberFormat(
document.documentElement.lang || userLocales || navigator.language, document.documentElement.lang || userLocales || navigator.language,
{ {
@@ -90,10 +90,10 @@ function isInViewport(element) {
const height = innerHeight || document.documentElement.clientHeight; const height = innerHeight || document.documentElement.clientHeight;
const width = innerWidth || document.documentElement.clientWidth; const width = innerWidth || document.documentElement.clientWidth;
return ( return (
rect.top >= 0 && rect.top >= 0 &&
rect.left >= 0 && rect.left >= 0 &&
rect.bottom <= height && rect.bottom <= height &&
rect.right <= width rect.right <= width
); );
} }
@@ -115,30 +115,29 @@ function cLog(message, writer) {
} }
} }
function getColorFromTheme(voteIsLike) { function getColorFromTheme(voteIsLike) {
let colorString; let colorString;
switch(extConfig.colorTheme) { switch (extConfig.colorTheme) {
case 'accessible': case "accessible":
if (voteIsLike === true) { if (voteIsLike === true) {
colorString = 'dodgerblue'; colorString = "dodgerblue";
} else { } else {
colorString = 'gold'; colorString = "gold";
} }
break; break;
case 'neon': case "neon":
if (voteIsLike === true) { if (voteIsLike === true) {
colorString = 'aqua'; colorString = "aqua";
} else { } else {
colorString = 'magenta'; colorString = "magenta";
} }
break; break;
case 'classic': case "classic":
default: default:
if (voteIsLike === true) { if (voteIsLike === true) {
colorString = 'lime'; colorString = "lime";
} else { } else {
colorString = 'red'; colorString = "red";
} }
} }
return colorString; return colorString;
@@ -151,5 +150,12 @@ export {
isVideoLoaded, isVideoLoaded,
cLog, cLog,
getColorFromTheme, getColorFromTheme,
} };
export { numberFormat, getBrowser, getVideoId, isInViewport, isVideoLoaded, cLog } export {
numberFormat,
getBrowser,
getVideoId,
isInViewport,
isVideoLoaded,
cLog,
};