Wanikani You Should Already Know This Reading

Inject mnemonics from other items into your lessons

当前为 2016-11-25 提交的版本,查看 最新版本

// ==UserScript==
// @name         Wanikani You Should Already Know This Reading
// @namespace    mempo
// @version      1.0
// @description  Inject mnemonics from other items into your lessons
// @author       Mempo
// @match        https://www.wanikani.com/lesson/session
// @match        http://www.wanikani.com/lesson/session
// @match        https://www.wanikani.com/vocabulary/*
// @match        http://www.wanikani.com/vocabulary/*
// @resource     qtipCSS http://cdn.jsdelivr.net/qtip2/3.0.3/jquery.qtip.css
// @require      http://cdn.jsdelivr.net/qtip2/3.0.3/jquery.qtip.js
// @grant        GM_getResourceText
// ==/UserScript==

(function() {
    //on lessons, define what section you're in by
    //#supplement-voc-meaning

    console.log("START WK YOU SHOULD ALREADY KNOW THIS READING");
    var qtipCSS = GM_getResourceText ("qtipCSS");
    var css = '.WKINJECT { ' +
              '    text-decoration: underline ' +
              '    color: blue ' +
              ' } ';
    
    
    
    addStyle(qtipCSS);
    addStyle(css);
    
    if (window.location.href.indexOf('vocabulary') != -1) { //on a vocabulary page
        $(".container .span12 > section p [lang=ja]").each(function(){
            if($(this).parent().next("section").attr("id") === "note-meaning"){ //meaning explanation
                $(this).parent().after('<div class="WKINJECT_MEANING"></div>');
            }else if($(this).parent().next("section").attr("id") === "note-reading"){ //reading explanation
                $(this).parent().after('<div class="WKINJECT_READING"></div>');
            }
            
            $(this).after('<div class="tooltiptext" style="display:none">'+
                          'Inject the <span class="WKINJECT" id="WKINJECT_MEANING" data-WKINJECT="'+$(this).html() +'" style="text-decoration:underline;color: blue;cursor:pointer">meaning</span> mnemonic of ' + $(this).html() + '<br>'+
                          'Inject the <span class="WKINJECT" id="WKINJECT_READING" data-WKINJECT="'+$(this).html() +'" style="text-decoration:underline;color: blue;cursor:pointer">reading</span> mnemonic of ' + $(this).html()+
                          '</div>');
            $(this).qtip({ // Grab some elements to apply the tooltip to
                content: {
                    text: $(this).next(".tooltiptext")

                },
                hide: {
                    event: false,
                    inactive: 2000
                }
            });
        });
    }
    
    $(".WKINJECT").on("click",function(event){
       
        if($(event.target).attr("id")==="WKINJECT_MEANING"){
            if(!$( "div.WKINJECT_MEANING" ).attr("id")){
                $( "div.WKINJECT_MEANING" ).load( "https://www.wanikani.com/vocabulary/" + event.target.dataset.wkinject + "/ .individual-item .span12 section.context-sentence + section p" , function(html){
                    $("div.WKINJECT_MEANING").before("<h3>Mnemonic for "+event.target.dataset.wkinject +"</h3>");
                    $("div.WKINJECT_MEANING").attr("id","WKINJECT_DONE");
                });
            }
        }else if($(event.target).attr("id")==="WKINJECT_READING"){
            if(!$( "div.WKINJECT_READING" ).attr("id")){
                $( "div.WKINJECT_READING" ).load( "https://www.wanikani.com/vocabulary/" + event.target.dataset.wkinject + "/ .individual-item .span12 section.context-sentence + section + section p" , function(html){
                    $("div.WKINJECT_READING").before("<h3>Mnemonic for "+event.target.dataset.wkinject +"</h3>");
                    $("div.WKINJECT_READING").attr("id","WKINJECT_DONE");
                });
            }
            
        }
    });
    
    function addStyle(aCss) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (head) {
            style = document.createElement('style');
            style.setAttribute('type', 'text/css');
            style.textContent = aCss;
            head.appendChild(style);
            return style;
        }
        return null;
    }
})();