Skip to content

Instantly share code, notes, and snippets.

@Property404
Last active October 16, 2022 22:42
Show Gist options
  • Save Property404/46cca9a72b786dcab161f48bc3a4185d to your computer and use it in GitHub Desktop.
Save Property404/46cca9a72b786dcab161f48bc3a4185d to your computer and use it in GitHub Desktop.
Remove
// ==UserScript==
// @name DeCC
// @version 1.2
// @grant none
// ==/UserScript==
// Removes [CC brakets] on Netflix subtitles (requires browser refresh)
function main()
{
console.log("Starting!");
const targetNode = document.querySelector(".watch-video");
console.log(targetNode);
const config = { attributes: false, childList: true, subtree: true };
let last_sub = [];
let tcontainer;
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
const tcontainer = targetNode.querySelector(".player-timedtext-text-container");
if(tcontainer)
{
console.log("Found tcontainer");
const spans = tcontainer.querySelectorAll("span");
let j=0;
spans.forEach(span=>{
console.log("Found span!");
j++;
const oldtext = span.innerHTML;
if(oldtext == last_sub[j])
return;
last_sub[j] = oldtext;
const newtext = oldtext.replace(/\[.*\]/g, "").replace(/^-\s*/g,"");
console.log(newtext);
span.innerHTML = newtext;
});
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
console.log("Observing!");
}
setTimeout(main, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment