Last active
July 26, 2024 15:20
-
-
Save rf5860/ec4ff60cb7406814a1de94cd2fe6dbfc to your computer and use it in GitHub Desktop.
Greasemonkey Script to add more speed options to the video player on teamtreehouse.com
This file contains hidden or 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 TreeHouse Video Speeds | |
// @namespace https://teamtreehouse.com/ | |
// @version 0.1 | |
// @description Add more speed options to the video player on teamtreehouse.com | |
// @updateURL https://gist.github.com/rf5860/ec4ff60cb7406814a1de94cd2fe6dbfc/raw/TreeHouseVideoSpeed.user.js | |
// @downloadURL https://gist.github.com/rf5860/ec4ff60cb7406814a1de94cd2fe6dbfc/raw/TreeHouseVideoSpeed.user.js | |
// @author rjf89 | |
// @match https://teamtreehouse.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to add new speed options | |
function addCustomSpeeds(speedControls) { | |
const speedList = speedControls.querySelector('ol'); | |
const newSpeeds = [2.25, 2.5, 2.75, 3, 3.25, 3.5, 4]; | |
newSpeeds.forEach(speed => { | |
const li = document.createElement('li'); | |
li.className = 'mejs-speed'; | |
li.setAttribute('data-speed', speed); | |
li.innerHTML = `${speed}x <span class="speed-tooltip">${speed}x</span>`; | |
speedList.insertBefore(li, speedList.firstChild); | |
}); | |
} | |
// Set up mutation observer | |
const targetNode = document.body; | |
const config = { childList: true, subtree: true }; | |
const callback = function(mutationsList, observer) { | |
for(let mutation of mutationsList) { | |
if (mutation.type === 'childList') { | |
const speedControls = document.querySelector('.mejs-speed-controls'); | |
if (speedControls) { | |
addCustomSpeeds(speedControls); | |
observer.disconnect(); | |
break; | |
} | |
} | |
} | |
}; | |
// Create and start the observer | |
const observer = new MutationObserver(callback); | |
observer.observe(targetNode, config); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment