Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Last active April 2, 2025 02:09
Show Gist options
  • Save jamtur01/e0956c082abfc9c01f1e21de397b7585 to your computer and use it in GitHub Desktop.
Save jamtur01/e0956c082abfc9c01f1e21de397b7585 to your computer and use it in GitHub Desktop.
Auto-press Skip Buttons on Plex
// ==UserScript==
// @name Trigger on Skip Forward Button Click by Adjusting Video Time
// @version 1.2
// @description Adjust video time when the Skip Forward button is clicked in the Plex player, even across episodes or media changes.
// @author James Turnbull
// @match *://*/*
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
function attachListener(skipForwardButton, video) {
if (!skipForwardButton || !video) return;
// Ensure no duplicate listeners
skipForwardButton.removeEventListener('click', handleSkipForward);
skipForwardButton.addEventListener('click', handleSkipForward);
console.log('Event listener attached to Skip Forward button.');
function handleSkipForward() {
setTimeout(() => {
if (video.readyState >= 1) { // HAVE_METADATA
const newTime = Math.max(video.currentTime - 20, 0);
console.log(`Adjusting video time from ${video.currentTime} to ${newTime}`);
video.currentTime = newTime;
} else {
console.log('Video not ready; skipping adjustment.');
}
}, 0);
}
}
function observeDOM() {
const observer = new MutationObserver(() => {
const skipForwardButton = document.querySelector('[aria-label="Skip Forward 30 Seconds"], [title="Skip Forward 30 Seconds"]');
const video = document.querySelector('video');
if (skipForwardButton && video) {
attachListener(skipForwardButton, video);
}
});
observer.observe(document.body, { childList: true, subtree: true });
console.log('Observing DOM for changes...');
}
// Initialize the observer
observeDOM();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment