Advertisement
Froschi

Force Enable Picture-in-Picture

Jun 12th, 2025 (edited)
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Force Enable Picture-in-Picture
  3. // @description  Replaces disablepictureinpicture with enablepictureinpicture, even inside iframes - Enforces video players to enable PiP mode / Example: Crunchyroll
  4. // @version      1.0
  5. // @author       Froschi
  6. // @match        *://*/*
  7. // @grant        none
  8. // ==/UserScript==
  9.  
  10. (function () {
  11.     'use strict';
  12.  
  13.     // Replace existing attributes
  14.     function replaceAttributes(root = document) {
  15.         const elements = root.querySelectorAll('[disablepictureinpicture]');
  16.         elements.forEach(el => {
  17.             console.log("🔧 Enforcing Picture-in-Picture on:", el);
  18.             el.removeAttribute('disablepictureinpicture');
  19.             el.setAttribute('enablepictureinpicture', '');
  20.         });
  21.     }
  22.  
  23.     // Watch for new elements being added dynamically
  24.     function watchForNewElements(root = document) {
  25.         const observer = new MutationObserver(mutations => {
  26.             mutations.forEach(mutation => {
  27.                 mutation.addedNodes.forEach(node => {
  28.                     if (node.nodeType === 1) {
  29.                         if (node.hasAttribute('disablepictureinpicture')) {
  30.                             node.removeAttribute('disablepictureinpicture');
  31.                             node.setAttribute('enablepictureinpicture', '');
  32.                         }
  33.                         const inner = node.querySelectorAll('[disablepictureinpicture]');
  34.                         inner.forEach(el => {
  35.                             el.removeAttribute('disablepictureinpicture');
  36.                             el.setAttribute('enablepictureinpicture', '');
  37.                         });
  38.                     }
  39.                 });
  40.             });
  41.         });
  42.         observer.observe(root.body, { childList: true, subtree: true });
  43.     }
  44.  
  45.     // Run on page load
  46.     window.addEventListener('load', () => {
  47.         console.log("🌼 Page loaded, enabling picture-in-picture...");
  48.         replaceAttributes();
  49.         watchForNewElements();
  50.     });
  51.     replaceAttributes();
  52. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement