WK Lesson Spoiler Tags

Makes example sentence translations visible on mouseover

当前为 2017-02-06 提交的版本,查看 最新版本

// ==UserScript==
// @name         WK Lesson Spoiler Tags
// @namespace    ktx_wk_lesson
// @version      0.1
// @description  Makes example sentence translations visible on mouseover
// @author       Karsten Rohweder
// @match        https://www.wanikani.com/lesson/session
// @grant        GM_addStyle
// ==/UserScript==

var $ = unsafeWindow.jQuery;

function addSpoilerEffect() {
    var elms = $('.context-sentence-group > p:nth-child(2)');
    if (elms.length > 0) {
        elms.addClass('ktx_spoiler');
        return true;
    }
    return false;
}

(function() {
    'use strict';
    GM_addStyle('.ktx_spoiler { color: transparent; text-shadow: 0 0 15px #aaa; } .ktx_spoiler:hover { color: black; text-shadow: none }');
    var observer = new MutationObserver(function(mutations){
        mutations.forEach(function(mutation){
            if (mutation.type == 'childList') {
                addSpoilerEffect();
            }
        });
    });
    var observerConfig = {
        attributes: true,
        childList: true,
        subtree: true
    };
    observer.observe(document.body, observerConfig);
})();