Formatting, static site style

This commit is contained in:
Dmitrii Selivanov committed 2021-11-21 14:23:00 +03:00
1 parent 6b96a70876
commit 1027f43503
2 files changed
+110 -100

No files matched your search

@@ -16,122 +16,124 @@
// @grant GM_xmlhttpRequest // @grant GM_xmlhttpRequest
// ==/UserScript== // ==/UserScript==
function getButtons() { function getButtons() {
return document return document
.getElementById("menu-container") .getElementById("menu-container")
?.querySelector("#top-level-buttons-computed"); ?.querySelector("#top-level-buttons-computed");
} }
function getLikeButton() { function getLikeButton() {
return getButtons().children[0]; return getButtons().children[0];
} }
function getDislikeButton() { function getDislikeButton() {
return getButtons().children[1]; return getButtons().children[1];
} }
function isVideoLiked() { function isVideoLiked() {
return getLikeButton().classList.contains("style-default-active"); return getLikeButton().classList.contains("style-default-active");
} }
function isVideoDisliked() { function isVideoDisliked() {
return getDislikeButton().classList.contains("style-default-active"); return getDislikeButton().classList.contains("style-default-active");
} }
function isVideoNotLiked() { function isVideoNotLiked() {
return getLikeButton().classList.contains("style-text"); return getLikeButton().classList.contains("style-text");
} }
function isVideoNotDisliked() { function isVideoNotDisliked() {
return getDislikeButton().classList.contains("style-text"); return getDislikeButton().classList.contains("style-text");
} }
function getState() { function getState() {
if (isVideoLiked()) { if (isVideoLiked()) {
return "liked"; return "liked";
} }
if (isVideoDisliked()) { if (isVideoDisliked()) {
return "disliked"; return "disliked";
} }
return "neutral"; return "neutral";
} }
function setLikes(likesCount) { function setLikes(likesCount) {
getButtons().children[0].querySelector("#text").innerText = likesCount; getButtons().children[0].querySelector("#text").innerText = likesCount;
} }
function setDislikes(dislikesCount) { function setDislikes(dislikesCount) {
getButtons().children[1].querySelector("#text").innerText = dislikesCount; getButtons().children[1].querySelector("#text").innerText = dislikesCount;
} }
function setState() { function setState() {
GM_xmlhttpRequest({ GM_xmlhttpRequest({
method: "GET", method: "GET",
responseType: "json", responseType: "json",
url: "https://return-youtube-dislike-api.azurewebsites.net/votes?videoId=" + getVideoId(), url:
onload: function(response) { "https://return-youtube-dislike-api.azurewebsites.net/votes?videoId=" +
if (response != undefined) { getVideoId(),
const formattedDislike = numberFormat(response.response.dislikes); onload: function (response) {
console.log(response); if (response != undefined) {
setDislikes(formattedDislike); const formattedDislike = numberFormat(response.response.dislikes);
} console.log(response);
} setDislikes(formattedDislike);
}); }
},
});
} }
function likeClicked() { function likeClicked() {
console.log("like" + getState()); console.log("like" + getState());
setState(); setState();
} }
function dislikeClicked() { function dislikeClicked() {
console.log("dislike" + getState()); console.log("dislike" + getState());
setState(); setState();
} }
function setInitalState() { function setInitalState() {
setState(); setState();
} }
function getVideoId() { function getVideoId() {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const videoId = urlParams.get("v"); const videoId = urlParams.get("v");
return videoId; return videoId;
} }
function isVideoLoaded() { function isVideoLoaded() {
const videoId = getVideoId(); const videoId = getVideoId();
return ( return (
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
); );
} }
function numberFormat(numberState) { function numberFormat(numberState) {
const userLocales = navigator.language; const userLocales = navigator.language;
const formatter = Intl.NumberFormat(userLocales, { notation: "compact" }); const formatter = Intl.NumberFormat(userLocales, { notation: "compact" });
return formatter.format(numberState); return formatter.format(numberState);
} }
function setEventListeners(evt) { function setEventListeners(evt) {
function checkForJS_Finish() { function checkForJS_Finish() {
if (getButtons()?.offsetParent && isVideoLoaded()) { if (getButtons()?.offsetParent && isVideoLoaded()) {
clearInterval(jsInitChecktimer); clearInterval(jsInitChecktimer);
const buttons = getButtons(); const buttons = getButtons();
if (!window.returnDislikeButtonlistenersSet) { if (!window.returnDislikeButtonlistenersSet) {
buttons.children[0].addEventListener("click", likeClicked); buttons.children[0].addEventListener("click", likeClicked);
buttons.children[1].addEventListener("click", dislikeClicked); buttons.children[1].addEventListener("click", dislikeClicked);
window.returnDislikeButtonlistenersSet = true; window.returnDislikeButtonlistenersSet = true;
} }
setInitalState(); setInitalState();
}
} }
}
if (window.location.href.indexOf("watch?") >= 0) { if (window.location.href.indexOf("watch?") >= 0) {
var jsInitChecktimer = setInterval(checkForJS_Finish, 111); var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
} }
} }
(function() { (function () {
'use strict'; "use strict";
window.addEventListener("yt-navigate-finish", setEventListeners, true); window.addEventListener("yt-navigate-finish", setEventListeners, true);
setEventListeners(); setEventListeners();
})(); })();
+45 -37
View File
@@ -12,39 +12,42 @@
<title>Return youtube dislike count</title> <title>Return youtube dislike count</title>
</head> </head>
<body> <body>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid"> <div class="container-xxl">
<a class="navbar-brand" href="/">Return youtube dislike count</a> <a class="navbar-brand" href="/">Return youtube dislike count</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
<span class="navbar-toggler-icon"></span> aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
</button> <span class="navbar-toggler-icon"></span>
<div class="collapse navbar-collapse" id="navbarNav"> </button>
<ul class="navbar-nav"> <div class="collapse navbar-collapse" id="navbarNav">
<li class="nav-item"> <ul class="navbar-nav">
<a class="nav-link" href="#downloads">Downloads</a> <li class="nav-item">
</li> <a class="nav-link" href="#downloads">Downloads</a>
<li class="nav-item"> </li>
<a class="nav-link" href="#installation">Installation</a> <li class="nav-item">
</li> <a class="nav-link" href="#installation">Installation</a>
<li class="nav-item"> </li>
<a class="nav-link" href="#faq">FAQ</a> <li class="nav-item">
</li> <a class="nav-link" href="#faq">FAQ</a>
<li class="nav-item"> </li>
<a class="nav-link" href="#communication">Communication</a> <li class="nav-item">
</li> <a class="nav-link" href="#communication">Communication</a>
<li class="nav-item"> </li>
<a class="nav-link" href="#sources">Sources</a> <li class="nav-item">
</li> <a class="nav-link" href="#sources">Sources</a>
</ul> </li>
</div> </ul>
</div> </div>
</nav> </div>
</nav>
<div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-lg-8 col-md-10 col-sm-12"> <div class="col-lg-8 col-md-10 col-sm-12">
<h3 class="mt-4">Chrome/Firefox/Usersript extension to return youtube dislike count</h3> <h3 class="mt-4">Chrome/Firefox/Usersript extension to return youtube dislike count</h3>
<img src="images/aAGrY8L_700b.jpg" class="img-fluid"/> <img src="images/aAGrY8L_700b.jpg" class="img-fluid"/>
<p><strong>Version 0.0.0.5 released - ratio (like/dislike) bar added</strong></p> <p><strong>Version 0.0.0.5 released - ratio (like/dislike) bar added</strong></p>
<img class="img-fluid mb-5" src="images/ratio.jpg"/> <img class="img-fluid mb-5" src="images/ratio.jpg"/>
@@ -79,18 +82,19 @@
<a href="files/chrome/return_youtube_dislike0.0.0.1.crx">v_0.0.0.1</a></p> <a href="files/chrome/return_youtube_dislike0.0.0.1.crx">v_0.0.0.1</a></p>
<p><a href="files/chrome/return_youtube_dislike0.0.0.2.crx">v_0.0.0.2</a> - Better number formatting added, <p><a href="files/chrome/return_youtube_dislike0.0.0.2.crx">v_0.0.0.2</a> - Better number formatting added,
<p><a href="files/chrome/return_youtube_dislike_LOAD_UNPACKED_0.0.0.3.zip">v_0.0.0.3</a> <p><a href="files/chrome/return_youtube_dislike_LOAD_UNPACKED_0.0.0.3.zip">v_0.0.0.3</a>
<p> 0.0.0.4 <strong> removed (accidental self-ddos)</strong></p> <p> 0.0.0.4 <strong> removed (accidental self-ddos)</strong></p>
<p> <a href="files/chrome/return_youtube_dislike_LOAD_UNPACKED_0.0.0.5.zip">0.0.0.5</a> <p><a href="files/chrome/return_youtube_dislike_LOAD_UNPACKED_0.0.0.5.zip">0.0.0.5</a>
- ratio bar added. Dislikes from every video on page are saved now - ratio bar added. Dislikes from every video on page are saved now
Previous versions are disabled automatically by chrome, because Chrome doesn't like .crx extensions. Previous versions are disabled automatically by chrome, because Chrome doesn't like .crx extensions.
Install this following new instructions. Install this following new instructions.
</p> </p>
<h4>Firefox:</h4> <h4>Firefox:</h4>
Install from extension's firefox addon store <a href="https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/" target="_blank">page</a>. Install from extension's firefox addon store <a
href="https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/" target="_blank">page</a>.
Check for updates often - this extension is being actively improved Check for updates often - this extension is being actively improved
Latest version coming out as soon as update is approved by Mozilla Latest version coming out as soon as update is approved by Mozilla
@@ -108,12 +112,15 @@
<div class="accordion-body"> <div class="accordion-body">
<div class="card card-body"> <div class="card card-body">
<p> NOT RECOMMENDED! Use firefox addon store <a href="https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/" target="_blank">link</a> <p> NOT RECOMMENDED! Use firefox addon store <a
href="https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/"
target="_blank">link</a>
</p> </p>
<p> <p>
<a href="files/ff/youtube_dislike_button-0.0.0.1-fx.xpi">v_0.0.0.1</a> <a href="files/ff/youtube_dislike_button-0.0.0.1-fx.xpi">v_0.0.0.1</a>
</p> </p>
<p><a href="files/ff/youtube_dislike_button-0.0.0.2-fx.xpi">v_0.0.0.2</a> - Better number formatting added <p><a href="files/ff/youtube_dislike_button-0.0.0.2-fx.xpi">v_0.0.0.2</a> - Better number formatting
added
thanks, <strong>bstka</strong> thanks, <strong>bstka</strong>
</p> </p>
</div> </div>
@@ -134,7 +141,8 @@
<h2>Installation on chrome</h2> <h2>Installation on chrome</h2>
<p></p><strong>Before installing new version - please manually delete old version</strong></p> <p></p><strong>Before installing new version - please manually delete old version</strong></p>
<p></p><strong>Chrome might disable this extension - you'll need to delete it and reinstall. </strong> <p></p><strong>Chrome might disable this extension - you'll need to delete it and reinstall. </strong>
This is a temporary problem while awaiting chrome store approval. You might use userscript or firefox extension meanwhile.</p> This is a temporary problem while awaiting chrome store approval. You might use userscript or firefox extension
meanwhile.</p>
<p> Installation is described for Chrome. For firefox extension is available in store</p> <p> Installation is described for Chrome. For firefox extension is available in store</p>