[Userscript] Level Duration 2.0

I have found that the original Level Duration script is not entirely accurate, and is rather bulky. Normally I would just go into the script itself and modify it to my wishes, but it’s a bit of a mess; so I decided to make a new one.

This script utilises WKOF to fetch the current level’s unlock date instead of just using the first time the script saw you at the level. Thanks to this the script is now more accurate and much smaller.

I didn’t add any display options, unlike the other script, but I instead made sure it does not take up any extra space in the header. If you would rather have it somewhere else then I might reconsider.

Since posting one display option has been added. You can now choose to display days and hours instead of fractions of days. Example 4 days 4 hours instead of 4.2 days. You can find the setting in the scripts settings in the menu.

Example:

Available at

https://greasyfork.org/en/scripts/41084-wanikani-level-duration

38 Likes

Let’s see if my browser can handle one more script… :smiling_imp:

9 Likes

I like it, very sleek, thanks a lot :slight_smile:

1 Like

Nice! I think I’ll switch over to this one but probably make a local modification to make it look a bit more like the old one but without the extra spacing which is a good idea.

Was thinking of something like:

.level-duration {
    text-align: center;
    color: #999 !important;
    margin-top: -2px;
    font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
    text-shadow: 0 1px 0 #ffffff;
}

And damn it, I just went from 18 days to 19.3 days after that switch. Somehow I didn’t want to know that… 57

2 Likes

I like those CSS changes. I should probably have made the text exactly like the other text from the start. I’ll update the script with that CSS incorporated, but I’ll leave the text as “[number] days on level”.

2 Likes

I’m not sure if WKOF supports it (I think it does), but you should look at the level_progressions endpoint for API v2. We’ve been tracking people’s progress on levels for a while, and those records should contain all the goodness. You can compare when they leveled up (unlocked_at) to when they finished their first lesson (started_at) without having to scan all their assignments for the level. :slight_smile:

5 Likes

Oh, that’s neat, thank you. I must have missed this when I scrolled through the documentation. It looks as though you are adding indexed arrays as one levels up; is it correct to fetch unlocked_at for the current level this way? I assume total_count refers to the number of recorded levels.

//array contains the /level_progressions endpoint data
date = array.data[array.total_count - 1].data.unlocked_at

Damn this script made me cry
Capture

5 Likes

It’s alright, we’re not all speed demons. I’ll fix it taking up two lines in the next update.

3 Likes

Thank you for this!

I never used the original, but with my reset the stats site isn’t accurate with this yet and I’d actually been planning to start a spreadsheet just to try and keep track myself for a rough idea, and this is a million times better.

1 Like

That’ll work! If you need the whole object, there’s always:

var latest_level_up = array.data.pop();
// then you can do latest_level_up.unlocked_at or latest_level_up.started_at

I’d suggest the started_at attribute for calculating the time on the level, though. That’s populated when someone does their first lesson for that level, so completionists who like finishing all their vocab before moving on won’t get the wrong impression. :wink:

2 Likes

Thanks! I already updated the script and it’s even neater now. Down to 50 lines compared to the old version’s 300 lines. I don’t know about using started_at though. unlocked_at feels more natural to me, as a user. I’ll ask around and see what people prefer, thanks for the suggestion.

AllenGhost

1 Like

How would I increase the spacing like the old script? I really liked the formatting.

1 Like

You mean you would like some extra margin below the text?

If yes, you could override the script to change the part that looks like this:

 '    .level-duration {' +
			 '        text-align: center;' +
			 '        color: #999 !important;' +
			 '        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;' +
			 '        text-shadow: 0 1px 0 #ffffff;' +
			 '        margin-top: -2px;' +
			 '        margin-bottom: 14px;' +
			 '    }' +

The last row with “margin-bottom: 14px” is not in the script at the moment. If you add this, you would have some extra spacing on the bottom. You can play with those -2px and 14px values a bit and adjust it how you think looks best to you.

2 Likes

Thank you! Haven’t used the original but this is great =)

1 Like

Awesome! Thank you!

Thank you, that’s a useful script.

Are you aware that it does not print on the mobile version of the website (Firefox 60/ Android 7)? I suppose that is because the “append” instruction does not find any matching pattern.

1 Like

Indeed I was not. That’s interesting. It works for me with Firefox 59 and Android 6. Are you using the mobile version of the site? I can’t see the level circle at all with the mobile version.

yes, I use the mobile version of the site, because of its compact design.
Yet, as you mention, it does not seem to have any level circle by default.

If you’d like I could probably add the duration under the reviews circle on mobile