Last active
April 28, 2022 13:27
-
-
Save TheByKotik/fc6336027d345866d7a8aa8a5f56d503 to your computer and use it in GitHub Desktop.
Trovo++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Trovo++ | |
// @version 1.4.1.0 | |
// @author Kotik | |
// @description Trovo++ | |
// @match https://trovo.live/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=trovo.live | |
// @run-at document-start | |
// @grant unsafeWindow | |
// @updateURL https://gist.github.com/TheByKotik/fc6336027d345866d7a8aa8a5f56d503/raw/trovopp.meta.js | |
// @downloadURL https://gist.github.com/TheByKotik/fc6336027d345866d7a8aa8a5f56d503/raw/trovopp.user.js | |
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Trovo++ | |
// @version 1.4.1.0 | |
// @author Kotik | |
// @description Trovo++ | |
// @match https://trovo.live/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=trovo.live | |
// @run-at document-start | |
// @grant unsafeWindow | |
// @updateURL https://gist.github.com/TheByKotik/fc6336027d345866d7a8aa8a5f56d503/raw/trovopp.meta.js | |
// @downloadURL https://gist.github.com/TheByKotik/fc6336027d345866d7a8aa8a5f56d503/raw/trovopp.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let vid; | |
const Deque = (latency) => | |
{ | |
Deque.Latencies[ Deque.Iterator++ ] = latency; | |
if ( Deque.Iterator >= Deque.Lenght ) { Deque.Iterator = 0; } | |
} | |
Deque.Init = (LenghtOfDeque) => | |
{ | |
Deque.Latencies = new Array( LenghtOfDeque ); | |
Deque.Iterator = 0; | |
Deque.Lenght = LenghtOfDeque; | |
Deque.Latencies.fill( 0.0 ); | |
Object.seal( Deque.Latencies ); | |
Object.seal( Deque.Lenght ); | |
Deque.Init = () => {}; | |
}; | |
Deque.IsSlowing = (latency) => | |
{ | |
return ((Deque.Latencies.reduce( (sum, a) => sum + a ) / Deque.Latencies.length) < latency ); | |
}; | |
const SpeedUp = () => | |
{ | |
const Latency = vid.buffered.end(0) - vid.currentTime; | |
Deque( Latency ); | |
if ( !vid.paused ) | |
{ | |
if ( Latency >= 1.0 ) | |
{ | |
if ( Deque.IsSlowing( Latency ) ) | |
{ | |
let lerp = vid.playbackRate + 0.01; | |
if ( lerp > 16.0 ) { lerp = 16.0; } | |
vid.playbackRate = lerp; | |
} | |
} | |
else | |
{ | |
vid.playbackRate = 1.0; | |
} | |
} | |
} | |
let Hook; | |
const WaitBuffer = () => | |
{ | |
if ( vid.buffered.length > 0 ) | |
{ | |
clearInterval( Hook ); | |
Deque.Init( 8 ); | |
setInterval( SpeedUp, 1000 ); | |
} | |
} | |
const HookVideo = () => | |
{ | |
vid = document.getElementsByTagName('video')[0]; | |
if ( vid !== undefined ) | |
{ | |
clearInterval( Hook ); | |
Hook = setInterval( WaitBuffer, 1000 ); | |
} | |
} | |
Hook = setInterval( HookVideo, 1000 ); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment