您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
enable the picture in picture feature by holding down mouse for 1 second
当前为
// ==UserScript== // @name Enable Picture In Picture For Every Sites // @namespace http://tampermonkey.net/ // @version 0.1 // @description enable the picture in picture feature by holding down mouse for 1 second // @author You // @match *://*/* // @grant none // ==/UserScript== let retry = true, timer = void(0), e_path = [], v_exist = false, // if a video exists in the path given target = void(0); function enable_pip(element){ if (!document.pictureInPictureEnabled) { alert('Your Browser Does Not Support Picture In Picture!'); } element.disablePictureInPicture = false; element.requestPictureInPicture().then().catch(()=>{ if(retry){ retry = false; enable_pip(element); }else{ console.log('unable to enable picture in picture\ncheck the browser'); } }); } document.onmousedown = (element)=>{ timer = setTimeout(()=>{ if(document.pictureInPictureElement){ // pause the video beforehand so that when mouseup, the video will play document.exitPictureInPicture(); target.pause(); }else{ e_path = element.path; for(let i = 0;i<e_path.length;i++){ // find that video element if(e_path[i].nodeName === 'VIDEO'){ v_exist = true; target = e_path[i]; enable_pip(target); target.pause(); // same console.log('PIP activated'); } } if(!v_exist){ console.log('no video exists in this path'); } } },1000); }; document.onmouseup = ()=>{ // if not 1 second, cancel the timer clearTimeout(timer); };