diff --git a/vaft/vaft-ublock-origin.js b/vaft/vaft-ublock-origin.js index ce76969..bb2194f 100644 --- a/vaft/vaft-ublock-origin.js +++ b/vaft/vaft-ublock-origin.js @@ -57,10 +57,8 @@ twitch-videoad.js text/javascript scope.ClientID = 'kimne78kx3ncx6brgo4mv6wki5h1ko'; scope.ClientVersion = 'null'; scope.ClientSession = 'null'; - //scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself - scope.PlayerType2 = 'autoplay'; //360p - scope.PlayerType3 = 'embed'; //Source - //scope.PlayerType4 = 'embed'; //Source + scope.PlayerType2 = 'embed'; //Source + scope.PlayerType3 = 'autoplay'; //360p scope.CurrentChannelName = null; scope.UsherParams = null; scope.WasShowingAd = false; @@ -284,9 +282,6 @@ twitch-videoad.js text/javascript if (weaverText.includes(AdSignifier)) { weaverText = await processM3U8(url, responseText, realFetch, PlayerType3); } - //if (weaverText.includes(AdSignifier)) { - // weaverText = await processM3U8(url, responseText, realFetch, PlayerType4); - //} resolve(new Response(weaverText)); }; var send = function() { diff --git a/vaft/vaft.user.js b/vaft/vaft.user.js index 7c41fa2..9807890 100644 --- a/vaft/vaft.user.js +++ b/vaft/vaft.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TwitchAdSolutions (vaft) // @namespace https://github.com/pixeltris/TwitchAdSolutions -// @version 5.8.3 +// @version 5.8.4 // @description Multiple solutions for blocking Twitch ads (vaft) // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js @@ -68,10 +68,8 @@ scope.ClientID = 'kimne78kx3ncx6brgo4mv6wki5h1ko'; scope.ClientVersion = 'null'; scope.ClientSession = 'null'; - //scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself - scope.PlayerType2 = 'autoplay'; //360p - scope.PlayerType3 = 'embed'; //Source - //scope.PlayerType4 = 'embed'; //Source + scope.PlayerType2 = 'embed'; //Source + scope.PlayerType3 = 'autoplay'; //360p scope.CurrentChannelName = null; scope.UsherParams = null; scope.WasShowingAd = false; @@ -295,9 +293,6 @@ if (weaverText.includes(AdSignifier)) { weaverText = await processM3U8(url, responseText, realFetch, PlayerType3); } - //if (weaverText.includes(AdSignifier)) { - // weaverText = await processM3U8(url, responseText, realFetch, PlayerType4); - //} resolve(new Response(weaverText)); }; var send = function() { diff --git a/video-swap-new/video-swap-new-ublock-origin.js b/video-swap-new/video-swap-new-ublock-origin.js index b2d4413..2166aae 100644 --- a/video-swap-new/video-swap-new-ublock-origin.js +++ b/video-swap-new/video-swap-new-ublock-origin.js @@ -249,6 +249,32 @@ twitch-videoad.js text/javascript return; } } else { + var lowResLines = encodingsM3u8.replace('\r', '').split('\n'); + var lowResBestUrl = null; + for (var j = 0; j < lowResLines.length; j++) { + if (lowResLines[j].startsWith('#EXT-X-STREAM-INF')) { + var res = parseAttributes(lowResLines[j])['RESOLUTION']; + if (res && lowResLines[j + 1].endsWith('.m3u8')) { + // Assumes resolutions are correctly ordered + lowResBestUrl = lowResLines[j + 1]; + break; + } + } + } + if (lowResBestUrl != null && streamInfo.Encodings != null) { + var normalEncodingsM3u8 = streamInfo.Encodings; + var normalLines = normalEncodingsM3u8.replace('\r', '').split('\n'); + for (var j = 0; j < normalLines.length - 1; j++) { + if (normalLines[j].startsWith('#EXT-X-STREAM-INF')) { + var res = parseAttributes(normalLines[j])['RESOLUTION']; + if (res) { + lowResBestUrl += ' ';// The stream doesn't load unless each url line is unique + normalLines[j + 1] = lowResBestUrl; + } + } + } + encodingsM3u8 = normalLines.join('\r\n'); + } streamInfo.BackupEncodings = encodingsM3u8; } var lines = encodingsM3u8.replace('\r', '').split('\n'); @@ -511,22 +537,25 @@ twitch-videoad.js text/javascript player.play(); return; } - 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 ? video.volume : player.getVolume(); - const muted = player.isMuted(); - const newVideo = document.createElement('video'); - newVideo.volume = muted ? 0 : volume; - newVideo.playsInline = true; - video.replaceWith(newVideo); - player.attachHTMLVideoElement(newVideo); - setImmediate(() => { - player.setVolume(volume); - player.setMuted(muted); - }); + const lsKeyQuality = 'video-quality'; + const lsKeyMuted = 'video-muted'; + const lsKeyVolume = 'volume'; + var currentQualityLS = localStorage.getItem(lsKeyQuality); + var currentMutedLS = localStorage.getItem(lsKeyMuted); + var currentVolumeLS = localStorage.getItem(lsKeyVolume); + if (player?.core?.state) { + localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted})); + localStorage.setItem(lsKeyVolume, player.core.state.volume); + } + if (player?.core?.state?.quality?.group) { + localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group})); } - playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });// ffz sets this false + playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true }); + setTimeout(() => { + localStorage.setItem(lsKeyQuality, currentQualityLS); + localStorage.setItem(lsKeyMuted, currentMutedLS); + localStorage.setItem(lsKeyVolume, currentVolumeLS); + }, 3000); } window.reloadTwitchPlayer = reloadTwitchPlayer; hookFetch(); diff --git a/video-swap-new/video-swap-new.user.js b/video-swap-new/video-swap-new.user.js index 2430033..ab5fd76 100644 --- a/video-swap-new/video-swap-new.user.js +++ b/video-swap-new/video-swap-new.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TwitchAdSolutions (video-swap-new) // @namespace https://github.com/pixeltris/TwitchAdSolutions -// @version 1.20 +// @version 1.21 // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js // @description Multiple solutions for blocking Twitch ads (video-swap-new) @@ -260,6 +260,32 @@ return; } } else { + var lowResLines = encodingsM3u8.replace('\r', '').split('\n'); + var lowResBestUrl = null; + for (var j = 0; j < lowResLines.length; j++) { + if (lowResLines[j].startsWith('#EXT-X-STREAM-INF')) { + var res = parseAttributes(lowResLines[j])['RESOLUTION']; + if (res && lowResLines[j + 1].endsWith('.m3u8')) { + // Assumes resolutions are correctly ordered + lowResBestUrl = lowResLines[j + 1]; + break; + } + } + } + if (lowResBestUrl != null && streamInfo.Encodings != null) { + var normalEncodingsM3u8 = streamInfo.Encodings; + var normalLines = normalEncodingsM3u8.replace('\r', '').split('\n'); + for (var j = 0; j < normalLines.length - 1; j++) { + if (normalLines[j].startsWith('#EXT-X-STREAM-INF')) { + var res = parseAttributes(normalLines[j])['RESOLUTION']; + if (res) { + lowResBestUrl += ' ';// The stream doesn't load unless each url line is unique + normalLines[j + 1] = lowResBestUrl; + } + } + } + encodingsM3u8 = normalLines.join('\r\n'); + } streamInfo.BackupEncodings = encodingsM3u8; } var lines = encodingsM3u8.replace('\r', '').split('\n'); @@ -522,22 +548,25 @@ player.play(); return; } - 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 ? video.volume : player.getVolume(); - const muted = player.isMuted(); - const newVideo = document.createElement('video'); - newVideo.volume = muted ? 0 : volume; - newVideo.playsInline = true; - video.replaceWith(newVideo); - player.attachHTMLVideoElement(newVideo); - setImmediate(() => { - player.setVolume(volume); - player.setMuted(muted); - }); + const lsKeyQuality = 'video-quality'; + const lsKeyMuted = 'video-muted'; + const lsKeyVolume = 'volume'; + var currentQualityLS = localStorage.getItem(lsKeyQuality); + var currentMutedLS = localStorage.getItem(lsKeyMuted); + var currentVolumeLS = localStorage.getItem(lsKeyVolume); + if (player?.core?.state) { + localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted})); + localStorage.setItem(lsKeyVolume, player.core.state.volume); + } + if (player?.core?.state?.quality?.group) { + localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group})); } - playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });// ffz sets this false + playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true }); + setTimeout(() => { + localStorage.setItem(lsKeyQuality, currentQualityLS); + localStorage.setItem(lsKeyMuted, currentMutedLS); + localStorage.setItem(lsKeyVolume, currentVolumeLS); + }, 3000); } window.reloadTwitchPlayer = reloadTwitchPlayer; hookFetch();