Custom Image for Youtube Background

Replace the old boring flat background with whatever picture you like

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

  1. // ==UserScript==
  2. // @name Custom Image for Youtube Background
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  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. (function () {
  14. 'use strict';
  15.  
  16. // Fill the array up with URLs to pictures
  17. const bgSources = [
  18. "https://i.kym-cdn.com/photos/images/original/000/581/296/c09.jpg",
  19. "https://i.kym-cdn.com/photos/images/original/000/581/296/c09.jpg"
  20. ]
  21.  
  22. function getRandomImageUrl(images) {
  23. const randomIndex = Math.floor(Math.random() * images.length);
  24. return images[randomIndex];
  25. }
  26.  
  27. // Select only one image from the array
  28. let bgImage = getRandomImageUrl(bgSources);
  29.  
  30. let css = `
  31. background-image: url(${bgImage});
  32. background-attachment: fixed;
  33. background-size: cover;
  34. background-repeat: no-repeat;
  35. background-position: center;
  36. `;
  37.  
  38. // Find the first #content div and apply the style
  39. const firstContentDiv = document.querySelector("#content");
  40. if (firstContentDiv) {
  41. firstContentDiv.style.cssText += css;
  42. }
  43.  
  44. let css2 = `
  45. #guide,#chips-wrapper{
  46. opacity: 0.9;
  47. }
  48. #cinematics-container{
  49. display: none;
  50. }
  51. `;
  52. if (typeof GM_addStyle !== "undefined") {
  53. GM_addStyle(css2);
  54. } else {
  55. let styleNode = document.createElement("style");
  56. styleNode.appendChild(document.createTextNode(css2));
  57. (document.querySelector("head") || document.documentElement).appendChild(styleNode);
  58. }
  59. })();