Greasy Fork

Greasy Fork is available in English.

Bunpro: Copy Sentences

Adds buttons to copy the Japanese and English sentences in review.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bunpro: Copy Sentences
// @namespace    http://tampermonkey.net/
// @version      0.4.14
// @description  Adds buttons to copy the Japanese and English sentences in review.
// @author       Kumirei
// @include      *bunpro.jp/*
// @exclude      *community.bunpro.jp*
// @require      http://greasyfork.icu/scripts/370623-bunpro-helpful-events/code/Bunpro:%20Helpful%20Events.js?version=974369
// @require      http://greasyfork.icu/scripts/370219-bunpro-buttons-bar/code/Bunpro:%20Buttons%20Bar.js?version=1044000
// @grant        none
// ==/UserScript==

;(function () {
    //add buttons
    $('HTML')[0].addEventListener('quiz-page', function () {
        if (!$('#copyJP').length)
            buttonsBar.addButton('copyJP', 'Copy JP', () =>
                copyText(parseSentence($('.study-question-japanese > div')[0])),
            )
        if (!$('#copyEN').length)
            buttonsBar.addButton('copyEN', 'Copy EN', () =>
                copyText($('.study-question-english-hint > span')[0].textContent),
            )
    })

    //Extracts the sentence from the sentence element
    function parseSentence(sentenceElem) {
        var sentence = ''

        var list = sentenceElem.childNodes

        list.forEach(function (currentValue, currentIndex, listObj) {
            var elem = currentValue
            var name = currentValue.tagName
            var className = currentValue.className

            if (name == 'SPAN') {
                if (['study-area-input'].includes(className)) {
                    sentence += '____'
                } else if (['vocab-popout', 'gp-popout'].includes(className)) {
                    const items = elem.childNodes
                    items.forEach(function (item) {
                        if (item.tagName == 'RUBY') {
                            sentence += item.childNodes[0].data
                        } else {
                            sentence += item.textContent
                        }
                    })
                }
            } else if (name == 'RUBY') {
                sentence += elem.childNodes[0].data
            } else {
                if (elem instanceof HTMLElement) {
                    sentence += elem.textContent
                } else if (elem instanceof Text) {
                    sentence += elem.textContent
                }
            }
        })

        return sentence
    }

    //copies the text
    copyText = function (text) {
        navigator.clipboard.writeText(text)
    }
})()