Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Force Enable Picture-in-Picture
- // @description Replaces disablepictureinpicture with enablepictureinpicture, even inside iframes - Enforces video players to enable PiP mode / Example: Crunchyroll
- // @version 1.0
- // @author Froschi
- // @match *://*/*
- // @grant none
- // ==/UserScript==
- (function () {
- 'use strict';
- // Replace existing attributes
- function replaceAttributes(root = document) {
- const elements = root.querySelectorAll('[disablepictureinpicture]');
- elements.forEach(el => {
- console.log("🔧 Enforcing Picture-in-Picture on:", el);
- el.removeAttribute('disablepictureinpicture');
- el.setAttribute('enablepictureinpicture', '');
- });
- }
- // Watch for new elements being added dynamically
- function watchForNewElements(root = document) {
- const observer = new MutationObserver(mutations => {
- mutations.forEach(mutation => {
- mutation.addedNodes.forEach(node => {
- if (node.nodeType === 1) {
- if (node.hasAttribute('disablepictureinpicture')) {
- node.removeAttribute('disablepictureinpicture');
- node.setAttribute('enablepictureinpicture', '');
- }
- const inner = node.querySelectorAll('[disablepictureinpicture]');
- inner.forEach(el => {
- el.removeAttribute('disablepictureinpicture');
- el.setAttribute('enablepictureinpicture', '');
- });
- }
- });
- });
- });
- observer.observe(root.body, { childList: true, subtree: true });
- }
- // Run on page load
- window.addEventListener('load', () => {
- console.log("🌼 Page loaded, enabling picture-in-picture...");
- replaceAttributes();
- watchForNewElements();
- });
- replaceAttributes();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement