Skip to content

Instantly share code, notes, and snippets.

@bo33b
Last active July 14, 2018 06:15
Show Gist options
  • Save bo33b/8485a04a0834a18bb1ceef71fad89b36 to your computer and use it in GitHub Desktop.
Save bo33b/8485a04a0834a18bb1ceef71fad89b36 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Duolingo Russian
// @description Duolingo Russian
// @namespace bo33b
// @author bo33b
// @version 1.1
// @match https://www.duolingo.com/*
// @grant none
// ==/UserScript==
(function(window, document) {
var RU = "яшертйуиопасдфгхжклзцчвбнм-щёэюыь-ЯШЕРТЙУИОПАСДФГХЖКЛЗЦЧВБНМ-ЩЁЭЮЫъ";
var EN = "qwertyuiopasdfghjklzxcvbnm-23478'-QWERTYUIOPASDFGHJKLZXCVBNM-@#$&*\"";
HTMLInputElement.prototype.insertAtCaret = HTMLTextAreaElement.prototype.insertAtCaret = function(text) {
var caret = this.selectionStart, content = this.value;
if (caret == content.length) return this.value += text;
this.value = content.substr(0, caret) + text + content.substr(this.selectionEnd);
this.selectionEnd = this.selectionStart = caret + text.length;
}
document.onkeypress = function(ev) {
var key = ev.key || String.fromCharCode(ev.charCode)
, el = document.querySelector('input, textarea');
if (el && EN.includes(key) && !(el.disabled||ev.ctrlKey||ev.altKey)) {
el.focus();
el.spellcheck = true;
if (el.placeholder == "Type in Russian") {
el.lang = 'ru';
el.insertAtCaret(RU[EN.indexOf(key)]);
el.dispatchEvent(new UIEvent('blur'));
ev.preventDefault();
if (el.value.includes('яа')||el.value.includes('тц'))
document.querySelector('h1').innerHTML+= '<br>Fool!';
}
}
if (key == '+')
document.querySelector('h1').innerHTML+=
`<pre style="position:absolute;left:0;font-size:14px">
. nominative = subj. - Я
. dative = of self - МНЕ
. genitive = of - МЕНЯ
. accusative = d.o. - МЕНЯ
. instrument = tool - МНОЙ
. preposition = in,at... - МНЕ</pre>`;
};
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment