Greasy Fork is available in English.

ACT.YouTube.MO.Embed-button

Go to Embed page to uses Subtitles/CC auto-translate menu on in-page fullscreen player, for mobile users.

  1. // ==UserScript==
  2. // @name ACT.YouTube.MO.Embed-button
  3. // @name:zh-CN ACT.YouTube.MO.转到嵌入页按钮
  4. // @description Go to Embed page to uses Subtitles/CC auto-translate menu on in-page fullscreen player, for mobile users.
  5. // @description:zh-CN 一键转到嵌入式页面以在页面内全屏播放器上使用字幕自动翻译菜单,供手机用户使用。
  6. // @author ACTCD
  7. // @version 20220722.1
  8. // @license GPL-3.0-or-later
  9. // @namespace ACTCD/Userscripts
  10. // @supportURL https://github.com/ACTCD/Userscripts#contact
  11. // @homepageURL https://github.com/ACTCD/Userscripts
  12. // @match *://m.youtube.com/*
  13. // @match *://www.youtube-nocookie.com/embed/*
  14. // @grant none
  15. // @inject-into content
  16. // @run-at document-start
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. "use strict";
  21.  
  22. const button = document.createElement("button");
  23. button.id = "ACT_Embed";
  24. button.innerText = "Embed";
  25. button.style.setProperty("color", "white");
  26. button.style.setProperty("background-color", "transparent");
  27. button.style.setProperty("border", "2px solid");
  28. button.style.setProperty("border-radius", "10px");
  29. button.style.setProperty("padding", "1px 5px");
  30. button.style.setProperty("font-size", "1.5em");
  31. button.style.setProperty("font-weight", "500");
  32. button.style.setProperty("text-shadow", "black 1px 1px 2px");
  33. button.addEventListener(
  34. "click",
  35. (event) => {
  36. let vid = new URL(location).searchParams.get("v");
  37. if (!vid) return;
  38. let url = new URL(
  39. "https://www.youtube-nocookie.com/embed/?autoplay=1&cc_lang_pref=zh&cc_load_policy=1&hl=zh&modestbranding=1&tlang=zh-Hans",
  40. );
  41. url.pathname = "/embed/" + vid;
  42. location.href = url;
  43. event.preventDefault();
  44. event.stopImmediatePropagation();
  45. },
  46. true,
  47. );
  48.  
  49. function insert_button() {
  50. if (location.hostname != "m.youtube.com") return;
  51. if (location.pathname != "/watch") return;
  52. if (button.parentNode) return;
  53. document
  54. .querySelector("ytm-home-logo", ".mobile-topbar-header-endpoint")
  55. ?.after(button);
  56. console.log("insert_button");
  57. }
  58.  
  59. function tweak() {
  60. insert_button();
  61. document.querySelector(".ytp-fullscreen-button")?.remove();
  62. }
  63.  
  64. new MutationObserver(tweak).observe(document, {
  65. subtree: true,
  66. childList: true,
  67. });
  68.  
  69. function web_app() {
  70. const meta = document.createElement("meta");
  71. meta.name = "apple-mobile-web-app-capable";
  72. meta.setAttribute("content", "yes");
  73. document.head.appendChild(meta);
  74. }
  75.  
  76. function WindowLoaded() {
  77. console.log("WindowLoaded");
  78. tweak();
  79. location.pathname.startsWith("/embed/") && web_app();
  80. }
  81.  
  82. if (document.readyState === "complete") {
  83. WindowLoaded();
  84. } else {
  85. window.addEventListener("load", WindowLoaded);
  86. }
  87. })();