Greasy Fork

Greasy Fork is available in English.

Bunpro: Jisho Button

Searches the sentence on Jisho.

当前为 2021-09-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Bunpro: Jisho Button
// @namespace    http://tampermonkey.net/
// @version      0.5.9
// @description  Searches the sentence on Jisho.
// @author       Kumirei
// @include      *bunpro.jp/*
// @exclude      *community.bunpro.jp*
// @require      http://greasyfork.icu/scripts/370623-bunpro-helpful-events/code/Bunpro:%20Helpful%20Events.js?version=974345
// @require      http://greasyfork.icu/scripts/370219-bunpro-buttons-bar/code/Bunpro:%20Buttons%20Bar.js?version=654288
// @grant        none
// ==/UserScript==

(function() {
    //Wait until we're on the study page and can add the button
    $('HTML')[0].addEventListener('quiz-page', function() {
        //add button
        buttonsBar.addButton('JishoButton', 'Jisho', 'window.open(\'https://www.jisho.org/search/\' + parseSentence($(\'.study-question-japanese > div\')[0]))');

        //Bind J to the Jisho button
        $('#study-answer-input').on('keyup', function(e) {
            if (e.which == 74 && $('#submit-study-answer').attr('value') == "Next") {
                $('#JishoButton').click();
            }
        });
    });
})();

//Extracts the sentence from the sentence elements
parseSentence = function(sentenceElem) {
    var sentence = "";
    sentenceElem.childNodes.forEach(function(elem) {
        // find the text in each kind of element and append it to the sentence string
        var name = elem.nodeName;
        if (name == "#text") {
            sentence += elem.data;
        }
        else if (name == "STRONG" && elem.children.length) {
            sentence += elem.children[0].childNodes[0].data;       // with kanji in url
            //sentence += elem.children[0].children[1].innerText;     // with kana in url
        }
        else if (name == "SPAN" && elem.className == "study-area-input") {
            if (elem.innerText == "") sentence += "____";
            else sentence += elem.innerText;
        }
        else if (name == "RUBY") {
            sentence += elem.childNodes[0].data;       // with kanji in url
            //sentence += elem.children[1].innerText;     // with kana in url
        }
    });
    return sentence;
};