Skip to content

Instantly share code, notes, and snippets.

@pixeljammed
Last active May 14, 2025 00:29
Show Gist options
  • Select an option

  • Save pixeljammed/11e33cedb5a126ca2d30d020b5b0ee51 to your computer and use it in GitHub Desktop.

Select an option

Save pixeljammed/11e33cedb5a126ca2d30d020b5b0ee51 to your computer and use it in GitHub Desktop.
Dumb video script for YouTube that made me laugh.
(function() {
let increment = 0.01; // Adjust this value to change the increment
let lowerBound = 0.1; // Adjust this value to change the lower bound
let upperBound = 3; // Adjust this value to change the upper bound
let A = 0; // Adjust this value to change the minimum hold time in milliseconds
let B = 2; // Adjust this value to change the maximum hold time in milliseconds
let targetRate = 0.1; // Initialize targetRate with a default value
let holding = false;
let holdTimer;
function getRandomRate(currentRate) {
let newRate;
if (currentRate < (lowerBound + upperBound) / 2) {
// More likely to pick a rate in the upper half
newRate = Math.random() * (upperBound - (upperBound + lowerBound) / 2) + (upperBound + lowerBound) / 2;
} else {
// More likely to pick a rate in the lower half
newRate = Math.random() * ((upperBound + lowerBound) / 2 - lowerBound) + lowerBound;
}
return Math.round(newRate * 10) / 10;
}
function updatePlaybackRate() {
const video = document.getElementsByTagName("video")[0];
if (video) {
if (!holding) {
if (Math.abs(video.playbackRate - targetRate) < increment) {
video.playbackRate = targetRate;
console.log(`Playback rate set to: ${video.playbackRate}`);
holding = true;
holdTimer = setTimeout(() => {
targetRate = getRandomRate(video.playbackRate);
holding = false;
}, Math.random() * (B - A) + A); // Randomize the hold time between A and B
} else {
if (video.playbackRate < targetRate) {
video.playbackRate += increment;
} else {
video.playbackRate -= increment;
}
video.playbackRate = Math.round(video.playbackRate * 100) / 100; // Ensure one decimal point precision
console.log(`Playback rate set to: ${video.playbackRate}`);
clearInterval(intervalID); // Clear the previous interval
intervalID = setInterval(updatePlaybackRate, Math.random() * (100 - 1) + 1); // Randomize the delay between 10 and 500 ms
}
}
} else {
console.warn("No video element found.");
}
}
targetRate = getRandomRate(0.1); // Set initial target rate
let intervalID = setInterval(updatePlaybackRate, Math.random() * (100 - 1) + 1); // Start the interval with a random delay
})();
document.querySelector('.video-stream').preservesPitch = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment