Skip to content

Instantly share code, notes, and snippets.

@eslin
Created April 7, 2025 20:10
Show Gist options
  • Save eslin/883255397c2af2f73bb6cdcf00ae0a5e to your computer and use it in GitHub Desktop.
Save eslin/883255397c2af2f73bb6cdcf00ae0a5e to your computer and use it in GitHub Desktop.
tampermonkey: plex subtitle filter
// ==UserScript==
// @name Selective Subtitle Button Handler on Plex
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Highlights subtitle elements and handles their buttons based on language rules on Plex Desktop app.
// @author You
// @match https://app.plex.tv/desktop/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const ignoredPatterns = [
/^None$/i,
/English/i,
/Swedish/i
];
function shouldIgnore(text) {
return ignoredPatterns.some(pattern => pattern.test(text));
}
function processSubtitles() {
const elements = document.querySelectorAll('[data-testid="subtitlesStream"]');
elements.forEach(el => {
const text = el.textContent.trim();
if (shouldIgnore(text)) {
console.log(`Skipping subtitle: "${text}"`);
return;
}
// Highlight the subtitle span
//el.style.border = '2px solid hotpink';
//el.style.padding = '2px';
// Tone down or mark the button
const button = el.closest('button');
if (button) {
button.style.display = 'none';
//button.style.opacity = '0.4';
//button.style.border = '2px dashed red';
console.log(`Modified button for subtitle: "${text}"`, button);
}
});
}
// Initial run
processSubtitles();
// React to dynamic content
const observer = new MutationObserver(() => {
processSubtitles();
});
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment