Obtain-Kanji-Info-from-jpdb.io-for-Mnemonic-generation

Will insert into the clipboard the info already parsed so that you only need to paste in for generating mnemonics

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Obtain-Kanji-Info-from-jpdb.io-for-Mnemonic-generation
// @namespace    http://tampermonkey.net/
// @version      2024-01-14
// @description  Will insert into the clipboard the info already parsed so that you only need to paste in for generating mnemonics
// @author       Fernando
// @match        https://jpdb.io/review
// @icon         https://www.google.com/s2/favicons?sz=64&domain=jpdb.io
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let copyToClipBKanjiInfo = () => {
        let radicalDivs = document.querySelectorAll('.subsection-composed-of-kanji div.subsection .description');
        let radicals = Array.from(radicalDivs).map(radicalDiv => radicalDiv.textContent.trim());

        let keyword = document.querySelector('.subsection-composed-of-kanji').nextElementSibling.querySelector('.subsection').textContent.trim();

        let finalText = `Radicals: ${radicals.join(', ')}\nKeyword: ${keyword}`;

        navigator.clipboard.writeText( finalText );
    }

    let insertButtonForKanjiInfoGen = () => {
        let box = document.querySelector('.review-reveal .result.kanji .vbox.gap');

        const button = document.createElement('button');
        button.textContent = 'Copy Kanji Info for Mnemonic generation';

        button.addEventListener('click', copyToClipBKanjiInfo);

        box.appendChild(button);
    }

    if ( document.querySelectorAll('.subsection-composed-of-kanji') ) insertButtonForKanjiInfoGen();

})();