WaniKani Hide Context Sentence

Hide context sentences until hovered.

当前为 2022-10-21 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        WaniKani Hide Context Sentence
// @namespace   rfindley
// @description Hide context sentences until hovered.
// @version     1.0.5
// @match       https://www.wanikani.com/review/session*
// @match       https://www.wanikani.com/lesson/session*
// @match       https://www.wanikani.com/vocabulary/*
// @match       https://www.wanikani.com/level/*/vocabulary/*
// @match       https://preview.wanikani.com/review/session*
// @match       https://preview.wanikani.com/lesson/session*
// @match       https://preview.wanikani.com/vocabulary/*
// @match       https://preview.wanikani.com/level/*/vocabulary/*
// @copyright   2015+, Robin Findley
// @license     MIT; http://opensource.org/licenses/MIT
// @run-at      document-end
// @grant       none
// ==/UserScript==

(function(gobj) {
    var css = `
        .context-sentence-group p:not([lang="ja"]):not(:hover) {
            background-color:#ccc;
            color:#ccc;
            text-shadow:none;
        }
    `;

    // Function to add a style tag.
    function add_css(css) {
        let style = document.createElement('style');
        style.setAttribute('type', 'text/css');
        let text = document.createTextNode(css);
        style.appendChild(text);
        document.head.append(style);
    }

    // Insert CSS
    add_css(css);

    // Add '.context-sentence-group' to sentences on Vocab pages.
    if (window.location.pathname.match(/^\/vocabulary\//)) {
        Array.from(document.querySelectorAll('.subject-section--context .subject-section__subtitle'))
            .find((node) => node.textContent.match('Context Sentences'))
            .closest('section')
            .querySelectorAll('.subject-section__text')
            .forEach((elem) => elem.classList.add('context-sentence-group'));
    }

}());