30 lines
968 B
JavaScript
30 lines
968 B
JavaScript
// ==UserScript==
|
|
// @name Default Speed for YT Videos
|
|
// @version 1.0.0
|
|
// @description Speed up YouTube Videos
|
|
// @author phga
|
|
// @match *://*.youtube.com/*
|
|
// @exclude *://*.youtube.com/subscribe_embed?*
|
|
// ==/UserScript==
|
|
const speed = 1.5;
|
|
const timeout = 100;
|
|
const waitAndRunSpeed = () => {
|
|
setTimeout(setVideoSpeed, timeout);
|
|
}
|
|
const setVideoSpeed = () => {
|
|
const ad = [...document.querySelectorAll('.ad-showing')][0];
|
|
const video = document.querySelector('video');
|
|
// If no ad is playing and the video has really started
|
|
if (!ad && video.currentTime >= 1) {
|
|
video.playbackRate = speed;
|
|
console.log(`Set video speed to ${speed}`);
|
|
} else {
|
|
console.log("Ad is running. Retrying to set video speed...");
|
|
setTimeout(setVideoSpeed, timeout);
|
|
}
|
|
}
|
|
|
|
// So we do not have to constantly run the function with setInterval
|
|
window.navigation.addEventListener("navigate", waitAndRunSpeed);
|
|
waitAndRunSpeed();
|