Skip to content

Instantly share code, notes, and snippets.

@valen214
Last active March 17, 2025 05:42
Show Gist options
  • Select an option

  • Save valen214/7095b14e1d10c1289e524ee96049a35a to your computer and use it in GitHub Desktop.

Select an option

Save valen214/7095b14e1d10c1289e524ee96049a35a to your computer and use it in GitHub Desktop.
Force music video to 1.0x speed on yt
// ==UserScript==
// @name Github Gist: force music playing at 1.0x speed on yt load
// @namespace https://gist.github.com/valen214/7095b14e1d10c1289e524ee96049a35a
// @version 0.2
// @description force music playing at 1.0x speed on yt load
// @author Valen
// @run-at document-end
// @match http*://www.youtube.com/watch*
// @grant none
// ==/UserScript==
(function(){
'use strict';
/*
https://gist.github.com/Ranamzes/12e5b948c4f0872915dddeb781cf2ee7
*/
function getResetCondition(){
let title = document.querySelector("#title yt-formatted-string").innerText.toLowerCase();
return (
title.includes("nightcore") ||
title.includes("song") ||
title.includes("music") ||
document.querySelector("#footer-section").innerHTML.includes("Music") ||
document.querySelector("h3#title.style-scope.ytd-video-description-music-section-renderer").innerText === "Music"
);
}
let first = true;
function resetSpeedIfMusic(){
if(first){
if(getResetCondition()){
console.info("Music video");
} else {
console.info("Not music video");
}
first = false;
}
try{
if(getResetCondition()){
document.querySelector("video").playbackRate = 1.0;
}
} catch(e){
console.error(e);
}
}
function bypassAdNotice(){
let elem = document.querySelector("ytd-enforcement-message-view-model");
let ret = elem?.parentElement?.removeChild(elem);
if(ret){
document.querySelector("tp-yt-iron-overlay-backdrop").opened = false
}
document.querySelector("video").play()
}
function functionsToRepeat(){
try{
resetSpeedIfMusic();
bypassAdNotice();
} catch(e){}
}
function repeat(args, count = 200){
if(count <= 0) return;
let functions = (typeof args === "function") ? [args] : args;
for(let func of functions){
try{
func();
} catch(e){}
}
setTimeout(repeat, 20, args, count-1);
}
repeat([resetSpeedIfMusic, bypassAdNotice]);
document.addEventListener("load", () => {
repeat([resetSpeedIfMusic, bypassAdNotice]);
setTimeout(() => {
repeat([resetSpeedIfMusic, bypassAdNotice]);
}, 1000);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment