Greasy Fork

Greasy Fork is available in English.

Youtube - Subtitle

Automatically enable the subtitles.

目前为 2023-11-05 提交的版本。查看 最新版本

// ==UserScript==
// @name         Youtube - Subtitle
// @namespace    http://greasyfork.icu/en/users/670188-hacker09?sort=daily_installs
// @version      2
// @description  Automatically enable the subtitles.
// @author       hacker09
// @match        https://*.youtube.com/embed/*
// @match        https://www.youtube.com/watch?v=*
// @icon         https://www.youtube.com/s/desktop/03f86491/img/favicon.ico
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  var Counter = 0; //Create a new variable
  document.querySelector('video').addEventListener('play', function() { //When the video is played
    Counter += 1; //Increase the counter by 1
    if (Counter === 1) //If it's the first time that the video is played
    { //Starts the if condition
      document.querySelector(".ytp-subtitles-button.ytp-button").innerHTML.match('unavailable') === null && document.querySelector(".ytp-subtitles-button.ytp-button").ariaPressed === 'false' ? document.querySelector(".ytp-subtitles-button.ytp-button").click() : ''; //Auto enable the subtitles if available and they are disabled
    } //Finishes the if condition
  }); //Finishes the timeupdate event listener
})();