WaniKani Community prioritize Japanese glyphs

Prioritization of Japanese glyphs for Han unification

目前为 2022-02-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         WaniKani Community prioritize Japanese glyphs
// @namespace    https://github.com/patarapolw
// @version      0.1.1
// @description  Prioritization of Japanese glyphs for Han unification
// @author       polv
// @license      MIT
// @match        https://community.wanikani.com/*
// @icon         https://www.google.com/s2/favicons?domain=wanikani.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    new MutationObserver((muts) => {
        for (const mut of muts) {
            mut.addedNodes.forEach((n) => {
                if (n instanceof HTMLElement) {
                    injectLang(n)
                }
            })
        }
    }).observe(document.body, {
        childList: true,
        subtree: true
    })

    injectLang(document.body)
})()

function injectLang(el, lang='ja-JP') {
    el.querySelectorAll(':not([lang])').forEach((it) => {
        let parent = it.parentElement
        while (parent) {
            const lang0 = parent.getAttribute('lang')
            if (parent.tagName.toLocaleUpperCase() !== 'HTML' && lang0 && lang0 !== lang && lang0 !== 'en') {
                return
            }
            parent = parent.parentElement
        }

        it.setAttribute('lang', lang)
  })
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址