Skip to content

Instantly share code, notes, and snippets.

@Ranamzes
Last active February 26, 2024 02:40
Show Gist options
  • Save Ranamzes/12e5b948c4f0872915dddeb781cf2ee7 to your computer and use it in GitHub Desktop.
Save Ranamzes/12e5b948c4f0872915dddeb781cf2ee7 to your computer and use it in GitHub Desktop.
Tampermonkey script to switch playback speed on YouTube using Enhancer for YouTube
// ==UserScript==
// @name Enhancer for YouTube Speed Toggle
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Toggle YouTube playback speed between normal and a preset speed using Enhancer for YouTube extension.
// @author Re•MART
// @match https://www.youtube.com/watch?*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let timespeed = null;
document.addEventListener('keydown', function(e) {
if (e.ctrlKey && (e.key === '/' || e.key === '.')) {
const settingsKey = 'enhancer-for-youtube';
const storedSettings = JSON.parse(localStorage.getItem(settingsKey));
const currentSpeed = storedSettings.speed;
if (timespeed === null && currentSpeed !== 1) {
timespeed = currentSpeed;
storedSettings.speed = 1;
} else if (currentSpeed === 1 && timespeed !== null) {
storedSettings.speed = timespeed;
} else if (currentSpeed !== 1) {
timespeed = currentSpeed;
}
localStorage.setItem(settingsKey, JSON.stringify(storedSettings));
// Trigger Enhancer for YouTube to read updated settings
document.dispatchEvent(new Event('efyt-update-preferences'));
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment