[UserScript] Info page tweaks

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