NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Doulingo Layout Alarm // @namespace http://ilnicki.me/ // @version 0.2 // @description Play sound when you use wrong keyboard layout on Doulingo site. // @author ilnicki // @match https://www.duolingo.com/* // @grant none // ==/UserScript== $( document ).ready(function() { var charmaps = [{ code: 'en', chars: '`1234567890-=' + 'qwertyuiop[]' + 'asdfghjkl;\'\\' + 'zxcvbnm,./' + '~!@#$%^&*()_+' + 'QWERTYUIOP{}' + 'ASDFGHJKL:"|' + 'ZXCVBNM<>? ' }, { code: 'ru', chars: 'ё1234567890-=' + 'йцукенгшщзхъ' + 'фывапролджэ\\' + 'ячсмитьбю.' + 'Ё!"№;%:?*()_+' + 'ЙЦУКЕНГШЩЗХЪ' + 'ФЫВАПРОЛДЖЭ/' + 'ЯЧСМИТЬБЮ, ' }]; var checkLayout = function(code, text) { var charmap; for (var i = 0; i < charmaps.length; i++) { if (charmaps[i].code === code) { charmap = charmaps[i]; break; } } if(charmap === null) return true; for (i = 0; i < text.length; i++) { if (charmap.chars.indexOf(text[i]) == -1) { return false; } } return true; }; $(document).keyup(function(e) { if (e.keyCode != 8) { var inputs = $('#text-input, #word-input'); if (inputs.is(':focus')) { if (!checkLayout(inputs.attr('lang'), inputs.val())) { soundManager.wrongSound.play(); } } } }); });