in

How to make subtitles change automatically on youtube?⁣


//represents clicked buttons (to turn on and change subtitle)
const settinsgBtn = document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-right-controls > button.ytp-button.ytp-settings-button.ytp-hd-quality-badge");
const translateBtn = document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-right-controls > button.ytp-subtitles-button.ytp-button");
const langueContentBtn = document.querySelectorAll(".ytp-menuitem-content")[2];
const autoTranslateBtn = document.querySelectorAll(".ytp-menuitem-label")[2];
const myLangueBtn = document.querySelectorAll('.ytp-menuitem-label')[80]

//It checks every second whether the buttons are on the screen and clicks the button if there is.
//Each button makes another button appear on the screen.
const checkElements = setInterval(clicker, 1000);

let count = 1;
function clicker() {
    if (count === 1 && translateBtn) {
      translateBtn.click(); count++;
    } 
    else if (count === 2 && settinsgBtn) {
      settinsgBtn.click(); count++;
    } 
    else if (count === 3 && langueContentBtn) {
      langueContentBtn.click(); count++;
    } 
    else if (count === 4 && autoTranslateBtn) {
      autoTranslateBtn.click(); count++;
    } 
    else if (count === 5 && myLangueBtn) {
      myLangueBtn.click(); count = 0;
      clearInterval(checkElements);
    }
}

clicker();

I want the youtube video to press the subtitle button and translate it into my language from the settings, but the variables are not defined immediately. If the button to be clicked is not visible at first, the variable returns undefined value. It works when I redefine the variable after the button appears. I tried without defining the variable but it again doesn’t work after the 2nd click.⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣



Source: https://stackoverflow.com/questions/70599914/how-to-make-subtitles-change-automatically-on-youtube

Path issue with passing a command from Autohotkey to PowerShell

The Nebulant CLI tool is a single binary that can be used as a helper for the web editor