diff --git a/README.md b/README.md index 8fb7b81..6f92400 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Tampermonkey / Greasemonkey can be used on the files suffixed by `user.js` e.g. - https://github.com/streamlink/streamlink (desktop application) - https://github.com/nopbreak/TwitchMod (android app) - https://twitchls.com/ (external site - purple screen may display every 10-15 mins) +- [Use a VPN targeting a region without ads](https://reddit.com/r/Twitch/comments/kisdsy/i_did_a_little_test_regarding_ads_on_twitch_and/) ## NOTE/TODO diff --git a/base/base.user.js b/base/base.user.js index 57e2c19..42bb295 100644 --- a/base/base.user.js +++ b/base/base.user.js @@ -15,6 +15,7 @@ scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -32,6 +33,9 @@ scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -631,12 +635,17 @@ } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -649,10 +658,10 @@ if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn-skip-midroll/dyn-skip-midroll-ublock-origin.js b/dyn-skip-midroll/dyn-skip-midroll-ublock-origin.js index 9195f48..3cf330a 100644 --- a/dyn-skip-midroll/dyn-skip-midroll-ublock-origin.js +++ b/dyn-skip-midroll/dyn-skip-midroll-ublock-origin.js @@ -6,6 +6,7 @@ twitch-videoad.js application/javascript scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = true; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 1; @@ -23,6 +24,9 @@ twitch-videoad.js application/javascript scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -622,12 +626,17 @@ twitch-videoad.js application/javascript } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -640,10 +649,10 @@ twitch-videoad.js application/javascript if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn-skip-midroll/dyn-skip-midroll.user.js b/dyn-skip-midroll/dyn-skip-midroll.user.js index a3856c6..b9ded7d 100644 --- a/dyn-skip-midroll/dyn-skip-midroll.user.js +++ b/dyn-skip-midroll/dyn-skip-midroll.user.js @@ -15,6 +15,7 @@ scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = true; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 1; @@ -32,6 +33,9 @@ scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -631,12 +635,17 @@ } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -649,10 +658,10 @@ if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn-skip/dyn-skip-ublock-origin.js b/dyn-skip/dyn-skip-ublock-origin.js index 029fd3e..2feaf12 100644 --- a/dyn-skip/dyn-skip-ublock-origin.js +++ b/dyn-skip/dyn-skip-ublock-origin.js @@ -6,6 +6,7 @@ twitch-videoad.js application/javascript scope.OPT_MODE_MUTE_BLACK = true; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = true; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -23,6 +24,9 @@ twitch-videoad.js application/javascript scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -622,12 +626,17 @@ twitch-videoad.js application/javascript } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -640,10 +649,10 @@ twitch-videoad.js application/javascript if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn-skip/dyn-skip.user.js b/dyn-skip/dyn-skip.user.js index 3fe7375..b7f605e 100644 --- a/dyn-skip/dyn-skip.user.js +++ b/dyn-skip/dyn-skip.user.js @@ -15,6 +15,7 @@ scope.OPT_MODE_MUTE_BLACK = true; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = true; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -32,6 +33,9 @@ scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -631,12 +635,17 @@ } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -649,10 +658,10 @@ if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn-video-swap/dyn-video-swap-ublock-origin.js b/dyn-video-swap/dyn-video-swap-ublock-origin.js index f500a9b..a71c012 100644 --- a/dyn-video-swap/dyn-video-swap-ublock-origin.js +++ b/dyn-video-swap/dyn-video-swap-ublock-origin.js @@ -6,6 +6,7 @@ twitch-videoad.js application/javascript scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = true; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -23,6 +24,9 @@ twitch-videoad.js application/javascript scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -622,12 +626,17 @@ twitch-videoad.js application/javascript } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -640,10 +649,10 @@ twitch-videoad.js application/javascript if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn-video-swap/dyn-video-swap.user.js b/dyn-video-swap/dyn-video-swap.user.js index 008b9b2..8246b36 100644 --- a/dyn-video-swap/dyn-video-swap.user.js +++ b/dyn-video-swap/dyn-video-swap.user.js @@ -15,6 +15,7 @@ scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = true; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -32,6 +33,9 @@ scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -631,12 +635,17 @@ } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -649,10 +658,10 @@ if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn/dyn-ublock-origin.js b/dyn/dyn-ublock-origin.js index c3ebab8..84223a2 100644 --- a/dyn/dyn-ublock-origin.js +++ b/dyn/dyn-ublock-origin.js @@ -6,6 +6,7 @@ twitch-videoad.js application/javascript scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = true; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -23,6 +24,9 @@ twitch-videoad.js application/javascript scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -622,12 +626,17 @@ twitch-videoad.js application/javascript } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -640,10 +649,10 @@ twitch-videoad.js application/javascript if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/dyn/dyn.user.js b/dyn/dyn.user.js index 3095979..acef60b 100644 --- a/dyn/dyn.user.js +++ b/dyn/dyn.user.js @@ -15,6 +15,7 @@ scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = true; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -32,6 +33,9 @@ scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -631,12 +635,17 @@ } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -649,10 +658,10 @@ if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/mute-black/mute-black-ublock-origin.js b/mute-black/mute-black-ublock-origin.js index 0e8bb19..52150ce 100644 --- a/mute-black/mute-black-ublock-origin.js +++ b/mute-black/mute-black-ublock-origin.js @@ -6,6 +6,7 @@ twitch-videoad.js application/javascript scope.OPT_MODE_MUTE_BLACK = true; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -23,6 +24,9 @@ twitch-videoad.js application/javascript scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -622,12 +626,17 @@ twitch-videoad.js application/javascript } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -640,10 +649,10 @@ twitch-videoad.js application/javascript if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/mute-black/mute-black.user.js b/mute-black/mute-black.user.js index 0a96e38..cf3c2ca 100644 --- a/mute-black/mute-black.user.js +++ b/mute-black/mute-black.user.js @@ -15,6 +15,7 @@ scope.OPT_MODE_MUTE_BLACK = true; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -32,6 +33,9 @@ scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -631,12 +635,17 @@ } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -649,10 +658,10 @@ if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/proxy-m3u8/proxy-m3u8-ublock-origin.js b/proxy-m3u8/proxy-m3u8-ublock-origin.js index 4cd3190..073955d 100644 --- a/proxy-m3u8/proxy-m3u8-ublock-origin.js +++ b/proxy-m3u8/proxy-m3u8-ublock-origin.js @@ -6,6 +6,7 @@ twitch-videoad.js application/javascript scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -23,6 +24,9 @@ twitch-videoad.js application/javascript scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -622,12 +626,17 @@ twitch-videoad.js application/javascript } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -640,10 +649,10 @@ twitch-videoad.js application/javascript if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume; diff --git a/proxy-m3u8/proxy-m3u8.user.js b/proxy-m3u8/proxy-m3u8.user.js index 872fded..7475ab4 100644 --- a/proxy-m3u8/proxy-m3u8.user.js +++ b/proxy-m3u8/proxy-m3u8.user.js @@ -15,6 +15,7 @@ scope.OPT_MODE_MUTE_BLACK = false; scope.OPT_MODE_VIDEO_SWAP = false; scope.OPT_MODE_LOW_RES = false; + scope.OPT_MODE_EMBED = false; scope.OPT_MODE_STRIP_AD_SEGMENTS = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED = false; scope.OPT_MODE_NOTIFY_ADS_WATCHED_ATTEMPTS = 2;// Larger values might increase load time. Lower values may increase ad chance. @@ -32,6 +33,9 @@ scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'thunderdome';//480p //scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'picture-by-picture';//360p } + if (!scope.OPT_ACCESS_TOKEN_PLAYER_TYPE && scope.OPT_MODE_EMBED) { + scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'embed'; + } // These are only really for Worker scope... scope.StreamInfos = []; scope.StreamInfosByUrl = []; @@ -631,12 +635,17 @@ } return null; } - var reactRootNode = document.querySelector('#root')?._reactRootContainer?._internalRoot?.current; + var reactRootNode = null; + var rootNode = document.querySelector('#root'); + if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) { + reactRootNode = rootNode._reactRootContainer._internalRoot.current; + } if (!reactRootNode) { console.log('Could not find react root'); return; } - var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props?.mediaPlayerInstance)?.props?.mediaPlayerInstance; + var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance); + player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null; var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings); if (!player) { console.log('Could not find player'); @@ -649,10 +658,10 @@ if (player.paused) { return; } - const sink = player.mediaSinkManager || player.core?.mediaSinkManager; - if (sink?.video?._ffz_compressor) { + const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null); + if (sink && sink.video && sink.video._ffz_compressor) { const video = sink.video; - const volume = video.volume ?? player.getVolume(); + const volume = video.volume ? video.volume : player.getVolume(); const muted = player.isMuted(); const newVideo = document.createElement('video'); newVideo.volume = muted ? 0 : volume;