Greasy Fork is available in English.
Automatically submits your answer once it's correct.
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/370219/612023/Bunpro%3A%20Auto%20Commit%2020.js
// ==UserScript==
// @name Bunpro: Auto Commit 2.0
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically submits your answer once it's correct.
// @author Kumirei
// @include *bunpro.jp/study
// @require http://greasyfork.icu/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// @grant none
// ==/UserScript==
(function() {
//add the buttons bar if it's not already there
if (!$('#buttonsBar').length) addBar();
$('#buttonsBar .flexWrapper').append('<div class="barButton"><input id="JishoButton" type="button" value="Jisho" onclick="window.open(\'https://www.jisho.org/search/\' + parseSentence($(\'.study-question-japanese > span\')[0]))"></div>');
var answer = "";
var currentInput = "";
//check answer each time a key is released
$('#study-answer-input').on('keyup', function(e) {
//update current input value
currentInput = $('#study-answer-input')[0].value;
//if the input matches the stored answer, then submit it
if (currentInput == answer) {
$('#submit-study-answer').click();
}
});
//update variables when a new item is detected
waitForKeyElements('.level_lesson_info a', function(e) {
answer = "";
var sentence = parseSentence($('.study-question-japanese > span')[0]).replace(/\[.*\]$/g, '');
var matchSentence = new RegExp('^'+sentence+'$');
var startIndex = sentence.match(/\./).index;
var sentenceEnd = sentence.slice(startIndex + 2);
var matchSentenceEnd = new RegExp(sentenceEnd + '$');
$('.examples .japanese-example-sentence').each(function(i, e) {
var parsedSentence = parseSentence(e);
if (parsedSentence.match(matchSentence) != null) {
var endIndex = parsedSentence.match(matchSentenceEnd).index;
answer = parsedSentence.slice(startIndex, endIndex);
console.log('ANSWER:', answer);
}
});
if (answer == "") {
console.log('No answer found');
console.log('Sentence:', sentence);
console.log('Sentence End:', sentenceEnd);
$('.examples .japanese-example-sentence').each(function(i, e) {console.log(parseSentence(e));});
alert('NO ANSWER FOUND');
}
});
//Extracts the sentence from the sentence elements
function parseSentence(sentenceElem) {
var text = "";
sentenceElem.childNodes.forEach(function(elem) {
// find the text in each kind of element and append it to the text string
var name = elem.nodeName;
if (name == "#text") {
text += elem.data;
} else if (name == "STRONG" || name == "SPAN") {
if (elem.className == "chui") {
if (!elem.children.length) text += elem.innerText
else text += elem.children[0].children[1].innerText;
} else if (elem.className == "study-area-input") {
text += ".*";
} else if (elem.className == "name-highlight") {
text += parseSentence(elem);
} else if (name == "STRONG" && elem.children.length) {
text += parseSentence(elem);
} else {
text += elem.innerText;
}
} else if (name == "RUBY") {
text += elem.children[1].innerText;
}
});
return text;
}
//adds the bar with buttons
function addBar() {
$('#check-grammar').before('<div id="buttonsBar"><div class="flexWrapper"</div></div>');
$('head').append('<style id="ButtonBarStyle">'+
'@media (max-width: 480px) {'+
'#buttonsBar .barButton {'+
'height: 30px;'+
'font-size: 12px;'+
'}'+
'}'+
'#buttonsBar {'+
'margin-top: 2.5px;'+
'}'+
'#buttonsBar .flexWrapper {'+
'height: 40px;'+
'display: flex;'+
'flex-wrap: wrap;'+
'margin: 0 -2.5px;'+
'}'+
'#buttonsBar .barButton {'+
'flex: 1;'+
'margin: 2.5px;'+
'}'+
'#buttonsBar .barButton input {'+
'background: rgba(25,34,49,0.8);'+
'height: 100% !important;'+
'color: white;'+
'border: 0;'+
'}'+
'#buttonsBar .barButton input:hover {'+
'color: rgb(103, 114, 124);'+
'}'+
'</style>');
}
})();