mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-02 02:41:22 +01:00
Merge pull request #246 from AgentConDier/mobile-support
Feature: Support for Android Firefox and m.youtube.com
This commit is contained in:
3 files changed
+59
-25
No files matched your search
@@ -1,3 +1,9 @@
|
|||||||
|
html {
|
||||||
|
/* fallback values for mobile */
|
||||||
|
--yt-spec-icon-disabled: #909090;
|
||||||
|
--yt-spec-text-primary: #030303;
|
||||||
|
}
|
||||||
|
|
||||||
#return-youtube-dislike-bar-container {
|
#return-youtube-dislike-bar-container {
|
||||||
background: var(--yt-spec-icon-disabled);
|
background: var(--yt-spec-icon-disabled);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
@@ -16,6 +22,16 @@
|
|||||||
top: 9px;
|
top: 9px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ytm-slim-video-action-bar-renderer > .ryd-tooltip {
|
||||||
|
padding-left: 12px;
|
||||||
|
top: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tp-yt-paper-tooltip not supported on mobile */
|
||||||
|
ytm-slim-video-action-bar-renderer tp-yt-paper-tooltip {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.ryd-tooltip-bar-container {
|
.ryd-tooltip-bar-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 2px;
|
height: 2px;
|
||||||
|
|||||||
@@ -46,8 +46,14 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
toSend = [];
|
toSend = [];
|
||||||
}
|
}
|
||||||
} else if (request.message == "fetch_from_youtube") {
|
} else if (request.message == "fetch_from_youtube") {
|
||||||
|
let headers = {}
|
||||||
|
if (navigator && navigator.userAgent) {
|
||||||
|
// Never request mobile version
|
||||||
|
headers["User-Agent"] = navigator.userAgent.replace(/\(.*Mobile;/,"(X11; Linux x86_64;");
|
||||||
|
}
|
||||||
fetch(`https://www.youtube.com/watch?v=${request.videoId}`, {
|
fetch(`https://www.youtube.com/watch?v=${request.videoId}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
headers: headers
|
||||||
})
|
})
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((text) => {
|
.then((text) => {
|
||||||
|
|||||||
@@ -19,14 +19,16 @@ function cLog(message, writer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getButtons() {
|
function getButtons() {
|
||||||
//--- If Menu Element Is Displayed: ---//
|
let menu_container = document.getElementById("menu-container");
|
||||||
if (document.getElementById("menu-container")?.offsetParent === null) {
|
//--- m.youtube.com: ---//
|
||||||
|
if (menu_container === null) {
|
||||||
|
return document.querySelector(".slim-video-action-bar-actions");
|
||||||
|
//--- If Menu Element Is Displayed: ---//
|
||||||
|
} else if (menu_container.offsetParent === null) {
|
||||||
return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
|
return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
|
||||||
//--- If Menu Element Isnt Displayed: ---//
|
//--- If Menu Element Isnt Displayed: ---//
|
||||||
} else {
|
} else {
|
||||||
return document
|
return menu_container.querySelector("#top-level-buttons-computed");
|
||||||
.getElementById("menu-container")
|
|
||||||
?.querySelector("#top-level-buttons-computed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,19 +41,23 @@ function getDislikeButton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isVideoLiked() {
|
function isVideoLiked() {
|
||||||
return getLikeButton().classList.contains("style-default-active");
|
return getLikeButton().classList.contains("style-default-active")
|
||||||
|
|| getLikeButton().querySelector('[aria-pressed="true"]') !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoDisliked() {
|
function isVideoDisliked() {
|
||||||
return getDislikeButton().classList.contains("style-default-active");
|
return getDislikeButton().classList.contains("style-default-active")
|
||||||
|
|| getDislikeButton().querySelector('[aria-pressed="true"]') !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoNotLiked() {
|
function isVideoNotLiked() {
|
||||||
return getLikeButton().classList.contains("style-text");
|
return getLikeButton().classList.contains("style-text")
|
||||||
|
|| getLikeButton().querySelector('[aria-pressed="false"]') !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoNotDisliked() {
|
function isVideoNotDisliked() {
|
||||||
return getDislikeButton().classList.contains("style-text");
|
return getDislikeButton().classList.contains("style-text")
|
||||||
|
|| getDislikeButton().querySelector('[aria-pressed="false"]') !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getState() {
|
function getState() {
|
||||||
@@ -66,10 +72,10 @@ function getState() {
|
|||||||
|
|
||||||
//--- Sets The Likes And Dislikes Values ---//
|
//--- Sets The Likes And Dislikes Values ---//
|
||||||
function setLikes(likesCount) {
|
function setLikes(likesCount) {
|
||||||
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
getLikeButton().querySelector("#text, .button-renderer-text").innerText = likesCount;
|
||||||
}
|
}
|
||||||
function setDislikes(dislikesCount) {
|
function setDislikes(dislikesCount) {
|
||||||
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
getDislikeButton().querySelector("#text, .button-renderer-text").innerText = dislikesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setState() {
|
function setState() {
|
||||||
@@ -161,7 +167,9 @@ function getVideoId(url) {
|
|||||||
function isVideoLoaded() {
|
function isVideoLoaded() {
|
||||||
const videoId = getVideoId(window.location.href);
|
const videoId = getVideoId(window.location.href);
|
||||||
return (
|
return (
|
||||||
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null ||
|
||||||
|
// mobile: no video-id attribute
|
||||||
|
document.querySelector('#player[loading="false"]:not([hidden])') !== null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,8 +197,8 @@ function setEventListeners(evt) {
|
|||||||
clearInterval(jsInitChecktimer);
|
clearInterval(jsInitChecktimer);
|
||||||
const buttons = getButtons();
|
const buttons = getButtons();
|
||||||
if (!window.returnDislikeButtonlistenersSet) {
|
if (!window.returnDislikeButtonlistenersSet) {
|
||||||
buttons.children[0].addEventListener("click", likeClicked);
|
getLikeButton().addEventListener("click", likeClicked);
|
||||||
buttons.children[1].addEventListener("click", dislikeClicked);
|
getDislikeButton().addEventListener("click", dislikeClicked);
|
||||||
let lastKnownScrollPosition = 0;
|
let lastKnownScrollPosition = 0;
|
||||||
let ticking = false;
|
let ticking = false;
|
||||||
// document.addEventListener('scroll', function(e) {
|
// document.addEventListener('scroll', function(e) {
|
||||||
@@ -220,8 +228,8 @@ function createRateBar(likes, dislikes) {
|
|||||||
var rateBar = document.getElementById("return-youtube-dislike-bar-container");
|
var rateBar = document.getElementById("return-youtube-dislike-bar-container");
|
||||||
|
|
||||||
const widthPx =
|
const widthPx =
|
||||||
getButtons().children[0].clientWidth +
|
getLikeButton().clientWidth +
|
||||||
getButtons().children[1].clientWidth +
|
getDislikeButton().clientWidth +
|
||||||
8;
|
8;
|
||||||
|
|
||||||
const widthPercent =
|
const widthPercent =
|
||||||
@@ -229,8 +237,9 @@ function createRateBar(likes, dislikes) {
|
|||||||
|
|
||||||
if (!rateBar) {
|
if (!rateBar) {
|
||||||
(
|
(
|
||||||
document.querySelector("#actions-inner") ||
|
document.getElementById("actions-inner") ||
|
||||||
document.getElementById("menu-container")
|
document.getElementById("menu-container") ||
|
||||||
|
document.querySelector("ytm-slim-video-action-bar-renderer")
|
||||||
).insertAdjacentHTML(
|
).insertAdjacentHTML(
|
||||||
"beforeend",
|
"beforeend",
|
||||||
`
|
`
|
||||||
@@ -267,17 +276,20 @@ function createRateBar(likes, dislikes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendVideoIds() {
|
function sendVideoIds() {
|
||||||
const ids = Array.from(
|
let links = Array.from(
|
||||||
document.getElementsByClassName(
|
document.getElementsByClassName(
|
||||||
"yt-simple-endpoint ytd-compact-video-renderer"
|
"yt-simple-endpoint ytd-compact-video-renderer"
|
||||||
)
|
)
|
||||||
)
|
).concat(
|
||||||
.concat(
|
Array.from(
|
||||||
Array.from(
|
document.getElementsByClassName("yt-simple-endpoint ytd-thumbnail")
|
||||||
document.getElementsByClassName("yt-simple-endpoint ytd-thumbnail")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.filter((x) => x.href && x.href.indexOf("/watch?v=") > 0)
|
);
|
||||||
|
// Also try mobile
|
||||||
|
if (links.length < 1) links = Array.from(
|
||||||
|
document.querySelectorAll(".large-media-item-metadata > a, a.large-media-item-thumbnail-container")
|
||||||
|
);
|
||||||
|
const ids = links.filter((x) => x.href && x.href.indexOf("/watch?v=") > 0)
|
||||||
.map((x) => getVideoId(x.href));
|
.map((x) => getVideoId(x.href));
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
message: "send_links",
|
message: "send_links",
|
||||||
|
|||||||
Reference in new issue
Block a user