Merge branch 'Anarios:main' into main

This commit is contained in:
Front authored and GitHub committed 2021-12-01 16:48:39 -05:00
commit 39b9f1349d
15 files changed
+120 -83

No files matched your search

@@ -4,7 +4,7 @@
// @version 0.5 // @version 0.5
// @description Return of the YouTube Dislike, Based off https://www.returnyoutubedislike.com/ // @description Return of the YouTube Dislike, Based off https://www.returnyoutubedislike.com/
// @author Anarios & JRWR // @author Anarios & JRWR
// @match *://*.youtube.com/watch* // @match *://*.youtube.com/*
// @compatible chrome // @compatible chrome
// @compatible firefox // @compatible firefox
// @compatible opera // @compatible opera
@@ -16,36 +16,12 @@
// ==/UserScript== // ==/UserScript==
function cLog(text, subtext = '') { function cLog(text, subtext = '') {
subtext = subtext.trim() === '' ? '' : `(${subtext})`; subtext = subtext.trim() === '' ? '' : `(${subtext})`;
console.log(`[Return Youtube Dislikes] ${text} ${subtext}`); console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
}
function doXHR(opts) {
if (typeof GM_xmlhttpRequest === 'function') {
return GM_xmlhttpRequest(opts);
}
if (typeof GM !== 'undefined') /*This will prevent from throwing "Uncaught ReferenceError: GM is not defined"*/{
if (typeof GM.xmlHttpRequest === 'function') {
return GM.xmlHttpRequest(opts);
}
}
console.warn('Unable to detect UserScript plugin, falling back to native XHR.');
const xhr = new XMLHttpRequest();
xhr.open(opts.method, opts.url, true);
xhr.onload = () => opts.onload({
response: JSON.parse(xhr.responseText),
});
xhr.onerror = err => console.error('XHR Failed', err);
xhr.send();
} }
function getButtons() { function getButtons() {
if (document.getElementById("menu-container").offsetParent === null) { if (document.getElementById("menu-container").offsetParent === null) {
return document.querySelector( return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
"ytd-menu-renderer.ytd-watch-metadata > div"
);
} else { } else {
return document return document
.getElementById("menu-container") .getElementById("menu-container")
@@ -96,9 +72,7 @@ function setDislikes(dislikesCount) {
} }
function createRateBar(likes, dislikes) { function createRateBar(likes, dislikes) {
var rateBar = document.getElementById( var rateBar = document.getElementById("return-youtube-dislike-bar-container");
"return-youtube-dislike-bar-container"
);
const widthPx = const widthPx =
getButtons().children[0].clientWidth + getButtons().children[0].clientWidth +
@@ -144,32 +118,46 @@ function createRateBar(likes, dislikes) {
} }
function setState() { function setState() {
cLog('Fetching votes...'); cLog("Fetching votes...");
let statsSet = false;
doXHR({ fetch(`https://www.youtube.com/watch?v=${getVideoId()}`).then((response) => {
method: "GET", response.text().then((text) => {
responseType: "json", let result = getDislikesFromYoutubeResponse(text);
url: if (result) {
"https://return-youtube-dislike-api.azurewebsites.net/votes?videoId=" + cLog("response from youtube:");
getVideoId(), cLog(JSON.stringify(result));
onload: function (xhr) { if (result.likes || result.dislikes) {
if (xhr != undefined) { const formattedDislike = numberFormat(result.dislikes);
const { dislikes, likes } = xhr.response; setDislikes(formattedDislike);
createRateBar(result.likes, result.dislikes);
statsSet = true;
}
}
});
});
fetch(
`https://return-youtube-dislike-api.azurewebsites.net/votes?videoId=${getVideoId()}`
).then((response) => {
response.json().then((json) => {
if (json && !statsSet) {
const { dislikes, likes } = json;
cLog(`Received count: ${dislikes}`); cLog(`Received count: ${dislikes}`);
setDislikes(numberFormat(dislikes)); setDislikes(numberFormat(dislikes));
createRateBar(likes, dislikes); createRateBar(likes, dislikes);
} }
}, });
}); });
} }
function likeClicked() { function likeClicked() {
cLog('Like clicked', getState()); cLog("Like clicked", getState());
setState(); setState();
} }
function dislikeClicked() { function dislikeClicked() {
cLog('Dislike clicked', getState()); cLog("Dislike clicked", getState());
setState(); setState();
} }
@@ -194,21 +182,53 @@ function isVideoLoaded() {
function roundDown(num) { function roundDown(num) {
if (num < 1000) return num; if (num < 1000) return num;
const decimal = Math.floor(Math.log10(num) - 1); const int = Math.floor(Math.log10(num) - 2);
const decimal = int + (int % 3 ? 1 : 0);
const value = Math.floor(num / 10 ** decimal); const value = Math.floor(num / 10 ** decimal);
return value * (10 ** decimal); return value * 10 ** decimal;
} }
function numberFormat(numberState) { function numberFormat(numberState) {
const userLocales = navigator.language; const userLocales = navigator.language;
const formatter = Intl.NumberFormat(userLocales, { const formatter = Intl.NumberFormat(userLocales, {
notation: 'compact', notation: "compact",
minimumFractionDigits: 1, minimumFractionDigits: 1,
maximumFractionDigits: 1 maximumFractionDigits: 1,
}); });
return formatter.format(roundDown(numberState)).replace('.0', ''); return formatter.format(roundDown(numberState)).replace(/\.0|,0/, "");
}
function getDislikesFromYoutubeResponse(htmlResponse) {
let start =
htmlResponse.indexOf('"videoDetails":') + '"videoDetails":'.length;
let end =
htmlResponse.indexOf('"isLiveContent":false}', start) +
'"isLiveContent":false}'.length;
if (end < start) {
end =
htmlResponse.indexOf('"isLiveContent":true}', start) +
'"isLiveContent":true}'.length;
}
let jsonStr = htmlResponse.substring(start, end);
let jsonResult = JSON.parse(jsonStr);
let rating = jsonResult.averageRating;
start = htmlResponse.indexOf('"topLevelButtons":[', end);
start =
htmlResponse.indexOf('"accessibilityData":', start) +
'"accessibilityData":'.length;
end = htmlResponse.indexOf("}", start);
let likes = +htmlResponse.substring(start, end).replace(/\D/g, "");
let dislikes = (likes * (5 - rating)) / (rating - 1);
let result = {
likes,
dislikes: Math.round(dislikes),
rating,
viewCount: +jsonResult.viewCount,
};
return result;
} }
function setEventListeners(evt) { function setEventListeners(evt) {
@@ -218,7 +238,7 @@ function setEventListeners(evt) {
const buttons = getButtons(); const buttons = getButtons();
if (!window.returnDislikeButtonlistenersSet) { if (!window.returnDislikeButtonlistenersSet) {
cLog('Registering button listeners...'); cLog("Registering button listeners...");
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;
@@ -228,7 +248,7 @@ function setEventListeners(evt) {
} }
if (window.location.href.indexOf("watch?") >= 0) { if (window.location.href.indexOf("watch?") >= 0) {
cLog('Setting up...'); cLog("Setting up...");
var jsInitChecktimer = setInterval(checkForJS_Finish, 111); var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
} }
} }
+3 -3
View File
@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta content="text/html; charset=utf-8"> <meta content="text/html; charset=utf-8">
<title>Return Youtube Dislike</title> <title>Return YouTube Dislike</title>
<link rel="stylesheet" href="popup.css"> <link rel="stylesheet" href="popup.css">
</head> </head>
<body> <body>
@@ -10,11 +10,11 @@
<center> <center>
<img src="icons/icon48.png" alt="Logo" /> <img src="icons/icon48.png" alt="Logo" />
<h1>Return Youtube Dislike</h1> <h1>Return YouTube Dislike</h1>
<p>by Dmitrii Selivanov & Community</p> <p>by Dmitrii Selivanov & Community</p>
<button id="link_website">Website</button> <button id="link_website">Website</button>
<button id="link_github">Github</button> <button id="link_github">GitHub</button>
<button id="link_discord">Discord</button> <button id="link_discord">Discord</button>
<br> <br>
@@ -139,7 +139,8 @@
function roundDown(num) { function roundDown(num) {
if (num < 1000) return num; if (num < 1000) return num;
const decimal = Math.floor(Math.log10(num) - 1); const int = Math.floor(Math.log10(num) - 2);
const decimal = int + (int % 3 ? 1 : 0);
const value = Math.floor(num / 10 ** decimal); const value = Math.floor(num / 10 ** decimal);
return value * (10 ** decimal); return value * (10 ** decimal);
} }
@@ -153,7 +154,7 @@
maximumFractionDigits: 1 maximumFractionDigits: 1
}); });
return formatter.format(roundDown(numberState)).replace('.0', ''); return formatter.format(roundDown(numberState)).replace(/\.0|,0/, '');
} }
var jsInitChecktimer = null; var jsInitChecktimer = null;
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"name": "Return Youtube Dislike", "name": "Return YouTube Dislike",
"description": "Returns ability to see dislikes", "description": "Returns ability to see dislikes",
"version": "0.0.0.9", "version": "0.0.0.9",
"manifest_version": 2, "manifest_version": 2,
+3 -3
View File
@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta content="text/html; charset=utf-8"> <meta content="text/html; charset=utf-8">
<title>Return Youtube Dislike</title> <title>Return YouTube Dislike</title>
<link rel="stylesheet" href="popup.css"> <link rel="stylesheet" href="popup.css">
</head> </head>
<body> <body>
@@ -10,11 +10,11 @@
<center> <center>
<img src="icons/icon48.png" alt="Logo" /> <img src="icons/icon48.png" alt="Logo" />
<h1>Return Youtube Dislike</h1> <h1>Return YouTube Dislike</h1>
<p>by Dmitrii Selivanov & Community</p> <p>by Dmitrii Selivanov & Community</p>
<button id="link_website">Website</button> <button id="link_website">Website</button>
<button id="link_github">Github</button> <button id="link_github">GitHub</button>
<button id="link_discord">Discord</button> <button id="link_discord">Discord</button>
<br> <br>
@@ -135,7 +135,8 @@ function isVideoLoaded() {
function roundDown(num) { function roundDown(num) {
if (num < 1000) return num; if (num < 1000) return num;
const decimal = Math.floor(Math.log10(num) - 1); const int = Math.floor(Math.log10(num) - 2);
const decimal = int + (int % 3 ? 1 : 0);
const value = Math.floor(num / 10 ** decimal); const value = Math.floor(num / 10 ** decimal);
return value * (10 ** decimal); return value * (10 ** decimal);
} }
@@ -149,7 +150,7 @@ function numberFormat(numberState) {
maximumFractionDigits: 1 maximumFractionDigits: 1
}); });
return formatter.format(roundDown(numberState)).replace('.0', ''); return formatter.format(roundDown(numberState)).replace(/\.0|,0/, '');
} }
function setEventListeners(evt) { function setEventListeners(evt) {
+2 -2
View File
@@ -1,7 +1,7 @@
[![Mozilla rating](https://img.shields.io/amo/stars/return-youtube-dislikes?label=Firefox%20Rating&style=flat&logo=firefox)](https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/)
[![Mozilla downloads](https://img.shields.io/amo/users/return-youtube-dislikes?label=Firefox%20Users&style=flat&logo=firefox)](https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/)
[![Chrome Web Store](https://img.shields.io/chrome-web-store/stars/gebbhagfogifgggkldgodflihgfeippi?label=Chrome%20Rating&style=flat&logo=google)](https://chrome.google.com/webstore/detail/youtube-dislike-button/gebbhagfogifgggkldgodflihgfeippi/) [![Chrome Web Store](https://img.shields.io/chrome-web-store/stars/gebbhagfogifgggkldgodflihgfeippi?label=Chrome%20Rating&style=flat&logo=google)](https://chrome.google.com/webstore/detail/youtube-dislike-button/gebbhagfogifgggkldgodflihgfeippi/)
[![Chrome Web Store Users](https://img.shields.io/chrome-web-store/users/gebbhagfogifgggkldgodflihgfeippi?label=Chrome%20Users&style=flat&logo=google)](https://chrome.google.com/webstore/detail/youtube-dislike-button/gebbhagfogifgggkldgodflihgfeippi/) [![Chrome Web Store Users](https://img.shields.io/chrome-web-store/users/gebbhagfogifgggkldgodflihgfeippi?label=Chrome%20Users&style=flat&logo=google)](https://chrome.google.com/webstore/detail/youtube-dislike-button/gebbhagfogifgggkldgodflihgfeippi/)
[![Mozilla rating](https://img.shields.io/amo/stars/return-youtube-dislikes?label=Firefox%20Rating&style=flat&logo=firefox)](https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/)
[![Mozilla downloads](https://img.shields.io/amo/users/return-youtube-dislikes?label=Firefox%20Users&style=flat&logo=firefox)](https://addons.mozilla.org/en-US/firefox/addon/return-youtube-dislikes/)
[![Commit rate](https://img.shields.io/github/commit-activity/m/Anarios/return-youtube-dislike?label=Commits&style=flat)](https://github.com/Anarios/return-youtube-dislike/commits/main) [![Commit rate](https://img.shields.io/github/commit-activity/m/Anarios/return-youtube-dislike?label=Commits&style=flat)](https://github.com/Anarios/return-youtube-dislike/commits/main)
[![Issues](https://img.shields.io/github/issues/Anarios/return-youtube-dislike?style=flat&label=Issues)](https://github.com/Anarios/return-youtube-dislike/issues) [![Issues](https://img.shields.io/github/issues/Anarios/return-youtube-dislike?style=flat&label=Issues)](https://github.com/Anarios/return-youtube-dislike/issues)
[![Discord](https://img.shields.io/discord/909435648170160229?label=Discord&style=flat&logo=discord)](https://discord.gg/UMxyMmCgfF) [![Discord](https://img.shields.io/discord/909435648170160229?label=Discord&style=flat&logo=discord)](https://discord.gg/UMxyMmCgfF)
+2 -2
View File
@@ -171,7 +171,7 @@
extension users to derive actual dislike count on a video extension users to derive actual dislike count on a video
</p> </p>
<p> <p>
Youtube has removed dislike statistics. Since this was a very YouTube has removed dislike statistics. Since this was a very
usefull feature - this extension aims to return this functionality usefull feature - this extension aims to return this functionality
to users. to users.
</p> </p>
@@ -181,7 +181,7 @@
</div> </div>
<p> <p>
We're considering integration with We're considering integration with
<a href="https://vancedapp.com/">Youtube Vanced</a> mobile app, if <a href="https://vancedapp.com/">YouTube Vanced</a> mobile app, if
the devs will want to utilize our API the devs will want to utilize our API
</p> </p>
+1 -1
View File
@@ -1,4 +1,4 @@
# Return-Youtube-Dislike # return-youtube-dislike-site
## Build Setup ## Build Setup
+1 -1
View File
@@ -3,7 +3,7 @@
<v-app-bar app color="lighten-2" flat> <v-app-bar app color="lighten-2" flat>
<v-tabs centered class="ml-n9" color="primary" router> <v-tabs centered class="ml-n9" color="primary" router>
<v-tab v-for="link in links" :key="link" :to="link.path"> <v-tab v-for="link in links" :key="link.path" :to="link.path">
{{ link.name }} {{ link.name }}
</v-tab> </v-tab>
</v-tabs> </v-tabs>
+2 -2
View File
@@ -3,8 +3,8 @@ import colors from 'vuetify/es5/util/colors'
export default { export default {
// Global page headers: https://go.nuxtjs.dev/config-head // Global page headers: https://go.nuxtjs.dev/config-head
head: { head: {
titleTemplate: 'Return Youtube Dislike', titleTemplate: 'Return YouTube Dislike',
title: 'Return Youtube Dislike', title: 'Return YouTube Dislike',
htmlAttrs: { htmlAttrs: {
lang: 'en' lang: 'en'
}, },
+6 -6
View File
@@ -21,20 +21,20 @@
data: () => ({ data: () => ({
items: [ items: [
{ {
question: "Where does extension get data?", question: "Where does the extension get its data?",
answer: "Combination of GoogleAPI data and scraped data. We save all available data to our DB for it to be available after google shuts down dislike counts in their API." answer: "A combination of Google's API data and scraped data. We save all available data to our DB so it can be made available after Google removes dislike counts from their API."
}, },
{ {
question: "Video dislike count doesn't update", question: "Why isn't the dislike count updating?",
answer: "Right now video dislikes are cached, and arent updated very frequenly. Once in 2-3 days, not more often Yeah, it's not ideal, but it is what it is. Working on improving how often we can update them" answer: "Right now video dislikes are cached and they arent updated very frequenly. Currently this is set to update once every 2–3 days. This isn't ideal and we are working on improving how often we can update them"
}, },
{ {
question: "How does this work?", question: "How does this work?",
answer: "The extension collects the video id of the video you are watching, fetches the dislike (and other fields like views, likes etc) using our API, if this is the first time the video was fetched by our API, it will use the YouTube API to get the data, then stores the data in a database for caching (cached for around 2-3 days) and archiving purposes and returns it to you. The extension then displays the dislikes to you." answer: "The extension collects the video ID of the video you are watching, fetches the dislike (and other fields like views, likes etc) using our API, if this is the first time the video was fetched by our API, it will use the YouTube API to get the data, then store it in the database for caching (cached for around 2-3 days) and archiving purposes, and returns it to you. The extension then displays the dislike count and ratio on the page."
}, },
{ {
question: "What will happen after the YouTube API stops returning the dislike count?", question: "What will happen after the YouTube API stops returning the dislike count?",
answer: "The backend will switch to using a combination of archived dislike stats, estimates extrapolated from extension user data and estimates based on view/like ratios for videos whose dislikes weren't archived and for outdated dislike archives." answer: "The backend will switch to using a combination of archived dislike stats, estimates extrapolated from extension user data, and estimates based on view/like ratios for videos whose dislikes weren't archived as well as outdated dislike count archives."
}, },
], ],
}), }),
+2 -2
View File
@@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<h1 style="font-size: 3em; margin-bottom:0;">Return Youtube Dislike</h1> <h1 style="font-size: 3em; margin-bottom:0;">Return YouTube Dislike</h1>
<div style="color: #999"> <div style="color: #999">
<p style="margin-top: 0">Browser extension and an API that show you dislikes on youtube</p> <p style="margin-top: 0">Browser extension and an API that show you dislikes on youtube</p>
</div> </div>
@@ -15,7 +15,7 @@
<v-btn class="mainAltButton" :href="githubLink" target="_blank"> <v-btn class="mainAltButton" :href="githubLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-github</v-icon> <v-icon style="margin-right: 0.5em;">mdi-github</v-icon>
Github GitHub
</v-btn> </v-btn>
<v-btn class="mainAltButton" :href="discordLink" target="_blank"> <v-btn class="mainAltButton" :href="discordLink" target="_blank">
+20 -5
View File
@@ -5,19 +5,34 @@
<div style="color: #999"> <div style="color: #999">
<p style="margin-bottom: 0;"> This is an <b>ALPHA version!</b> It may be slow. It may be buggy.</p> <p style="margin-bottom: 0;"> This is an <b>ALPHA version!</b> It may be slow. It may be buggy.</p>
<p style="margin-bottom: 3em;">Only available for Chrome, Firefox and as a Userscript now, but coming to other platforms soon.</p> <p style="margin-bottom: 1em;">Available for Firefox and all Chromium browsers (Chrome/Edge/Opera/Brave).</p>
</div> </div>
<v-btn class="mainAltButton" :href="firefoxLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-firefox</v-icon>
Firefox
</v-btn>
<v-btn class="mainAltButton" :href="chromeLink" target="_blank"> <v-btn class="mainAltButton" :href="chromeLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-google-chrome</v-icon> <v-icon style="margin-right: 0.5em;">mdi-google-chrome</v-icon>
Chrome Chrome
</v-btn> </v-btn>
<v-btn class="mainAltButton" :href="firefoxLink" target="_blank"> <v-btn class="mainAltButton" :href="chromeLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-firefox</v-icon> <v-icon style="margin-right: 0.5em;">mdi-microsoft-edge</v-icon>
Firefox Edge
</v-btn> </v-btn>
<v-btn class="mainAltButton" :href="chromeLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-opera</v-icon>
Opera
</v-btn>
<h3 style="margin-top: 3em; margin-bottom:0">Other Platforms</h3>
<div style="color: #999">
<p style="margin-top: 0em; margin-bottom:0;">If your browser is not yet supported, try this UserScript.</p>
</div>
<v-btn class="mainAltButton" :href="scriptLink" target="_blank"> <v-btn class="mainAltButton" :href="scriptLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-script-text-outline</v-icon> <v-icon style="margin-right: 0.5em;">mdi-script-text-outline</v-icon>
Userscript (Tampermonkey) Userscript (Tampermonkey)
@@ -25,7 +40,7 @@
<h3 style="margin-top: 3em;">Third Party Implementations</h3> <h3 style="margin-top: 3em;">Third Party Implementations</h3>
<div style="color: #999"> <div style="color: #999">
<p style="margin-bottom: 0;">No liability on our side, use at your own risk</p> <p style="margin-bottom: 0;">No liability on our side, use at your own risk.</p>
</div> </div>
<v-btn class="mainAltButton" :href="iosJailbreakLink" target="_blank"> <v-btn class="mainAltButton" :href="iosJailbreakLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-apple</v-icon> <v-icon style="margin-right: 0.5em;">mdi-apple</v-icon>
+1 -1
View File
@@ -9,7 +9,7 @@
<v-btn class="mainAltButton" :href="githubLink" target="_blank"> <v-btn class="mainAltButton" :href="githubLink" target="_blank">
<v-icon style="margin-right: 0.5em;">mdi-github</v-icon> <v-icon style="margin-right: 0.5em;">mdi-github</v-icon>
Github GitHub
</v-btn> </v-btn>
<v-btn class="mainAltButton" :href="discordLink" target="_blank"> <v-btn class="mainAltButton" :href="discordLink" target="_blank">