Watch9 Reconstruct

Restores the classic Watch page layout from before 2019

当前为 2022-07-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Watch9 Reconstruct
  3. // @version 1.1.2
  4. // @description Restores the classic Watch page layout from before 2019
  5. // @author Aubrey
  6. // @namespace aubymori
  7. // @match https://www.youtube.com/*
  8. // @license MIT
  9. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. // ok, i'm saying it now.
  15. // do not expect much updates of this script.
  16. // i have better things to do
  17.  
  18. async function waitForElm(q) {
  19. while (document.querySelector(q) == null) {
  20. await new Promise(r => requestAnimationFrame(r));
  21. };
  22. return document.querySelector(q);
  23. };
  24.  
  25. const w9rStyle = document.createElement("style");
  26. w9rStyle.innerHTML = `
  27. #w9r-sub-count {
  28. opacity: .8;
  29. margin-left: 6px;
  30. }
  31.  
  32. #info-strings.ytd-video-primary-info-renderer,
  33. #owner-sub-count {
  34. display: none !important;
  35. }
  36. `;
  37. document.getElementsByTagName("head")[0].appendChild(w9rStyle);
  38.  
  39. document.addEventListener("yt-page-data-updated", async function() {
  40. var pubDate = await waitForElm("ytd-video-primary-info-renderer");
  41. const pubDatePnt = pubDate.data.dateText.simpleText;
  42. function fixPubDate(date) {
  43. if (/(Premier)|(Stream)|(Start)/.test(date)) {
  44. return date;
  45. } else {
  46. return "Published on " + date;
  47. }
  48. }
  49. var subCnt = await waitForElm("ytd-video-secondary-info-renderer");
  50. const subCntPnt = subCnt.data.owner.videoOwnerRenderer.subscriberCountText.simpleText;
  51. function fixSubCnt(cnt) {
  52. return cnt.replace(/( subscribers)|( subscriber)/, "").replace("No", "0");
  53. }
  54. var subBtn = await waitForElm("#subscribe-button tp-yt-paper-button");
  55. var pubDateElm = await waitForElm(".date.ytd-video-secondary-info-renderer");
  56. var viewCount = await waitForElm("ytd-video-view-count-renderer");
  57. if (document.querySelector("#w9r-sub-count") == null) {
  58. var w9rSubCount = document.createElement("yt-formatted-string");
  59. w9rSubCount.text = {runs:[{text: subCntPnt.replace(/( subscribers)|( subscriber)/, "").replace("No", "0")}]};
  60. w9rSubCount.id = "w9r-sub-count";
  61. subBtn.querySelector("yt-formatted-string").insertAdjacentElement("afterEnd", w9rSubCount)
  62. } else {
  63. document.querySelector("#w9r-sub-count").text = {simpleText:fixSubCnt(subCntPnt)};//{runs:[{text: fixSubCnt(subCntPnt)}]};
  64. };
  65.  
  66. viewCount.removeAttribute("small");
  67. pubDateElm.innerHTML = fixPubDate(pubDatePnt);
  68. });