Created
September 27, 2016 14:19
-
-
Save slash3r/d4483d7d9a1b2e40aa2dfee4a3a3c892 to your computer and use it in GitHub Desktop.
JCJP Enhancements [by slash3r]
This file contains 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 JCJP Enhancements [by slash3r] | |
// @namespace https://github.com/slash3r | |
// @version 1 | |
// @grant none | |
// @include http://japaneseclass.jp/lessons/* | |
// @include http://japaneseclass.jp/practice | |
// ==/UserScript== | |
var isPractice = false; | |
var newStyle = 'word-spacing: 10000px !important;white-space: nowrap;'; | |
var oldStyle = 'white-space: nowrap;'; | |
function isQuizVisible() { | |
if (isPractice) { | |
return true; | |
} | |
var isVisible = false; | |
var vocabQuiz = document.querySelector('.vocabulary-quiz, .kanji-quiz, .chapter-quiz'); | |
if (vocabQuiz && parseInt(vocabQuiz.style.getPropertyValue('opacity')) == 1) { | |
isVisible = true; | |
} | |
return isVisible; | |
} | |
function handleInput(key) { | |
if (!isQuizVisible()) { | |
return; | |
} | |
var answerOptions = document.querySelectorAll('.answer-option'); | |
if (answerOptions) { | |
if (answerOptions.length == 4) { | |
if (key >= 49 && key <= 52) { | |
answerOptions[3-(52-key)].click(); | |
return; | |
} | |
if (key == 83) { | |
for (var i = 0; i <= 4; i++) { | |
var inline = answerOptions[i].getElementsByClassName('inline')[0]; | |
var option = answerOptions[i].getElementsByClassName('option')[0]; | |
if (option.innerHTML.indexOf('・') == -1) { | |
return; | |
} | |
if (option.getAttribute('style') == newStyle) { | |
inline.setAttribute('style', oldStyle); | |
option.setAttribute('style', oldStyle); | |
} | |
else { | |
inline.setAttribute('style', newStyle); | |
option.setAttribute('style', newStyle); | |
} | |
} | |
} | |
} | |
} | |
} | |
(function () { | |
if (document.URL == "http://japaneseclass.jp/practice") { | |
isPractice = true; | |
} | |
document.addEventListener('keydown', function (e) { | |
if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) { | |
return; | |
} | |
if (e.keyCode == 83 || (e.keyCode >= 49 && e.keyCode <= 52)) { | |
handleInput(e.keyCode); | |
} | |
}, false); | |
}) (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment