Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save returnk/6d65d389a2d8d9a7a4311ef72c88f87f to your computer and use it in GitHub Desktop.
Save returnk/6d65d389a2d8d9a7a4311ef72c88f87f to your computer and use it in GitHub Desktop.

Revisions

  1. @qwertyuiop6 qwertyuiop6 revised this gist Apr 19, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion TranslateToChineseOnYouTube.user.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    // @description translate to Chinese automatically.
    // @author qwertyuiop6
    // @match https://www.youtube.com/watch*
    // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
    // @require https://cdn.bootcss.com/jquery/3.4.0/jquery.min.js
    // @grant none
    // ==/UserScript==

  2. @qwertyuiop6 qwertyuiop6 revised this gist Nov 16, 2018. No changes.
  3. @qwertyuiop6 qwertyuiop6 revised this gist Sep 15, 2018. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions TranslateToChineseOnYouTube.user.js
    Original file line number Diff line number Diff line change
    @@ -13,19 +13,19 @@
    'use strict';

    function translateToChinese(){
    var 字幕 = $('[role="menuitem"]:contains("字幕")');
    if(!字幕.length) return;
    字幕.click();
    var 中文简 = $('[role="menuitemradio"]:contains("中文(简体)")');
    if (中文简.length) {
    中文简.click();
    var sub = $('[role="menuitem"]:contains("字幕")');
    if(!sub.length) return;
    sub.click();
    var subc = $('[role="menuitemradio"]:contains("中文(简体)")');
    if (subc.length) {
    subc.click();
    } else {
    var 自动翻译 = $('[role="menuitemradio"]:contains("自动翻译")');
    if (!自动翻译.length) return;
    自动翻译.click();
    var 自动翻译中文 = $('[role="menuitemradio"]:contains("中文(简体)")');
    if (!自动翻译中文.length) return;
    自动翻译中文.click();
    var autoTrans = $('[role="menuitemradio"]:contains("自动翻译")');
    if (!autoTrans.length) return;
    autoTrans.click();
    var autoTransC = $('[role="menuitemradio"]:contains("中文(简体)")');
    if (!autoTransC.length) return;
    autoTransC.click();
    }
    }

  4. @qwertyuiop6 qwertyuiop6 created this gist Sep 15, 2018.
    39 changes: 39 additions & 0 deletions TranslateToChineseOnYouTube.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    // ==UserScript==
    // @name 自动翻译->字幕中文简体
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @description translate to Chinese automatically.
    // @author qwertyuiop6
    // @match https://www.youtube.com/watch*
    // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
    // @grant none
    // ==/UserScript==

    (function() {
    'use strict';

    function translateToChinese(){
    var 字幕 = $('[role="menuitem"]:contains("字幕")');
    if(!字幕.length) return;
    字幕.click();
    var 中文简 = $('[role="menuitemradio"]:contains("中文(简体)")');
    if (中文简.length) {
    中文简.click();
    } else {
    var 自动翻译 = $('[role="menuitemradio"]:contains("自动翻译")');
    if (!自动翻译.length) return;
    自动翻译.click();
    var 自动翻译中文 = $('[role="menuitemradio"]:contains("中文(简体)")');
    if (!自动翻译中文.length) return;
    自动翻译中文.click();
    }
    }

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