Hey, I wrote a code for a hotkey [u] to automatically select audio/subtitles language for me, it simulates clicking on the subs icon, then clicking on a preferred audio lang and a preferred subtitles lang.
function changeLang(){
// click on the subtitles icon to open it
document.getElementsByClassName("button-nfplayerSubtitles")[0].click();
setTimeout(function(){ // delay to give the subs menu time to show up
// order of preffered langs
var prefAudioLangs = [
"ruso [Original]",
"ruso",
"español de España - Audio descriptivo",
"español - Audio descriptivo",
"español de España [Original]",
"español [Original]",
"español de España",
"español"
];
// get available audio langs
var audioLangs = document.querySelectorAll("div.track-list-audio > ul > li");
var found = false;
for (let io = 0; io < prefAudioLangs.length; io++) {
for (let i = 0; i < audioLangs.length; i++) {
if (audioLangs[i].innerText == prefAudioLangs[io]){
audioLangs[i].click();
var chosenAudio = audioLangs[i].innerText;
found = true;
break;
}
}
if(found){ break; }
}
// define preffered subtitle langs
if ( chosenAudio.includes("ruso") ){
var prefSubtLangs = [
"ruso [CC]",
"ruso"
];
} else {
var prefSubtLangs = [
"español de España [CC]",
"español de España",
"español [CC]",
"español"
];
}
var subtLangs = document.querySelectorAll("div.track-list-subtitles > ul > li");
var found = false;
for (let io = 0; io < prefSubtLangs.length; io++) {
for (let i = 0; i < subtLangs.length; i++) {
if (subtLangs[i].innerText == prefSubtLangs[io]){
subtLangs[i].click();
found = true;
break;
}
}
if(found){ break; }
}
// click subs icon to hide the menu
setTimeout(function(){
document.getElementsByClassName("button-nfplayerSubtitles")[0].click();
}, 2000 );
}, 1000 );
}
function mylistener(e) {
if ( e.keyCode == 85) { // U
changeLang();
}
}
document.addEventListener('keyup', mylistener, false);
The problem is that when the UI is hidden the subs icon doesnât exist ( document.getElementsByClassName(âbutton-nfplayerSubtitlesâ) returns nothing ), so every time before clicking the shortcut i have to move the mouse on the screen to show the UI.
Would you have any idea how to show the netflix UI using JS so i can use this shortcut even when the UI is hidden without having to move the mouse before?
I have a set of 3 shortcuts like these, for each english,russian and spannish allowing me to quickly switch between then, as the list of langs is quite long and not sorted so its a pain to do it manually.