Greasy Fork

来自缓存

Greasy Fork is available in English.

Duolingo IME Auto-Toggler

Automatically toggles between IME on and off states when doing the Japanese, Korean, and Chinese Duolingo courses (and their reverse trees).

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Duolingo IME Auto-Toggler
// @namespace    mog86uk-duolingo-ime-auto-toggler
// @version      0.2
// @description  Automatically toggles between IME on and off states when doing the Japanese, Korean, and Chinese Duolingo courses (and their reverse trees).
// @author       mog86uk (a.k.a. testmoogle)
// @include      /^https?:\/\/www\.duolingo\.(com|cn)($|\/.*$)/
// @noframes
// ==/UserScript==

/*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! This userscript is for FIREFOX only !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/

(function () {
    'use strict';
    var lastTitle;

    function addGlobalStyleId(css, id) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        style.id = id;
        head.appendChild(style);
    }

    addGlobalStyleId('', 'styleAutoIME');

    function main() {
	    var j4e, k4e, z4e, e4j, e4k, e4z;

	    // Japanese for English speakers
	    j4e =`
			textarea[placeholder="Type in Japanese"],
			input[placeholder="Type in Japanese"] {
				ime-mode: active;
			}
			textarea[placeholder="Type in English"],
			input[placeholder="Type in English"] {
				ime-mode: disabled;
			}`;

	    // Korean for English speakers
		k4e =`
			textarea[placeholder="Type in Korean"],
		    input[placeholder="Type in Korean"] {
		        ime-mode: active;
		    }
		    textarea[placeholder="Type in English"],
		    input[placeholder="Type in English"] {
		        ime-mode: disabled;
		    }`;

	    // Chinese for English speakers
	    z4e =`
	    	textarea[placeholder="Type in Chinese"],
	        input[placeholder="Type in Chinese"] {
	            ime-mode: active;
	        }
	        textarea[placeholder="Type in English"],
	        input[placeholder="Type in English"] {
	            ime-mode: inactive;
	        }`;

	    // English for Japanese speakers (a.k.a. "Japanese reverse tree")
	    e4j =`
	    	textarea[placeholder="日本語で入力してください"],
	        input[placeholder="日本語で入力してください"] {
	            ime-mode: active;
	        }
	        textarea[placeholder="英語で入力してください"],
	        input[placeholder="英語で入力してください"] {
	            ime-mode: disabled;
	        }`;

	    // English for Korean speakers (a.k.a. "Korean reverse tree")
	    e4k =`
	    	textarea[placeholder="한국어로 입력"],
	        input[placeholder="한국어로 입력"] {
	            ime-mode: active;
	        }
	        textarea[placeholder="영어로 입력"],
	        input[placeholder="영어로 입력"] {
	            ime-mode: disabled;
	        }`;

	    // English for Chinese speakers (a.k.a. "Chinese reverse tree")
	    e4z =`
	    	textarea[placeholder="使用中文键入"],
	        input[placeholder="使用中文键入"] {
	            ime-mode: active;
	        }
	        textarea[placeholder="使用英语键入"],
	        input[placeholder="使用英语键入"] {
	            ime-mode: inactive;
	        }`;

	    switch (document.title) {
	    	case "Duolingo | Learn Japanese for free":
	        	document.getElementById('styleAutoIME').innerHTML = j4e;
	            break;
	    	case "Duolingo | Learn Korean for free":
	        	document.getElementById('styleAutoIME').innerHTML = k4e;
	            break;
	    	case "Duolingo | Learn Chinese for free":
	        	document.getElementById('styleAutoIME').innerHTML = z4e;
	            break;
	    	case "Duolingo | 無料で英語を学ぼう":
	    		document.getElementById('styleAutoIME').innerHTML = e4j;
	            break;
	    	case "듀오링고 | 무료로 영어를 배우세요.":
	    		document.getElementById('styleAutoIME').innerHTML = e4k;
	            break;
	    	case "多邻国 | 免费学习英语":
	    		document.getElementById('styleAutoIME').innerHTML = e4z;
	            break;
	    }
	}

    function checkTitle() {
        if (lastTitle != document.title) {
            main();
            lastTitle = document.title;
        }
        setTimeout(checkTitle, 2000);
    }

    checkTitle();
})();