ACT.YouTube.MO.转到嵌入页按钮

一键转到嵌入式页面以在页面内全屏播放器上使用字幕自动翻译菜单,供手机用户使用。

目前为 2022-04-18 提交的版本。查看 最新版本

  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 20220419.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. // @run-at document-start
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20.  
  21. const button = document.createElement("button");
  22. button.id = "ACT_Embed";
  23. button.innerText = "Embed";
  24. button.style.setProperty('color', 'white');
  25. button.style.setProperty('background-color', 'transparent');
  26. button.style.setProperty('border', '2px solid');
  27. button.style.setProperty('border-radius', '10px');
  28. button.style.setProperty('padding', '1px 5px');
  29. button.style.setProperty('font-size', '1.5em');
  30. button.style.setProperty('font-weight', '500');
  31. button.style.setProperty('text-shadow', 'black 1px 1px 2px');
  32. button.addEventListener('click', event => {
  33. let vid = new URL(location).searchParams.get('v');
  34. if (!vid) return;
  35. let url = new URL('https://www.youtube-nocookie.com/embed/?autoplay=1&cc_lang_pref=zh&cc_load_policy=1&hl=zh&modestbranding=1&tlang=zh-Hans');
  36. url.pathname = '/embed/' + vid;
  37. location.href = url;
  38. event.preventDefault();
  39. event.stopImmediatePropagation();
  40. }, true);
  41.  
  42. function insert_button() {
  43. if (location.hostname != 'm.youtube.com') return;
  44. if (location.pathname != '/watch') return;
  45. if (button.parentNode) return;
  46. document.querySelector('ytm-home-logo','.mobile-topbar-header-endpoint')?.after(button);
  47. console.log('insert_button');
  48. }
  49.  
  50. function tweak() {
  51. insert_button()
  52. document.querySelector('.ytp-fullscreen-button')?.remove();
  53. }
  54.  
  55. new MutationObserver(tweak).observe(document, { subtree: true, childList: true });
  56.  
  57. function web_app() {
  58. const meta = document.createElement('meta');
  59. meta.name = 'apple-mobile-web-app-capable';
  60. meta.setAttribute('content', 'yes');
  61. document.head.appendChild(meta);
  62. }
  63.  
  64. function WindowLoaded() {
  65. console.log('WindowLoaded');
  66. tweak();
  67. location.pathname.startsWith('/embed/') && web_app();
  68. }
  69.  
  70. if (document.readyState === 'complete') {
  71. WindowLoaded();
  72. } else {
  73. window.addEventListener('load', WindowLoaded);
  74. }
  75.  
  76. })();

QingJ © 2025

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