Youtube Custom Font

Applies a custom font, Vazirmatn, to all text elements on the current web page (YouTube).

  1. // ==UserScript==
  2. // @name Youtube Custom Font
  3. // @version 0.1.1
  4. // @author Amm1rr
  5. // @description Applies a custom font, Vazirmatn, to all text elements on the current web page (YouTube).
  6. // @homepage https://github.com/Amm1rr/
  7. // @namespace amm1rr.youtube.custom.font
  8. // @match https://*.youtube.*/*
  9. // @icon https://cdn.jsdelivr.net/gh/Amm1rr/Userscripts@main/Youtube-Custom-Font/Icon.png
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. // Description:
  15. // This script injects a small "bubble float button" on the top left corner of the YouTube page.
  16. // Clicking the button applies a custom font, Vazirmatn, to all text elements on the webpage.
  17. // You can customize the font family and element selector to your preference.
  18.  
  19. (function () {
  20. // Configuration object for easy customization
  21. const config = {
  22. fontFamily: "Vazirmatn",
  23. // selector: ".style-scope", //Youtube Class
  24. selector: "*",
  25. buttonID: "yt-custom-font",
  26. buttonText: "A",
  27. notificationDuration: 2000,
  28. buttonFadeDuration: 2000,
  29. notificationMessage: "Fonts updated: Vazirmatn font applied.",
  30. buttonTooltip: "Enhance readability with Vazirmatn font",
  31. };
  32.  
  33. if (document.getElementById(config.buttonID)) {
  34. console.log(
  35. "Custom Font: " + config.buttonID + " button already exists.\n bye bye()"
  36. );
  37. // console.log("Custom Font: bye bye()");
  38. return;
  39. }
  40.  
  41. // Apply custom font to selected elements
  42. function applyCustomFont(selector, fontFamily) {
  43. const style = document.createElement("style");
  44. style.textContent = `${selector} * {font-family: ${fontFamily} !important;}`;
  45. document.head.appendChild(style);
  46. }
  47.  
  48. // Show notification with fade effect
  49. function showNotification(message, duration) {
  50. const notification = document.createElement("div");
  51. Object.assign(notification.style, {
  52. position: "fixed",
  53. bottom: "80%",
  54. left: "50%",
  55. transform: "translateX(-50%)",
  56. padding: "10px 20px",
  57. backgroundColor: "rgba(0, 123, 255, 0.8)",
  58. color: "yellow",
  59. borderRadius: "5px",
  60. boxShadow: "0 2px 5px rgba(0,0,0,0.2)",
  61. zIndex: "10000",
  62. opacity: "0",
  63. transition: "opacity 0.5s ease",
  64. textAlign: "center",
  65. });
  66. notification.textContent = message;
  67. document.body.appendChild(notification);
  68.  
  69. requestAnimationFrame(() => {
  70. notification.style.opacity = "1";
  71. });
  72.  
  73. setTimeout(() => {
  74. notification.style.opacity = "0";
  75. notification.addEventListener(
  76. "transitionend",
  77. () => notification.remove(),
  78. { once: true }
  79. );
  80. }, duration);
  81. }
  82.  
  83. // Create and add font change button
  84. function addFontChangeButton() {
  85. const button = document.createElement("button");
  86. button.id = config.buttonID;
  87. button.textContent = config.buttonText;
  88. button.title = config.buttonTooltip;
  89.  
  90. const buttonStyle = {
  91. position: "fixed",
  92. top: "10px",
  93. left: "3px",
  94. zIndex: "9999",
  95. width: "20px",
  96. height: "20px",
  97. borderRadius: "50%",
  98. backgroundColor: "rgba(123, 110, 242, 0.3)",
  99. color: "#FFFFFF",
  100. border: "none",
  101. fontWeight: "bold",
  102. fontFamily: "Arial",
  103. cursor: "pointer",
  104. boxShadow: "0 2px 5px rgba(0,0,0,0.3)",
  105. transition: "background-color 0.3s ease, opacity 0.3s ease",
  106. };
  107. Object.assign(button.style, buttonStyle);
  108.  
  109. function setButtonHoverState(isHover) {
  110. if (!button.disabled) {
  111. button.style.backgroundColor = isHover
  112. ? "rgba(123, 110, 242, 0.8)"
  113. : "rgba(123, 110, 242, 0.3)";
  114. }
  115. }
  116.  
  117. button.addEventListener("mouseenter", () => setButtonHoverState(true));
  118. button.addEventListener("mousemove", () => setButtonHoverState(true));
  119. button.addEventListener("mouseover", () => setButtonHoverState(true));
  120. button.addEventListener("mouseleave", () => setButtonHoverState(false));
  121.  
  122. button.addEventListener("click", () => {
  123. button.disabled = true;
  124. button.style.cursor = "default";
  125. button.style.backgroundColor = "rgba(123, 110, 242, 0.3)";
  126.  
  127. applyCustomFont(config.selector, config.fontFamily);
  128. showNotification(config.notificationMessage, config.notificationDuration);
  129.  
  130. button.style.opacity = "0";
  131. setTimeout(() => {
  132. button.disabled = false;
  133. button.style.cursor = "pointer";
  134. button.style.opacity = "1";
  135. }, config.buttonFadeDuration);
  136. });
  137.  
  138. document.body.appendChild(button);
  139.  
  140. function handleFullscreenChange() {
  141. const isFullscreen = !!document.fullscreenElement;
  142. button.style.opacity = isFullscreen ? "0" : "1";
  143. button.style.pointerEvents = isFullscreen ? "none" : "auto";
  144. }
  145.  
  146. document.addEventListener("fullscreenchange", handleFullscreenChange);
  147. document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
  148. }
  149.  
  150. // Initialize the font change functionality
  151. addFontChangeButton();
  152. })();

QingJ © 2025

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