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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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();

})();