Last active
August 21, 2021 22:58
-
-
Save vrumger/ba78da48649019892ffc454a4610ace8 to your computer and use it in GitHub Desktop.
A tampermonkey script to automatically set the playback on YouTube
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 YouTube playback rate | |
// @namespace https://lungers.com | |
// @version 0.1 | |
// @description Automatically set the playback on YouTube | |
// @author Andrew Lane | |
// @match https://www.youtube.com/watch?v=* | |
// @run-at document-end | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
if (sessionStorage.hasOwnProperty('yt-player-playback-rate')) { | |
console.log('Playback rate already set'); | |
return; | |
} | |
const channelSelector = '.ytd-video-owner-renderer'; | |
const artistSelector = '#upload-info .badge-style-type-verified-artist'; | |
const liveSelector = '#date .ytd-video-primary-info-renderer:not(#dot)'; | |
const ignoredChannels = [ | |
'UCa10nxShhzNrCE1o2ZOPztg', // Trap Nation | |
'UCM9KEEuzacwVlkt9JfJad7g', // Chill Nation | |
'UCj_Y-xJ2DRDGP4ilfzplCOQ', // House Nation | |
'UC3ifTl5zKiCAhHIBQYcaTeg', // Proximity | |
'UC_aEa8K-EOJ3D6gOs7HcyNg', // NCS | |
'UCXO3dTkwiv6hDI5_MTZ8OuA', // Ma Fo | |
'UCQtq9GX2WGDzvapvfIwkUyg', // Wandering Music | |
'UCTOFODoILyXvkRdXtmepffA', // DEEPROT | |
]; | |
const observer = new MutationObserver((mutations, observer) => { | |
mutations.forEach(mutation => { | |
const channel = document.querySelector(channelSelector); | |
const artistBadge = document.querySelector(artistSelector); | |
const liveBadge = document.querySelector(liveSelector); | |
if (!channel?.href) { | |
return; | |
} | |
observer.disconnect(); | |
const channelID = new URL(channel.href).pathname.split('/').pop(); | |
if (ignoredChannels.includes(channelID)) { | |
console.log('Not setting playback rate: ignored channel'); | |
} else if (artistBadge !== null) { | |
console.log('Not setting playback rate: artist channel'); | |
} else if (liveBadge !== null && liveBadge.innerText.startsWith('Started streaming on ')) { | |
console.log('Not setting playback rate: live stream'); | |
} else { | |
sessionStorage.setItem('yt-player-playback-rate', `{"data":"1.25","creation":${Date.now()}}`); | |
setTimeout(() => { | |
location.reload(); | |
}, 100); | |
} | |
}); | |
}); | |
observer.observe(document.body, { | |
childList: true, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment