Custom Image for Youtube Background

Replace the old boring flat background with whatever picture you like

当前为 2024-07-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Custom Image for Youtube Background
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Replace the old boring flat background with whatever picture you like
  6. // @author Hoover
  7. // @match *://*.youtube.com/*
  8. // @grant none
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13.  
  14. // Only tested on dark mode. If you're using light mode, you're a lunatic.
  15.  
  16. (function () {
  17. 'use strict';
  18.  
  19. // Fill the array up with URLs to pictures
  20. const bgSources = [
  21. "https://i.kym-cdn.com/photos/images/original/000/581/296/c09.jpg",
  22. "https://i.kym-cdn.com/photos/images/original/000/581/296/c09.jpg"
  23. ]
  24.  
  25. function getRandomImageUrl(images) {
  26. const randomIndex = Math.floor(Math.random() * images.length);
  27. return images[randomIndex];
  28. }
  29.  
  30. // Select only one image from the array
  31. let bgImage = getRandomImageUrl(bgSources);
  32.  
  33. let css = `
  34. background-image: url(${bgImage});
  35. background-attachment: fixed;
  36. background-size: cover;
  37. background-repeat: no-repeat;
  38. background-position: center;
  39. `;
  40.  
  41. // Find the first #content div and apply the background style
  42. const firstContentDiv = document.querySelector("#content");
  43. if (firstContentDiv) {
  44. firstContentDiv.style.cssText += css;
  45. }
  46.  
  47. // Overriding and adding css styles
  48. let css2 = `
  49. html[dark],
  50. [dark] {
  51. --yt-spec-base-background:#0f0f0fbf;
  52. }
  53. #cinematics-container{
  54. display: none;
  55. }
  56. `;
  57. if (typeof GM_addStyle !== "undefined") {
  58. GM_addStyle(css2);
  59. } else {
  60. let styleNode = document.createElement("style");
  61. styleNode.appendChild(document.createTextNode(css2));
  62. (document.querySelector("head") || document.documentElement).appendChild(styleNode);
  63. }
  64. })();