@@ -13,16 +13,18 @@ export default {
1313 badges : [ BADGES . hot ] ,
1414 changeLogs : {
1515 "2024-06-05" : "fix video in iframes" ,
16+ "2024-07-19" : "fix video that disable pip" ,
1617 } ,
1718
1819 contentScript : {
1920 onClick_ : async function ( ) {
2021 const { UfsGlobal } = await import ( "./content-scripts/ufs_global.js" ) ;
2122
23+ const Mark = "__pip__" ;
24+
2225 function findLargestPlayingVideoInViewport ( ) {
2326 const videos = Array . from ( document . querySelectorAll ( "video" ) )
2427 . filter ( ( video ) => video . readyState != 0 )
25- . filter ( ( video ) => video . disablePictureInPicture == false )
2628 . sort (
2729 ( v1 , v2 ) =>
2830 UfsGlobal . DOM . getOverlapScore ( v2 ) -
@@ -35,11 +37,11 @@ export default {
3537 }
3638 async function requestPictureInPicture ( video ) {
3739 await video . requestPictureInPicture ( ) ;
38- video . setAttribute ( "__pip__" , true ) ;
40+ video . setAttribute ( Mark , true ) ;
3941 video . addEventListener (
4042 "leavepictureinpicture" ,
4143 ( event ) => {
42- video . removeAttribute ( "__pip__" ) ;
44+ video . removeAttribute ( Mark ) ;
4345 } ,
4446 {
4547 once : true ,
@@ -49,20 +51,22 @@ export default {
4951 }
5052 function maybeUpdatePictureInPictureVideo ( entries , observer ) {
5153 const observedVideo = entries [ 0 ] . target ;
52- if ( ! document . querySelector ( "[__pip__ ]" ) ) {
54+ if ( ! document . querySelector ( "[" + Mark + " ]") ) {
5355 observer . unobserve ( observedVideo ) ;
5456 return ;
5557 }
5658 const video = findLargestPlayingVideoInViewport ( ) ;
57- if ( video && ! video . hasAttribute ( "__pip__" ) ) {
59+ if ( video && ! video . hasAttribute ( Mark ) ) {
5860 observer . unobserve ( observedVideo ) ;
5961 requestPictureInPicture ( video ) ;
6062 }
6163 }
6264 ( async ( ) => {
6365 const video = findLargestPlayingVideoInViewport ( ) ;
6466 if ( ! video ) return ;
65- if ( video . hasAttribute ( "__pip__" ) ) {
67+ if ( video . disablePictureInPicture )
68+ video . disablePictureInPicture = false ;
69+ if ( video . hasAttribute ( Mark ) ) {
6670 document . exitPictureInPicture ( ) ;
6771 return ;
6872 }
0 commit comments