Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philomuzzi/e8df7d82466a522b8271ff98c9754674 to your computer and use it in GitHub Desktop.
Save philomuzzi/e8df7d82466a522b8271ff98c9754674 to your computer and use it in GitHub Desktop.
Translate to Chinese automatically. youtube自动翻译中文简体
// ==UserScript==
// @name 自动翻译->字幕中文简体
// @namespace http://tampermonkey.net/
// @version 0.1
// @description translate to Chinese automatically.
// @author qwertyuiop6
// @match https://www.youtube.com/watch*
// @require https://cdn.bootcss.com/jquery/3.4.0/jquery.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
function translateToChinese(){
var sub = $('[role="menuitem"]:contains("字幕")');
if(!sub.length) return;
sub.click();
var subc = $('[role="menuitemradio"]:contains("中文(简体)")');
if (subc.length) {
subc.click();
return;
}
var subtc = $('[role="menuitemradio"]:contains("中文(台湾)")');
if (subtc.length) {
subtc.click();
return;
}
var etc = $('[role="menuitemradio"]:contains("英语")');
if (etc.length) {
etc.click();
return;
}
var autoetc = $('[role="menuitemradio"]:contains("英语(自动生成)")');
if (autoetc.length) {
autoetc.click();
return;
}
}
function onLoadStart(){
$('.ytp-subtitles-button[aria-pressed="false"]').click();
$('.ytp-settings-button').click();
translateToChinese();
$('.ytp-settings-button').click();
}
$('video').on('loadstart', onLoadStart).trigger('loadstart');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment