Add Picture in Picture button

Adds a Picture in Picture button below stream

  1. // ==UserScript==
  2. // @name Add Picture in Picture button
  3. // @version 1.2
  4. // @description Adds a Picture in Picture button below stream
  5. // @author Spedwards
  6. // @match https://www.twitch.tv/*
  7. // @run-at document-end
  8. // @namespace https://gf.qytechs.cn/users/6797
  9. // ==/UserScript==
  10.  
  11. const selector = `#root > div > div.tw-flex.tw-flex-column.tw-flex-nowrap.tw-full-height > div > main > div.root-scrollable.scrollable-area.scrollable-area--suppress-scroll-x > div.simplebar-scroll-content > div > div > div.channel-root.tw-full-height > div.channel-root__player-container.tw-pd-b-2 > div > div.channel-info-bar.tw-border-b.tw-border-bottom-left-radius-large.tw-border-bottom-right-radius-large.tw-border-l.tw-border-r.tw-border-t.tw-flex.tw-flex-wrap.tw-justify-content-between.tw-lg-pd-b-0.tw-lg-pd-t-1.tw-lg-pd-x-1.tw-pd-1 > div > div > div > div.channel-info-bar__content-right.tw-full-width > div.tw-align-items-start.tw-flex.tw-flex-wrap.tw-justify-content-between.tw-mg-t-05 > div:nth-child(2) > div:nth-child(2) > div.tw-mg-x-1`;
  12.  
  13. (function() {
  14. (new MutationObserver(function(mutationList) {
  15. const button = document.getElementById('pip');
  16. if (!button) {
  17. const el = document.querySelector(selector);
  18. if (el) {
  19. el.className = 'tw-mg-l-1';
  20. el.insertAdjacentElement('afterend', createButton());
  21. }
  22. }
  23. })).observe(document.getElementsByTagName('title')[0] || document, {childList: true, subtree: true});
  24.  
  25. function createButton() {
  26. const pipDiv = createElement('DIV', {id: 'pip'});
  27. const divWrap = createElement('DIV', {class: 'tw-relative'});
  28. const btn = createElement('BUTTON', {class: 'tw-interactive tw-button tw-button--text', events: [{type: 'click', fn: () => document.querySelector('div.player-video video').requestPictureInPicture()}]});
  29. const btnText = createElement('SPAN', {class: 'tw-button__text', innerHTML: 'Picture in Picture'});
  30. btn.appendChild(btnText);
  31. divWrap.appendChild(btn);
  32. pipDiv.appendChild(divWrap);
  33. return pipDiv;
  34. }
  35.  
  36. function createElement(e, opts) {
  37. const el = document.createElement(e);
  38. if (!opts) return el;
  39. if (opts.id) el.id = opts.id;
  40. if (opts.class) el.className = opts.class;
  41. if (opts.innerHTML) el.innerHTML = opts.innerHTML;
  42. if (opts.events) opts.events.forEach(event => el.addEventListener(event.type, event.fn));
  43. return el;
  44. }
  45. })();

QingJ © 2025

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