Return YouTube Dislike

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

当前为 2023-12-13 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址