Advertisement
myarkqub

Untitled

Nov 22nd, 2022
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         test1
  3. // @namespace    https://www.returnyoutubedislike.com/
  4. // @homepage     https://www.returnyoutubedislike.com/
  5. // @version      3.0.13
  6. // @description  Return of the YouTube Dislike, Based off https://www.returnyoutubedislike.com/
  7. // @icon         https://icon2.cleanpng.com/20190210/pra/kisspng-oral-b-computer-icons-electric-toothbrush-vector-g-dislike-svg-png-icon-free-download-529935-onl-5c5fed7ba2c572.3419149515497905876667.jpg
  8. // @author       Anarios & JRWR
  9. // @match        *://*.youtube.com/*
  10. // @exclude      *://music.youtube.com/*
  11. // @exclude      *://*.music.youtube.com/*
  12. // @downloadURL  https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
  13. // @updateURL    https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
  14. // @grant        GM.xmlHttpRequest
  15. // @connect      youtube.com
  16. // @grant        GM_addStyle
  17. // @run-at       document-end
  18. // ==/UserScript==
  19. //Edited by Akob
  20. const extConfig = {
  21.     // BEGIN USER OPTIONS
  22.     // You may change the following variables to allowed values listed in the corresponding brackets (* means default). Keep the style and keywords intact.
  23.     showUpdatePopup: false, // [true, false*] Show a popup tab after extension update (See what's new)
  24.     disableVoteSubmission: false, // [true, false*] Disable like/dislike submission (Stops counting your likes and dislikes)
  25.     coloredThumbs: false, // [true, false*] Colorize thumbs (Use custom colors for thumb icons)
  26.     coloredBar: false, // [true, false*] Colorize ratio bar (Use custom colors for ratio bar)
  27.     colorTheme: "classic", // [classic*, accessible, neon] Color theme (red/green, blue/yellow, pink/cyan)
  28.     numberDisplayFormat: "compactShort", // [compactShort*, compactLong, standard] Number format (For non-English locale users, you may be able to improve appearance with a different option. Please file a feature request if your locale is not covered)
  29.     numberDisplayRoundDown: true, // [true*, false] Round down numbers (Show rounded down numbers)
  30.     tooltipPercentageMode: "none", // [none*, dash_like, dash_dislike, both, only_like, only_dislike] Mode of showing percentage in like/dislike bar tooltip.
  31.     numberDisplayReformatLikes: false, // [true, false*] Re-format like numbers (Make likes and dislikes format consistent)
  32.     // END USER OPTIONS
  33. };
  34.  
  35. const LIKED_STATE = "LIKED_STATE";
  36. const DISLIKED_STATE = "DISLIKED_STATE";
  37. const NEUTRAL_STATE = "NEUTRAL_STATE";
  38. let previousState = 3; //1=LIKED, 2=DISLIKED, 3=NEUTRAL
  39. let likesvalue = 0;
  40. let dislikesvalue = 0;
  41.  
  42. let isMobile = location.hostname == "m.youtube.com";
  43. let isShorts = () => location.pathname.startsWith("/shorts");
  44. let mobileDislikes = 0;
  45. function cLog(text, subtext = "") {
  46.     subtext = subtext.trim() === "" ? "" : `(${subtext})`;
  47.     console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
  48. }
  49.  
  50. function isInViewport(element) {
  51.     const rect = element.getBoundingClientRect();
  52.     const height = innerHeight || document.documentElement.clientHeight;
  53.     const width = innerWidth || document.documentElement.clientWidth;
  54.     return (
  55.         // When short (channel) is ignored, the element (like/dislike AND short itself) is
  56.         // hidden with a 0 DOMRect. In this case, consider it outside of Viewport
  57.         !(rect.top == 0 && rect.left == 0 && rect.bottom == 0 && rect.right == 0) &&
  58.         rect.top >= 0 &&
  59.         rect.left >= 0 &&
  60.         rect.bottom <= height &&
  61.         rect.right <= width
  62.     );
  63. }
  64.  
  65. function getButtons() {
  66.     if (isShorts()) {
  67.         let elements = document.querySelectorAll(
  68.             isMobile
  69.                 ? "ytm-like-button-renderer"
  70.                 : "#like-button > ytd-like-button-renderer"
  71.         );
  72.         for (let element of elements) {
  73.             if (isInViewport(element)) {
  74.                 return element;
  75.             }
  76.         }
  77.     }
  78.     if (isMobile) {
  79.         return document.querySelector(".slim-video-action-bar-actions");
  80.     }
  81.     if (document.getElementById("menu-container")?.offsetParent === null) {
  82.         return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
  83.     } else {
  84.         return document
  85.             .getElementById("menu-container")
  86.             ?.querySelector("#top-level-buttons-computed");
  87.     }
  88. }
  89.  
  90. function getLikeButton() {
  91.     return getButtons().children[0];
  92. }
  93.  
  94. function getLikeTextContainer() {
  95.     return (
  96.         getLikeButton().querySelector("#text") ??
  97.         getLikeButton().getElementsByTagName("yt-formatted-string")[0] ??
  98.         getLikeButton().querySelector("span[role='text']")
  99.     );
  100. }
  101.  
  102. function getDislikeButton() {
  103.     return getButtons().children[1];
  104. }
  105.  
  106. function getDislikeTextContainer() {
  107.     return (
  108.         getDislikeButton().querySelector("#text") ??
  109.         getDislikeButton().getElementsByTagName("yt-formatted-string")[0]
  110.     );
  111. }
  112.  
  113. let mutationObserver = new Object();
  114.  
  115. if (isShorts() && mutationObserver.exists !== true) {
  116.     cLog("initializing mutation observer");
  117.     mutationObserver.options = {
  118.         childList: false,
  119.         attributes: true,
  120.         subtree: false,
  121.     };
  122.     mutationObserver.exists = true;
  123.     mutationObserver.observer = new MutationObserver(function (
  124.         mutationList,
  125.         observer
  126.     ) {
  127.         mutationList.forEach((mutation) => {
  128.             if (
  129.                 mutation.type === "attributes" &&
  130.                 mutation.target.nodeName === "TP-YT-PAPER-BUTTON" &&
  131.                 mutation.target.id === "button"
  132.             ) {
  133.                 cLog("Short thumb button status changed");
  134.                 if (mutation.target.getAttribute("aria-pressed") === "true") {
  135.                     mutation.target.style.color =
  136.                         mutation.target.parentElement.parentElement.id === "like-button"
  137.                             ? getColorFromTheme(true)
  138.                             : getColorFromTheme(false);
  139.                 } else {
  140.                     mutation.target.style.color = "unset";
  141.                 }
  142.                 return;
  143.             }
  144.             cLog(
  145.                 "unexpected mutation observer event: " + mutation.target + mutation.type
  146.             );
  147.         });
  148.     });
  149. }
  150.  
  151. function isVideoLiked() {
  152.     if (isMobile) {
  153.         return (
  154.             getLikeButton().querySelector("button").getAttribute("aria-label") ==
  155.             "true"
  156.         );
  157.     }
  158.     return getLikeButton().classList.contains("style-default-active");
  159. }
  160.  
  161. function isVideoDisliked() {
  162.     if (isMobile) {
  163.         return (
  164.             getDislikeButton().querySelector("button").getAttribute("aria-label") ==
  165.             "true"
  166.         );
  167.     }
  168.     return getDislikeButton().classList.contains("style-default-active");
  169. }
  170.  
  171. function isVideoNotLiked() {
  172.     if (isMobile) {
  173.         return !isVideoLiked();
  174.     }
  175.     return getLikeButton().classList.contains("style-text");
  176. }
  177.  
  178. function isVideoNotDisliked() {
  179.     if (isMobile) {
  180.         return !isVideoDisliked();
  181.     }
  182.     return getDislikeButton().classList.contains("style-text");
  183. }
  184.  
  185. function checkForUserAvatarButton() {
  186.     if (isMobile) {
  187.         return;
  188.     }
  189.     if (document.querySelector("#avatar-btn")) {
  190.         return true;
  191.     } else {
  192.         return false;
  193.     }
  194. }
  195.  
  196. function getState() {
  197.     if (isVideoLiked()) {
  198.         return LIKED_STATE;
  199.     }
  200.     if (isVideoDisliked()) {
  201.         return DISLIKED_STATE;
  202.     }
  203.     return NEUTRAL_STATE;
  204. }
  205.  
  206. function setLikes(likesCount) {
  207.     if (isMobile) {
  208.         getButtons().children[0].querySelector(".button-renderer-text").innerText =
  209.             likesCount;
  210.         return;
  211.     }
  212.     getLikeTextContainer().innerText = likesCount;
  213. }
  214.  
  215. function setDislikes(dislikesCount) {
  216.     if (isMobile) {
  217.         mobileDislikes = dislikesCount;
  218.         return;
  219.     }
  220.     getDislikeTextContainer()?.removeAttribute('is-empty');
  221.     // getDislikeTextContainer().innerText = dislikesCount;
  222.     if (!document.querySelector(".zetta1")) {
  223.         document.querySelector(`#segmented-dislike-button .yt-spec-button-shape-next`).insertAdjacentHTML("beforeend", `<span class="zetta1">&nbsp;${dislikesCount}</span>`)
  224.     }
  225.     else {
  226.         document.querySelector(".zetta1").innerHTML = `&nbsp;${dislikesCount}`
  227.     }
  228.     document.querySelector(`#segmented-dislike-button .yt-spec-button-shape-next`).style.width = "80px";
  229. }
  230.  
  231. function getLikeCountFromButton() {
  232.     try {
  233.         if (isShorts()) {
  234.             //Youtube Shorts don't work with this query. It's not necessary; we can skip it and still see the results.
  235.             //It should be possible to fix this function, but it's not critical to showing the dislike count.
  236.             return false;
  237.         }
  238.         let likeButton = getLikeButton()
  239.             .querySelector("yt-formatted-string#text") ??
  240.             getLikeButton().querySelector("button");
  241.  
  242.         let likesStr = likeButton.getAttribute("aria-label")
  243.             .replace(/\D/g, "");
  244.         return likesStr.length > 0 ? parseInt(likesStr) : false;
  245.     }
  246.     catch {
  247.         return false;
  248.     }
  249.  
  250. }
  251.  
  252. (typeof GM_addStyle != "undefined"
  253.     ? GM_addStyle
  254.     : (styles) => {
  255.         let styleNode = document.createElement("style");
  256.         styleNode.type = "text/css";
  257.         styleNode.innerText = styles;
  258.         document.head.appendChild(styleNode);
  259.     })(`
  260.     #return-youtube-dislike-bar-container {
  261.       background: var(--yt-spec-icon-disabled);
  262.       border-radius: 2px;
  263.     }
  264.  
  265.     #return-youtube-dislike-bar {
  266.       background: var(--yt-spec-text-primary);
  267.       border-radius: 2px;
  268.       transition: all 0.15s ease-in-out;
  269.     }
  270.  
  271.     .ryd-tooltip {
  272.       position: relative;
  273.       display: block;
  274.       height: 2px;
  275.       top: 9px;
  276.     }
  277.  
  278.     .ryd-tooltip-bar-container {
  279.       width: 100%;
  280.       height: 2px;
  281.       position: absolute;
  282.       padding-top: 6px;
  283.       padding-bottom: 28px;
  284.       top: -6px;
  285.     }
  286.   `);
  287.  
  288. function createRateBar(likes, dislikes) {
  289.     if (isMobile) {
  290.         return;
  291.     }
  292.     let rateBar = document.getElementById("return-youtube-dislike-bar-container");
  293.  
  294.     const widthPx =
  295.         getButtons().children[0].clientWidth +
  296.         getButtons().children[1].clientWidth +
  297.         8;
  298.  
  299.     const widthPercent =
  300.         likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
  301.  
  302.     var likePercentage = parseFloat(widthPercent.toFixed(1));
  303.     const dislikePercentage = (100 - likePercentage).toLocaleString();
  304.     likePercentage = likePercentage.toLocaleString();
  305.  
  306.     var tooltipInnerHTML;
  307.     switch (extConfig.tooltipPercentageMode) {
  308.         case "dash_like":
  309.             tooltipInnerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}&nbsp;&nbsp;-&nbsp;&nbsp;${likePercentage}%`;
  310.             break;
  311.         case "dash_dislike":
  312.             tooltipInnerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}&nbsp;&nbsp;-&nbsp;&nbsp;${dislikePercentage}%`;
  313.             break;
  314.         case "both":
  315.             tooltipInnerHTML = `${likePercentage}%&nbsp;/&nbsp;${dislikePercentage}%`;
  316.             break;
  317.         case "only_like":
  318.             tooltipInnerHTML = `${likePercentage}%`;
  319.             break;
  320.         case "only_dislike":
  321.             tooltipInnerHTML = `${dislikePercentage}%`;
  322.             break;
  323.         default:
  324.             tooltipInnerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}`;
  325.     }
  326.  
  327.     if (!rateBar && !isMobile) {
  328.         let colorLikeStyle = "";
  329.         let colorDislikeStyle = "";
  330.         if (extConfig.coloredBar) {
  331.             colorLikeStyle = "; background-color: " + getColorFromTheme(true);
  332.             colorDislikeStyle = "; background-color: " + getColorFromTheme(false);
  333.         }
  334.  
  335.         document.getElementById("menu-container").insertAdjacentHTML(
  336.             "beforeend",
  337.             `
  338.         <div class="ryd-tooltip" style="width: ${widthPx}px">
  339.         <div class="ryd-tooltip-bar-container">
  340.            <div
  341.               id="return-youtube-dislike-bar-container"
  342.               style="width: 100%; height: 2px;${colorDislikeStyle}"
  343.               >
  344.               <div
  345.                  id="return-youtube-dislike-bar"
  346.                  style="width: ${widthPercent}%; height: 100%${colorDislikeStyle}"
  347.                  ></div>
  348.            </div>
  349.         </div>
  350.         <tp-yt-paper-tooltip position="top" id="ryd-dislike-tooltip" class="style-scope ytd-sentiment-bar-renderer" role="tooltip" tabindex="-1">
  351.            <!--css-build:shady-->${tooltipInnerHTML}
  352.         </tp-yt-paper-tooltip>
  353.         </div>
  354. `
  355.         );
  356.     } else {
  357.         document.getElementById(
  358.             "return-youtube-dislike-bar-container"
  359.         ).style.width = widthPx + "px";
  360.         document.getElementById("return-youtube-dislike-bar").style.width =
  361.             widthPercent + "%";
  362.  
  363.         document.querySelector("#ryd-dislike-tooltip > #tooltip").innerHTML =
  364.             tooltipInnerHTML;
  365.  
  366.         if (extConfig.coloredBar) {
  367.             document.getElementById(
  368.                 "return-youtube-dislike-bar-container"
  369.             ).style.backgroundColor = getColorFromTheme(false);
  370.             document.getElementById(
  371.                 "return-youtube-dislike-bar"
  372.             ).style.backgroundColor = getColorFromTheme(true);
  373.         }
  374.     }
  375. }
  376.  
  377. function setState() {
  378.     cLog("Fetching votes...");
  379.     let statsSet = false;
  380.  
  381.     fetch(
  382.         `https://returnyoutubedislikeapi.com/votes?videoId=${getVideoId()}`
  383.     ).then((response) => {
  384.         response.json().then((json) => {
  385.             if (json && !("traceId" in response) && !statsSet) {
  386.                 const { dislikes, likes } = json;
  387.                 cLog(`Received count: ${dislikes}`);
  388.                 // console.log(document.querySelector(".zetta1"))
  389.                 // if (!document.querySelector(".zetta1")) {
  390.                 //     document.querySelector(`#segmented-dislike-button .yt-spec-button-shape-next`).insertAdjacentHTML("beforeend", `<span class="zetta1">&nbsp;${numberFormat(dislikes)}</span>`)
  391.                 // }
  392.                 // else {
  393.                 //     document.querySelector(".zetta1").innerHTML = `&nbsp;${numberFormat(dislikes)}`
  394.                 // }
  395.                 // document.querySelector(`#segmented-dislike-button .yt-spec-button-shape-next`).style.width = "80px";
  396.                 likesvalue = likes;
  397.                 dislikesvalue = dislikes;
  398.                 setDislikes(numberFormat(dislikes));
  399.                 if (extConfig.numberDisplayReformatLikes === true) {
  400.                     const nativeLikes = getLikeCountFromButton();
  401.                     if (nativeLikes !== false) {
  402.                         setLikes(numberFormat(nativeLikes));
  403.                     }
  404.                 }
  405.                 createRateBar(likes, dislikes);
  406.                 if (extConfig.coloredThumbs === true) {
  407.                     if (isShorts()) {
  408.                         // for shorts, leave deactived buttons in default color
  409.                         let shortLikeButton = getLikeButton().querySelector(
  410.                             "tp-yt-paper-button#button"
  411.                         );
  412.                         let shortDislikeButton = getDislikeButton().querySelector(
  413.                             "tp-yt-paper-button#button"
  414.                         );
  415.                         if (shortLikeButton.getAttribute("aria-pressed") === "true") {
  416.                             shortLikeButton.style.color = getColorFromTheme(true);
  417.                         }
  418.                         if (shortDislikeButton.getAttribute("aria-pressed") === "true") {
  419.                             shortDislikeButton.style.color = getColorFromTheme(false);
  420.                         }
  421.                         mutationObserver.observer.observe(
  422.                             shortLikeButton,
  423.                             mutationObserver.options
  424.                         );
  425.                         mutationObserver.observer.observe(
  426.                             shortDislikeButton,
  427.                             mutationObserver.options
  428.                         );
  429.                     } else {
  430.                         getLikeButton().style.color = getColorFromTheme(true);
  431.                         getDislikeButton().style.color = getColorFromTheme(false);
  432.                     }
  433.                 }
  434.             }
  435.         });
  436.     });
  437. }
  438.  
  439. function likeClicked() {
  440.     if (checkForUserAvatarButton() == true) {
  441.         if (previousState == 1) {
  442.             likesvalue--;
  443.             createRateBar(likesvalue, dislikesvalue);
  444.             setDislikes(numberFormat(dislikesvalue));
  445.             previousState = 3;
  446.         } else if (previousState == 2) {
  447.             likesvalue++;
  448.             dislikesvalue--;
  449.             setDislikes(numberFormat(dislikesvalue));
  450.             createRateBar(likesvalue, dislikesvalue);
  451.             previousState = 1;
  452.         } else if (previousState == 3) {
  453.             likesvalue++;
  454.             createRateBar(likesvalue, dislikesvalue);
  455.             previousState = 1;
  456.         }
  457.         if (extConfig.numberDisplayReformatLikes === true) {
  458.             const nativeLikes = getLikeCountFromButton();
  459.             if (nativeLikes !== false) {
  460.                 setLikes(numberFormat(nativeLikes));
  461.             }
  462.         }
  463.     }
  464. }
  465.  
  466. function dislikeClicked() {
  467.     if (checkForUserAvatarButton() == true) {
  468.         if (previousState == 3) {
  469.             dislikesvalue++;
  470.             setDislikes(numberFormat(dislikesvalue));
  471.             createRateBar(likesvalue, dislikesvalue);
  472.             previousState = 2;
  473.         } else if (previousState == 2) {
  474.             dislikesvalue--;
  475.             setDislikes(numberFormat(dislikesvalue));
  476.             createRateBar(likesvalue, dislikesvalue);
  477.             previousState = 3;
  478.         } else if (previousState == 1) {
  479.             likesvalue--;
  480.             dislikesvalue++;
  481.             setDislikes(numberFormat(dislikesvalue));
  482.             createRateBar(likesvalue, dislikesvalue);
  483.             previousState = 2;
  484.             if (extConfig.numberDisplayReformatLikes === true) {
  485.                 const nativeLikes = getLikeCountFromButton();
  486.                 if (nativeLikes !== false) {
  487.                     setLikes(numberFormat(nativeLikes));
  488.                 }
  489.             }
  490.         }
  491.     }
  492. }
  493.  
  494. function setInitialState() {
  495.     setState();
  496. }
  497.  
  498. function getVideoId() {
  499.     const urlObject = new URL(window.location.href);
  500.     const pathname = urlObject.pathname;
  501.     if (pathname.startsWith("/clip")) {
  502.         return document.querySelector("meta[itemprop='videoId']").content;
  503.     } else {
  504.         if (pathname.startsWith("/shorts")) {
  505.             return pathname.slice(8);
  506.         }
  507.         return urlObject.searchParams.get("v");
  508.     }
  509. }
  510.  
  511. function isVideoLoaded() {
  512.     if (isMobile) {
  513.         return document.getElementById("player").getAttribute("loading") == "false";
  514.     }
  515.     const videoId = getVideoId();
  516.  
  517.     return (
  518.         document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
  519.     );
  520. }
  521.  
  522. function roundDown(num) {
  523.     if (num < 1000) return num;
  524.     const int = Math.floor(Math.log10(num) - 2);
  525.     const decimal = int + (int % 3 ? 1 : 0);
  526.     const value = Math.floor(num / 10 ** decimal);
  527.     return value * 10 ** decimal;
  528. }
  529.  
  530. function numberFormat(numberState) {
  531.     let numberDisplay;
  532.     if (extConfig.numberDisplayRoundDown === false) {
  533.         numberDisplay = numberState;
  534.     } else {
  535.         numberDisplay = roundDown(numberState);
  536.     }
  537.     return getNumberFormatter(extConfig.numberDisplayFormat).format(
  538.         numberDisplay
  539.     );
  540. }
  541.  
  542. function getNumberFormatter(optionSelect) {
  543.     let userLocales;
  544.     if (document.documentElement.lang) {
  545.         userLocales = document.documentElement.lang;
  546.     } else if (navigator.language) {
  547.         userLocales = navigator.language;
  548.     } else {
  549.         try {
  550.             userLocales = new URL(
  551.                 Array.from(document.querySelectorAll("head > link[rel='search']"))
  552.                     ?.find((n) => n?.getAttribute("href")?.includes("?locale="))
  553.                     ?.getAttribute("href")
  554.             )?.searchParams?.get("locale");
  555.         } catch {
  556.             cLog(
  557.                 "Cannot find browser locale. Use en as default for number formatting."
  558.             );
  559.             userLocales = "en";
  560.         }
  561.     }
  562.  
  563.     let formatterNotation;
  564.     let formatterCompactDisplay;
  565.     switch (optionSelect) {
  566.         case "compactLong":
  567.             formatterNotation = "compact";
  568.             formatterCompactDisplay = "long";
  569.             break;
  570.         case "standard":
  571.             formatterNotation = "standard";
  572.             formatterCompactDisplay = "short";
  573.             break;
  574.         case "compactShort":
  575.         default:
  576.             formatterNotation = "compact";
  577.             formatterCompactDisplay = "short";
  578.     }
  579.  
  580.     const formatter = Intl.NumberFormat(userLocales, {
  581.         notation: formatterNotation,
  582.         compactDisplay: formatterCompactDisplay,
  583.     });
  584.     return formatter;
  585. }
  586.  
  587. function getColorFromTheme(voteIsLike) {
  588.     let colorString;
  589.     switch (extConfig.colorTheme) {
  590.         case "accessible":
  591.             if (voteIsLike === true) {
  592.                 colorString = "dodgerblue";
  593.             } else {
  594.                 colorString = "gold";
  595.             }
  596.             break;
  597.         case "neon":
  598.             if (voteIsLike === true) {
  599.                 colorString = "aqua";
  600.             } else {
  601.                 colorString = "magenta";
  602.             }
  603.             break;
  604.         case "classic":
  605.         default:
  606.             if (voteIsLike === true) {
  607.                 colorString = "lime";
  608.             } else {
  609.                 colorString = "red";
  610.             }
  611.     }
  612.     return colorString;
  613. }
  614.  
  615. function setEventListeners(evt) {
  616.     let jsInitChecktimer;
  617.  
  618.     function checkForJS_Finish() {
  619.         console.log();
  620.         if (isShorts() || (getButtons()?.offsetParent && isVideoLoaded())) {
  621.             const buttons = getButtons();
  622.  
  623.             if (!window.returnDislikeButtonlistenersSet) {
  624.                 cLog("Registering button listeners...");
  625.                 try {
  626.                     buttons.children[0].addEventListener("click", likeClicked);
  627.                     buttons.children[1].addEventListener("click", dislikeClicked);
  628.                     buttons.children[0].addEventListener("touchstart", likeClicked);
  629.                     buttons.children[1].addEventListener("touchstart", dislikeClicked);
  630.                     document.querySelector(`#segmented-dislike-button`).addEventListener("click", dislikeClicked)
  631.                 } catch {
  632.                     return;
  633.                 } //Don't spam errors into the console
  634.                 window.returnDislikeButtonlistenersSet = true;
  635.             }
  636.             setInitialState();
  637.             clearInterval(jsInitChecktimer);
  638.         }
  639.     }
  640.  
  641.     cLog("Setting up...");
  642.     jsInitChecktimer = setInterval(checkForJS_Finish, 111);
  643. }
  644.  
  645. (function () {
  646.     "use strict";
  647.     window.addEventListener("yt-navigate-finish", setEventListeners, true);
  648.     setEventListeners();
  649. })();
  650. if (isMobile) {
  651.     let originalPush = history.pushState;
  652.     history.pushState = function (...args) {
  653.         window.returnDislikeButtonlistenersSet = false;
  654.         setEventListeners(args[2]);
  655.         return originalPush.apply(history, args);
  656.     };
  657.     setInterval(() => {
  658.         getDislikeButton().querySelector(".button-renderer-text").innerText =
  659.             mobileDislikes;
  660.     }, 1000);
  661. }
  662.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement