Youtube plus

Small CSS tweaks to youtube with color theme settings

目前为 2024-03-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube plus
  3. // @description Small CSS tweaks to youtube with color theme settings
  4. // @grant GM_addStyle
  5. // @include *://youtube.com/*
  6. // @include *://www.youtube.com/*
  7. // @run-at document-start
  8. // @version 3.5
  9. // @namespace https://greasyfork.org/users/3167
  10. // ==/UserScript==
  11.  
  12. var defaultcolor = "hsla(3, 60%, 47%, 1)";
  13.  
  14. var customcolor = defaultcolor;
  15.  
  16. var firstrun = false;
  17.  
  18. if (typeof(Storage) !== "undefined") {
  19. if (localStorage.yt_custom_color) {
  20. customcolor = localStorage.yt_custom_color;
  21. } else {
  22. firstrun = true;
  23. localStorage.yt_custom_color = customcolor;
  24. }
  25. }
  26.  
  27. console.log("yt_custom_color", customcolor);
  28.  
  29. var stylesheet = `
  30. body {
  31. /* --yt-custom-color: " + customcolor + "; */
  32. }
  33. .ytp-pause-overlay {
  34. display: none;
  35. }
  36. #player-ads { display: none; }
  37. body,
  38. ytd-app {
  39. --yt-brand-paper-button-color: var(--yt-custom-color) !important;
  40. --yt-brand-color: var(--yt-custom-color) !important;
  41. }
  42. paper-button.style-scope.ytd-subscribe-button-renderer,
  43. paper-button.ytd-subscribe-button-renderer {
  44. background-color: var(--yt-custom-color);
  45. }
  46. paper-button.style-scope.ytd-subscribe-button-renderer[subscribed] {
  47. background-color: var(--yt-spec-10-percent-layer);
  48. }
  49. ytd-guide-entry-renderer[active] path.style-scope.yt-icon {
  50. color: var(--yt-custom-color) !important;
  51. }
  52. #progress.yt-page-navigation-progress,
  53. #progress.ytd-thumbnail-overlay-resume-playback-renderer,
  54. .ytp-red2 .ytp-swatch-background-color,
  55. .ytp-red2 .ytp-swatch-background-color-secondary,
  56. .ytp-play-progress.ytp-swatch-background-color,
  57. .ytp-swatch-background-color-secondary,
  58. .ytp-scrubber-button.ytp-swatch-background-color {
  59. background-color: var(--yt-custom-color) !important;
  60. }
  61. path#lozenge-path,
  62. path.style-scope.ytd-topbar-logo-renderer {
  63. fill: var(--yt-custom-color);
  64. }
  65. div#top div#player {
  66. max-height: calc(100vh - var(--ytd-masthead-height, 56px));
  67. }
  68. `;
  69.  
  70.  
  71.  
  72. var setcustomcolor = function (colorinput) {
  73. console.log("Changing color theme to: " + colorinput);
  74. customcolor = colorinput;
  75. document.body.style.setProperty('--yt-custom-color', customcolor);
  76.  
  77. localStorage.yt_custom_color = customcolor;
  78.  
  79. var savedcolor = localStorage.yt_custom_color;
  80. console.log("Saved color theme: " + savedcolor);
  81. }
  82. unsafeWindow.setcustomcolor = setcustomcolor;
  83.  
  84. var pickcustomcolor = function () {
  85. console.log("click");
  86. customcolorpicker.click();
  87. }
  88. unsafeWindow.pickcustomcolor = pickcustomcolor;
  89.  
  90. var resetcustomcolor = function () {
  91. unsafeWindow.setcustomcolor(defaultcolor);
  92. }
  93. unsafeWindow.resetcustomcolor = resetcustomcolor;
  94.  
  95. var video_emitkey = function(keycode) {
  96. var video_element = document.getElementById("movie_player");
  97. if (video_element) {
  98. var ke = new KeyboardEvent('keydown');
  99. delete ke.keyCode;
  100. Object.defineProperty(ke, "keyCode", {"value" : keycode});
  101. video_element.dispatchEvent(ke);
  102. }
  103. }
  104.  
  105. var volumecontrol_init = function() {
  106. var video_player = document.getElementById("ytd-player");
  107. if (video_player) {
  108.  
  109. if (!video_player.youtubeplus_wheel_hooked) {
  110. video_player.addEventListener('wheel', function(e) {
  111. e.preventDefault();
  112. if (e.deltaY < 0) {
  113. video_emitkey(38);
  114. }
  115. if (e.deltaY > 0) {
  116. video_emitkey(40);
  117. }
  118. });
  119. video_player.youtubeplus_wheel_hooked = true;
  120. }
  121. }
  122. }
  123.  
  124. var redirectshorts_init = function() {
  125. if (location.href.includes("/shorts/")){
  126. let redirect_url = location.href.replace("/shorts/", "/watch?v=");
  127. console.log("Shorts detected, redirecting to: " + redirect_url);
  128. window.location.href = redirect_url;
  129. }
  130. }
  131.  
  132. var init = function() {
  133. if (typeof GM_addStyle != "undefined") {
  134. GM_addStyle (stylesheet);
  135. } else {
  136. var css = document.createElement("style");
  137. css.type = "text/css";
  138. css.innerHTML = stylesheet;
  139. document.head.appendChild(css);
  140. }
  141.  
  142. var customcolorpicker = document.createElement('input');
  143. customcolorpicker.type = "color";
  144. customcolorpicker.onchange = "setcustomcolor(this.value);";
  145. customcolorpicker.style = "display: none;";
  146. customcolorpicker.addEventListener("change", function() {
  147. setcustomcolor(this.value);
  148.  
  149. });
  150. redirectshorts_init();
  151. setcustomcolor(customcolor);
  152. volumecontrol_init();
  153. mutator_init();
  154. console.log("Youtube++ init!");
  155. }
  156.  
  157. var mutator_callback = function() {
  158. //console.log("Mutation detected...");
  159. volumecontrol_init();
  160. mutator_init();
  161. }
  162.  
  163. var mutator_init = function() {
  164. var targetNode = document.body;
  165. if (targetNode && !targetNode.youtubeplus_mutator_hooked) {
  166. var observer = new MutationObserver(mutator_callback);
  167. observer.observe(targetNode, { childList: true });
  168. targetNode.youtubeplus_mutator_hooked = true;
  169. }
  170. }
  171.  
  172. if (typeof unsafeWindow.Request_OLD == "undefined") {
  173. var Request_OLD = unsafeWindow.Request;
  174. class Request extends Request_OLD {
  175. constructor(a,b) {
  176. b = b || {};
  177. b.credentials = b.credentials || "same-origin";
  178. super(a,b)
  179. }
  180. }
  181. unsafeWindow.Request = Request;
  182. }
  183.  
  184. console.log("Youtube++ loaded!");
  185.  
  186. document.addEventListener("DOMContentLoaded", function(event) {
  187. init();
  188. console.log("Youtube++ init!");
  189. });
  190.