[UserScript] Info page tweaks

After WaniKani added the ‘Visually Similar Kanji section’, my first thought was “I want this at the top”, so I did this.
Each section is collapsible, and reorder-able (drag and drop).  After you reorder the sections, this order is auto-saved.

A note: If you are using the other ‘Similar Kanji’ script, you will need to make an adjustment in the scripts settings (found on the dashboard under the menu button at the top right)

https://greasyfork.org/en/scripts/26164-wanikani-info-page-tweaks



1 Like

Noooooooooo, the script was deleted on greasemonkey. Please bring it back D:

3 Likes

Anyone got it saved, or currently using it? Please put it somewhere, and doesn’t have to be GreasyFork.

Maybe, right here, or Github Gist.

If I recall correctly, it broke at some point, and since I was barely using it, and only seven other people had ever installed it, I just said ‘eh screw it’.
But, here ya go if you wanna give it a go.

// ==UserScript==
// @name         WaniKani Info Page Tweaks
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  try to take over the world!
// @author       You
// @match        https://www.wanikani.com/dashboard*
// @match        https://www.wanikani.com/kanji/*
// @match        https://www.wanikani.com/radicals/*
// @match        https://www.wanikani.com/vocabulary/*
// @require      https://greasyfork.org/scripts/22751-wanikani-settings/code/WaniKani%20Settings.js?version=166555
// @require      https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// @grant        none
// ==/UserScript==
 
window.onload = function(e){ 
    'use strict';
    if(window.location.pathname.indexOf('kanji/') > -1 || window.location.pathname.indexOf('radicals/') > -1 || window.location.pathname.indexOf('vocabulary/') > -1){
        if((getSetting('SimilarKanjiScript') === "1") && (window.location.pathname.indexOf('kanji/') > -1)){
            waitForKeyElements ("#similar_kanji", goItemTweaks, true);
        }
        else {
            goItemTweaks();
        }
        addStyle('.collapsable {' +
                 '  cursor: pointer;' +
                 '}' +
                '#itemsSortable {' +
                '  list-style-type: none;' +
                 '  margin-left: 0;' +
                '}');
    } else {
        makeSettings("Info Pages",{1: {Name: "SimilarKanjiScript", Display: "Similar Kanji Script Installed?", Type: "checkbox", Default: "0"}});
    }
};
 
function goItemTweaks(){
    debugger;
    var start;
    switch(window.location.pathname.substring(1,2)){
        case 'k':
        case 'K':
            start = 1;
            break;
        case 'r':
        case 'R':
            start = 0;
            break;
        case 'v':
        case 'V':
            start = 2;
            break;
    }
    $('h2:gt(' + start + ')').click(function (){
        $(this).parent().children().not('h2').toggle();
    });
    $.each($('h2:gt(' + start + ')'),function(){
        $(this).parent().children().not('h2').hide();
        $(this).addClass('collapsable');
    });
    $('head').append('<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css" type="text/css" />');
	if (typeof jQuery.ui == 'undefined') {
        jQuery.getScript("https://code.jquery.com/ui/1.12.0/jquery-ui.js", function(data2, status, jqxhr) {
        });
    }
    $('section:has(h2):not("#information"):not("#progress"):not("#note-meaning"):not("#note-reading"):not(:last)').wrapAll('<ul id="itemsSortable">');
    var i = 0;
    $.each($('section:has(h2):not("#information"):not("#progress"):not("#note-meaning"):not("#note-reading"):not(:last)'), function(item,value){
        $(value).wrap('<li id="li' + i + '" class="liItem">');
        i = i+1;
    });
    setTimeout(function(){
        $('#itemsSortable').sortable({
            update: function( event, ui ) {
                setNewOrderVar();
            }
        });
    }, 2000);
    setTimeout(function(){
        reorder();
    }, 2000);
}
 
function setNewOrderVar(){
    switch(window.location.pathname.substring(1,2)){
        case 'k':
        case 'K':
            localStorage.setItem("WKInfoTweakOrderKanji",$('#itemsSortable').sortable("toArray"));
            break;
        case 'r':
        case 'R':
            localStorage.setItem("WKInfoTweakOrderRadicals",$('#itemsSortable').sortable("toArray"));
            break;
        case 'v':
        case 'V':
            localStorage.setItem("WKInfoTweakOrderVocab",$('#itemsSortable').sortable("toArray"));
            break;
    }
}
 
function reorder(){
    var order;
    switch(window.location.pathname.substring(1,2)){
        case 'k':
        case 'K':
            order = getSetting('WKInfoTweakOrderKanji').split(',');
            break;
        case 'r':
        case 'R':
            order = getSetting('WKInfoTweakOrderRadicals').split(',');
            break;
        case 'v':
        case 'V':
            order = getSetting('WKInfoTweakOrderVocab').split(',');
            break;
    }
    $.each(order,function(item,value){
        $("#" + value).appendTo($('#itemsSortable'));
    });
}
1 Like

Wait for Key Elements is also gone, but it might be replaceable with MutationObserver.

WaniKani Settings is still there, but it might be replaceable with Gorbit’s shared libraries, if required.

Lastly, debugger; needs to be removed.

Yeah, greasyfork removes the waitForKeyElements library from time to time. I’ve had to find or publish my own a few times.
Settings, was a pre-wkof. If I were to make this today, I’d use the wkof library.
debuggers. Those damn debuggers. I’m awful at remembering to remove those.

1 Like