// ==UserScript== // @name Duolingo Auto IME On-Off // @namespace mog86uk-duo-autoime // @version 1.02 // @description Forces IME to switch between English and Japanese automatically for each typing question. // @author mog86uk (aka. testmoogle) // @match https://www.duolingo.com/* // @exclude https://www.duolingo.com/discussion // @exclude https://www.duolingo.com/topic/* // @exclude https://www.duolingo.com/comment/* // @require http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js // @grant none // @run-at document-idle // @downloadURL none // ==/UserScript== jQuery.noConflict(); jQuery(document).ready(function($) { 'use strict'; var typeLang = ""; var typeLangPrevious = ""; var alertShown = 0; function Start(mutationRecords) { if (/^https:\/\/www\.duolingo\.com.*\/practice$/.test(window.location.href) || /^https:\/\/www\.duolingo\.com\/skill\/ja\/.+\/.+$/.test(window.location.href)) { if (!alertShown) { if (typeof $('html').css('ime-mode') === 'undefined' && typeof $('html').prop('inputMode') === 'undefined') { alert("If you're using Chrome or Opera, you'll need to enable the following browser flag:\n\n#enable-experimental-web-platform-features\n\nFirefox should work fine as it is, but Chrome and Opera need to enable this flag to be able to make use of the 'inputmode' experimental html attribute. (See the userscript's page on greasyfork if you need more help with enabling this browser flag.) ^^"); } alertShown = 1; } else { mutationRecords.forEach (function (mutation) { typeLang = $('textarea[data-test="challenge-translate-input"]').attr('lang'); if (typeLang !== typeLangPrevious || (typeLang === 'en' && $('textarea[data-test="challenge-translate-input"]').css('ime-mode') === 'auto')) { if (typeLang === 'en') { $('textarea[data-test="challenge-translate-input"]').attr('inputmode', 'latin').css('ime-mode', 'disabled').blur().focus(); } else if (typeLang === 'ja') { $('textarea[data-test="challenge-translate-input"]').attr('inputmode', 'kana').css('ime-mode', 'active').blur().focus(); } typeLangPrevious = typeLang; } }); } } } if (window.top == window.self) { var observerOfStuff = new MutationObserver(Start); observerOfStuff.observe(document.body, { attributes: true, subtree: true }); } });