volkan-k / Youtube auto translate to English

// ==UserScript==
// @name         Youtube auto translate to English
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Use Turkish (if available), then English or then translate to English automatically.
// @author       volkan-k
// @match        https://www.youtube.com/watch*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function translateToEnglish(){
        var sub = $('[role="menuitem"]:contains("Subtitles")');
        if(!sub.length) return;
        sub.click();
        var subct = $('[role="menuitemradio"]:contains("Turkish")');
        if (subct.length) {
            subct.click();
        } else {
			var subce = $('[role="menuitemradio"]:contains("English")');
			if (subce.length) {
				subce.click();
			} else {
				var autoTrans = $('[role="menuitemradio"]:contains("Auto-translate")');
				if (!autoTrans.length) return;
				autoTrans.click();
				var autoTransC = $('[role="menuitemradio"]:contains("English")');
				if (!autoTransC.length) return;
				autoTransC.click();
			}
		}
    }

    function onLoadStart(){
        $('.ytp-subtitles-button[aria-pressed="false"]').click();
        $('.ytp-settings-button').click();
        translateToEnglish();
        $('.ytp-settings-button').click();
    }
    $('video').on('loadstart', onLoadStart).trigger('loadstart');
})();