Skip to content

Instantly share code, notes, and snippets.

@rf5860
Last active July 26, 2024 15:20
Show Gist options
  • Save rf5860/ec4ff60cb7406814a1de94cd2fe6dbfc to your computer and use it in GitHub Desktop.
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
// ==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