jpdb.io - show non-redundant vocab on learn page

Replaces the "You know" known words stat with the "Total known non-redundant vocabulary" value

目前為 2025-09-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         jpdb.io - show non-redundant vocab on learn page
// @namespace    http://tampermonkey.net/
// @description  Replaces the "You know" known words stat with the "Total known non-redundant vocabulary" value
// @version      1.0
// @author       JawGBoi
// @match        https://jpdb.io/learn*
// @grant        none
// @run-at       document-idle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    const totalWords = document.querySelector('table.cross-table tr:nth-child(2) td:nth-child(2)');
    const knownWords = document.querySelector('table.cross-table tr:nth-child(2) td:last-child');
    const nonRedundantSection = document.querySelector('table.cross-table + p');

    // script can only run if required elements are found
    if (nonRedundantSection && totalWords && knownWords) {
        try {
            // find the number at the end of the paragraph's text:
            const nonRedundantText = nonRedundantSection.textContent;
            const nonRedundantMatch = nonRedundantText.match(/(\d+)$/);
            const nonRedundantCount = parseInt(nonRedundantMatch[1], 10);

            // get total word count
            const totalNoWord = parseInt(totalWords.textContent.replace(/,/g, ''), 10);

            nonRedundantSection.remove(); // no need for the redundant words section anymore

            // recalculate percentage:
            let newPercentage = 0;
            if (totalNoWord > 0) {
                newPercentage = Math.floor((nonRedundantCount / totalNoWord) * 100);
            }

            // 5. Format the new string and update the 'You know' cell.
            knownWords.textContent = `${nonRedundantCount} (${newPercentage}%)`;

        }
        catch (error)
        {
            console.error("jpdb non redundant vocab script error:", error);
        }
    }
}
)();