Last active
May 30, 2017 08:43
-
-
Save romul/e14714364315642c46489ad765f19b27 to your computer and use it in GitHub Desktop.
Добавляет возможность проходить задания в ichebnik.ru при помощи клавиатуры.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Ichebnik Keyboard Input | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Добавляет возможность проходить задания в ichebnik.ru при помощи клавиатуры. | |
// @author Roman Smirnov | |
// @match http://ichebnik.ru/*/* | |
// @match https://ichebnik.ru/*/* | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// для замещения сокращенной версии на сайте | |
setInterval(function(){ $("body").unbind("keypress"); }, 100); | |
function getLetter(char){ | |
switch (char) { | |
case "A": | |
return "á"; | |
case "O": | |
return "ó"; | |
case "U": | |
return "ú"; | |
case "E": | |
return "é"; | |
case "I": | |
return "í"; | |
case "N": | |
return "ñ"; | |
default: | |
return char; | |
} | |
} | |
function clickInsideMestTable(n){ | |
switch (n) { | |
case 1: | |
$(".mest:first div:contains(yo)").click(); | |
break; | |
case 2: | |
$(".mest:first div:contains(tú)").click(); | |
break; | |
case 3: | |
$(".mest:first div:contains(él)").click(); | |
$(".mest:first div:contains(ella)").click(); | |
$(".mest:first div:contains(Usted)").click(); | |
$(".mest:first div:contains(ellas)").click(); | |
$(".mest:first div:contains(Ustedes)").click(); | |
break; | |
case 4: | |
$(".mest:first div:contains(nosotros)").click(); | |
$(".mest:first div:contains(nosotras)").click(); | |
break; | |
case 5: | |
$(".mest:first div:contains(vosotros)").click(); | |
$(".mest:first div:contains(vosotras)").click(); | |
break; | |
case 6: | |
$(".mest:first div:contains(ellos)").click(); | |
$(".mest:first div:contains(ellas)").click(); | |
$(".mest:first div:contains(Ustedes)").click(); | |
break; | |
} | |
} | |
$(document).keypress(function(e) { | |
if ($("#text_dictant").length) { | |
return; | |
} | |
if (e.charCode == 13) { | |
if ($(".snext:first").length) { | |
$(".snext:first").click(); | |
} else { | |
$(".slide_link_start:first").click(); | |
} | |
} else if (e.charCode >= 49 && e.charCode <= 55) { | |
if ($(".yui-strupel-table:first").length) { | |
$(".yui-strupel-table:first td:nth-child("+e.key+")").click(); | |
} else if ($(".table_nm:first").length) { | |
$(".table_nm:first td:nth-child("+e.key+")").click(); | |
} else if ($(".mest:first").length) { | |
clickInsideMestTable(e.charCode-48); | |
} | |
} else { | |
var letter = getLetter(e.key); | |
var letterDiv = Array.from($(".bf_letter:contains("+letter+")")).filter(function(el){ return el.innerText == letter; })[0]; | |
if (letterDiv) { letterDiv.click(); } | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment