m.YouTube.com add PIP picture in picture pop-out button

Adds a pop out to PIP button to m.YouTube.com

目前为 2024-02-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name m.YouTube.com add PIP picture in picture pop-out button
  3. // @namespace m-youtube-com-pip-button
  4. // @version 1.0
  5. // @description Adds a pop out to PIP button to m.YouTube.com
  6. // @author hlorand.hu
  7. // @match https://m.youtube.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
  9. // @grant none
  10. // @license https://creativecommons.org/licenses/by-nc-sa/4.0/
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. //'use strict';
  16. function addbutton(){
  17. document.getElementById("pipbutton").innerHTML = "";
  18.  
  19. let button = document.createElement('button');
  20. button.textContent = "PIP";
  21. button.className = "speedbutton";
  22.  
  23. button.style.margin = "4px";
  24. button.style.padding = "4px";
  25.  
  26. button.style.backgroundColor = "brown";
  27. button.style.position = "relative";
  28.  
  29. button.onclick = function() {
  30. let video = document.querySelector("video");
  31. video.requestPictureInPicture();
  32. };
  33.  
  34. let target = document.getElementById("pipbutton");
  35. target.insertBefore(button, target.firstChild);
  36.  
  37.  
  38. } // end addbuttons
  39.  
  40. // Periodically check if the buttons are visible
  41. // (sometimes YouTube redraws its interface).
  42. setInterval(()=>{
  43. // Creating a div that will contain buttons.
  44. if( document.getElementById("pipbutton") == undefined ){
  45. let parent = document.querySelector('.related-chips-slot-wrapper'); // placement of buttons
  46. let wrapper = document.createElement('div');
  47. wrapper.setAttribute("id","pipbutton");
  48. parent.insertBefore(wrapper, parent.firstChild);
  49. addbutton();
  50.  
  51. }
  52.  
  53. }, 1000);
  54.  
  55. })();