[Userscript] WaniKani Leech List

What is it?
This script adds a Top Leeches section under the critical Items list on the Dashboard. It is an approximation of a no longer supported script.

55%20PM

How to Install?

  1. As always, make sure you have a script manager installed. If you don’t, follow these instructions.
  2. This script depends on the WaniKani Open Framework. Make sure you have that installed by following these instructions.
  3. Get the script here: https://greasyfork.org/en/scripts/372157-wanikani-dashboard-leech-list

Planned Features

Support

  • This script has been tested in Chrome and Firefox using Tampermonkey.
  • Please post any bugs/requests and I’ll get back to you as soon as I can.

Revision History

1.0.0 - Initial release.
1.2.1 - Replaced critical items with leech list, ability to see more leeches on separate page, round leech value to 2 decimal places. @Chikuhitsu

4 Likes

It’s kind of adorable that you based your script on my code and used my post as a template for yours. :blush:

1 Like

hehe yes, you should definitely be attributed here. I have never posted a script before, I am not a javascript developer by any means, and so had to use your code as a starting point for mine. I really appreciate you putting in all the work to get the leech stuff back up and running :slight_smile:

I am a little worried about the leech scripts becoming too splintered. For example, if I add a setting where people can change their leech threshold, my script and this one could start showing inconsistent data. I don’t know when I’ll have enough time, but maybe I’ll try re-adding this part of the script into mine and add settings so people can pick and choose which parts they want to display.

2 Likes

Sounds good to me :slight_smile: I agree, I’d rather it all be in one script.

Well sorry to splinter the script even further :sweat_smile: but I made this.


Also made a menu where you can the change amount of leeches, leeches per table and leechthreshold.leech%20table%20menu

leech%20table%20menu%20dialog
Result if leech threshold is set from 1 to 2:


Only typed most of this code this weekend so there are probably still some bugs in there though.

Like ukebox said I too would like it better if all of this code was in one script.

1 Like

My only recommendation would be to round the leech values to two decimal places (for display) so you don’t see stuff like 1.4142135[…].

I doubt I’ll have time to consolidate all of this any time soon. Maybe in a couple months when things (hopefully) settle down.

I made some small local changes to make the list properly replace the critical items and round scores to 2 decimals.

    function round(number, decimals)
    {
        return +(Math.round(number + "e+" + decimals) + "e-" + decimals);
    }

    function addTopLeechList(topLeeches) {
        var rows = ""
        topLeeches.forEach(function(item) {
            let row = `<tr class="${item.object}"><td><a href="${item.data.document_url}"><span lang="ja">${item.data.slug}</span><span class="pull-right">${round(item.leech_score, 2)}</span></a></td></tr>`
            rows+=row;
        });

        let sectionContent = `<h3 class="small-caps">Top Leeches</h3>
                  <table>
                    <tbody style="display: table-row-group;">
                      ${rows}
                    </tbody>
                  </table>`
        $('.low-percentage').html(sectionContent)
    }

Edit: I also managed to make it show all leeches on the critical-items page. I have another suggestion: Using the filters from “Additional Filters”, it would be possible to request only leech items from the framework (one only needs to specify the threshold value).

Also: How about hosting this on GitHub/BitBucket or something like that?

@seanblue, @Dani2 (figured this might interest you :wink: )

I didn’t see a good way to reuse the filter from Additional Filters, which is why I copied it for the dashboard script. What exactly are you suggesting?

Something like this to get the items:

	function test_items(items) {
		console.log(items);
	}
	
	var config = {
		wk_items: {
			options: {subjects: true, assignments: true},
			filters : {
				additionalFilters_leechTraining: '1.01'
			}
		}
	};
	
	wkof.ItemData.get_items(config).then(test_items);

Right, but I didn’t want to require people to install the Additional Filters script to use the dashboard one. Going through the same method has no benefit (other than code de-duplication) so I don’t think it really matters.

Of course, just pointing it out - it doesn’t solve everything anyway, since it still lacks the individual item’s score.

I still think it’d be better to have something like a “main module” for leech-related scripts, so that multiple ways to display or otherwise use leeches can work on a shared base (same formula and threshold).

For my situation, I’m used to having the SRS grid details, so I probably won’t switch back to having my leeches shown in the SRS boxes themselves - but replacing the critical items with leeches is something I’ll definitely use. And I’m sure there’d be even more ways to work with leeches. Which means, either one big monolith of a script with tons of options, or several smaller scripts with a common base.

I’d say it might be be worth considering if something like the leech score couldn’t be added to the open framework itself - it’s something pretty basic, after all.

The threshold for the dashboard scripts should be able to differ from Self Study. The reason being that in Self Study you can create more that one ruleset for filtering and you may set different leech thresholds for each.

That said, I do think it would be a good idea to combine all the dashboard leech scripts in some way. I likely won’t have time until November at the earliest, so we’ll see then. At that time I’ll also add a setting so you can change your leech threshold for the dashboard leech information.

I agree with the self study being independent.

But that doesn’t solve the problem of everyone who’s making a script that deals with leeches using their own independently configurable threshold…

I agree. I didn’t see your editing comment about the monolith. Even if I add all the existing functionality to my script, nothing will stop someone from creating another one later. I certainly don’t want to have to maintain or own all of the leech scripts.

Even if the leech filter is added to Open Framework, you could still change the filter value (leech threshold). So that may not be enough.

I’ve never tried adding a greasyfork library script, but that might be the right solution here. Then the library script could do the filtering and any script that needs that data can depend on it. Maybe then I could also figure out a way to reuse it for Additional Filters, but I’m less sure of how I’d do that.

Yeah, my thought was some kind of basic leech script that does the filtering and exposes the threshold value for configuration (because I think users should be able to decide what they consider a leech - just doing it once instead of for several smaller scripts). Then other scripts could get the items from there.

IF the calculation of the score could be integrated into the WKOF - so that every item we get from there comes with it’s leech score already filled - filtering would be trivial. The leech filter from additional filters could be integrated as well (since it wouldn’t need to do any fancy calculations anymore - just compare numbers). That way, both the self-study script and the “leech foundation module” could use the leech filter from the WKOF with their respective threshold values.

Sure thing, i’ll put this up on github so you can do a PR

1 Like

Sounds good ^^

I’ve added a way to display radicals correctly too (using characters or character_images instead of slug).

2 Likes

I incorporated your changes and updated on greasyfork. I also but them on github.

1 Like

So after reading the wanikani framework readme I figured out that instead of using these to filter:

function filterToActiveAssignments(items) {
		return items.filter(itemIsActiveAssignment);
	}

	function itemIsActiveAssignment(item) {
		let assignments = item.assignments;
		if (assignments === undefined) {
			return false;
		}

		let srsStage = getSrsStage(assignments);

		return srsStage >= 1 && srsStage <= 8;
	}

    function getSrsStage(assignments) {
		return assignments.srs_stage;
	}

We could just do this, right?

const config = {
		wk_items: {
			options: {
				review_statistics: true
			},
            filters: {
                level: '1..+0', //only retrieve items from lv 1 up to and including current level
                srs: {value: 'lock, init, burn', invert: true} //exlude locked, initial and burned items
            }
		}
	};
1 Like