[Userscript]: Hide Context Sentence Translation

Since this one was a super quick fix, I’ve gone ahead and posted an update.
Thanks @polv for jumping in with a quick solution!

7 Likes

awesome, thank you!

I was using this WaniKani: Context Sentence Flash Cards - Chrome Web Store extension before and it had a click to see it thing going on it but it doesn’t work anymore. Is it possible for you to make it like that? This script doesn’t work on dark mode themes like Breeze Dark or Elementary Dark.

Can this made to be working with:

That would we really appreciated.

The one in the first post doesn’t hide sentence translations in Review for me, only Pattern of Use.

My correction
// ==UserScript==
// @name        WaniKani Hide Context Sentence
// @namespace   rfindley
// @description Hide context sentences until hovered.
// @version     1.0.7
// @match       https://www.wanikani.com/subjects/review
// @match       https://www.wanikani.com/subjects/*/lesson*
// @match       https://www.wanikani.com/vocabulary/*
// @match       https://www.wanikani.com/level/*/vocabulary/*
// @match       https://preview.wanikani.com/subjects/review
// @match       https://preview.wanikani.com/subjects/*/lesson*
// @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),
        .subject-collocations__collocation-text:not([lang="ja"]):not(:hover),
        .context-sentences .wk-text:not([lang="ja"]):not(:hover),
        a.page-nav__anchor#context ~ section.subject-section__content .subject-section__text--grouped :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'));
    }

}());
1 Like

Thanks! I may not have had reviews available (I don’t remember), and I knew reviews and lessons were supposed to share the same layout now. Apparently not! I’ll get your update integrated after breakfast.

This script isn’t working for me anymore. Was there a recent change to wanikani? I’m using google chrome.