Last active
February 26, 2024 02:40
-
-
Save Ranamzes/12e5b948c4f0872915dddeb781cf2ee7 to your computer and use it in GitHub Desktop.
Tampermonkey script to switch playback speed on YouTube using Enhancer for 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 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