ACT.Youtube.MO.Embed-button

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

当前为 2022-03-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ACT.Youtube.MO.Embed-button
  3. // @description Go to Embed page to uses auto-translate on in-page fullscreen player, for mobile users.
  4. // @author ACTCD
  5. // @version 20220323.1
  6. // @license GPL-3.0-or-later
  7. // @namespace ACTCD/Userscripts
  8. // @supportURL https://github.com/ACTCD/Userscripts#contact
  9. // @homepageURL https://github.com/ACTCD/Userscripts
  10. // @match *://m.youtube.com/*
  11. // @match *://www.youtube-nocookie.com/embed/*
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. 'use strict';
  18.  
  19. const button = document.createElement("button");
  20. button.id = "ACT_Embed";
  21. button.innerText = "Embed";
  22. button.style.setProperty('color', 'white');
  23. button.style.setProperty('background-color', 'transparent');
  24. button.style.setProperty('border', '2px solid');
  25. button.style.setProperty('border-radius', '10px');
  26. button.style.setProperty('padding', '1px 5px');
  27. button.style.setProperty('font-size', '1.5em');
  28. button.style.setProperty('font-weight', '500');
  29. button.style.setProperty('text-shadow', 'black 1px 1px 2px');
  30. button.addEventListener('click', event => {
  31. let vid = new URL(location).searchParams.get('v');
  32. if (!vid) return;
  33. 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');
  34. url.pathname = '/embed/' + vid;
  35. location.href = url;
  36. event.preventDefault();
  37. event.stopImmediatePropagation();
  38. });
  39.  
  40. function insert_button() {
  41. if (location.hostname != 'm.youtube.com') return;
  42. if (location.pathname != '/watch') return;
  43. if (button.parentNode) return;
  44. document.querySelector('.mobile-topbar-header-endpoint')?.insertAdjacentElement("afterend", button);
  45. console.log('insert_button');
  46. }
  47.  
  48. function tweak() {
  49. insert_button()
  50. document.querySelector('.ytp-fullscreen-button')?.remove();
  51. }
  52.  
  53. new MutationObserver(tweak).observe(document, { subtree: true, childList: true });
  54.  
  55. function web_app() {
  56. const meta = document.createElement('meta');
  57. meta.name = 'apple-mobile-web-app-capable';
  58. meta.setAttribute('content', 'yes');
  59. document.head.appendChild(meta);
  60. }
  61.  
  62. function WindowLoaded() {
  63. console.log('WindowLoaded');
  64. tweak();
  65. if (location.pathname.startsWith('/embed/')) web_app();
  66. }
  67.  
  68. if (document.readyState === 'complete') {
  69. WindowLoaded();
  70. } else {
  71. window.addEventListener('load', WindowLoaded);
  72. }
  73.  
  74. })();