Return YouTube Dislike

Return of the YouTube Dislike, Based off https://www.returnyoutubedislike.com/

安装此脚本?
作者推荐脚本

你可能也喜欢 Dark Mode

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