# \[Userscript\] Level Duration 2.0

**URL:** https://community.wanikani.com/t/userscript-level-duration-20/30668
**Category:** API And Third-Party Apps
**Created:** [April 26, 2018, 1:39pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668 "2018-04-26T13:39:51Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Kumirei](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/kumirei/32/480522_2.png) [@Kumirei](https://community.wanikani.com/u/Kumirei)
#### Post date: [April 26, 2018, 1:39pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/1 "2018-04-26T13:39:51Z")

</div>

> ⚠ This is a third-party script/app and is not created by the WaniKani team. By using this, you understand that it can stop working at any time or be discontinued indefinitely.

This script replaces [the original Level Duration script](https://community.wanikani.com/t/userscript-level-duration-display/4991). Unlike the previous one, this script fetches your level unlock date from the API, so it is much more accurate. To do this it relies on [WKOF](https://community.wanikani.com/t/installing-wanikani-open-framework/28549), so you will need to install that first for this to work.

There are a couple of different display options for this script. If you have been on your current for say 4 days and 2 hours, you can choose from these options:

```plaintext
4 days 2 hours
4.1 days on level
4.1 days
4d 2h
4日2時
4日2時 (in the FangSong font)

```

##### Example:

 ![brave_Ujg9xWv7lu](https://global.discourse-cdn.com/wanikanicommunity/original/4X/6/2/c/62c1e7d705c15dad8aa2f0468e09371cfdb22811.png)

### Available at

> **[Wanikani: Level Duration 2](https://greasyfork.org/en/scripts/41084-wanikani-level-duration-2)**
>
> Displays the number of days you have spent on the current level.

---

<div class="post-metadata">

### Author: ![jprspereira](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/jprspereira/32/389740_2.png) [@jprspereira](https://community.wanikani.com/u/jprspereira)
#### Post date: [April 26, 2018, 1:46pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/2 "2018-04-26T13:46:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Powerpuncher](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/powerpuncher/32/231125_2.png) [@Powerpuncher](https://community.wanikani.com/u/Powerpuncher)
#### Post date: [April 26, 2018, 1:47pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/3 "2018-04-26T13:47:47Z")

</div>

I like it, very sleek, thanks a lot 🙂

---

<div class="post-metadata">

### Author: ![irrelephant](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/irrelephant/32/69530_2.png) [@irrelephant](https://community.wanikani.com/u/irrelephant)
#### Post date: [April 26, 2018, 3:43pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/4 "2018-04-26T15:43:12Z")

</div>

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:

```auto
.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](https://global.discourse-cdn.com/wanikanicommunity/original/3X/d/8/d816971be39aeb386ee8fcba9b8c3679dd192545.jpg)

---

<div class="post-metadata">

### Author: ![Kumirei](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/kumirei/32/480522_2.png) [@Kumirei](https://community.wanikani.com/u/Kumirei)
#### Post date: [April 26, 2018, 3:55pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/5 "2018-04-26T15:55:47Z")

</div>

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”.

---

<div class="post-metadata">

### Author: ![oldbonsai](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/oldbonsai/32/33394_2.png) [@oldbonsai](https://community.wanikani.com/u/oldbonsai)
#### Post date: [April 26, 2018, 7:14pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/6 "2018-04-26T19:14:00Z")

</div>

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. 🙂

---

<div class="post-metadata">

### Author: ![Kumirei](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/kumirei/32/480522_2.png) [@Kumirei](https://community.wanikani.com/u/Kumirei)
#### Post date: [April 26, 2018, 7:35pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/7 "2018-04-26T19:35:05Z")

</div>

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.

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

```

---

<div class="post-metadata">

### Author: ![Nofaith](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/nofaith/32/205634_2.png) [@Nofaith](https://community.wanikani.com/u/Nofaith)
#### Post date: [April 26, 2018, 7:37pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/8 "2018-04-26T19:37:22Z")

</div>

Damn this script made me cry  
 ![Capture](https://global.discourse-cdn.com/wanikanicommunity/original/3X/1/1/115615d199797495edc31bc8ad1011537b03d6a1.PNG)

---

<div class="post-metadata">

### Author: ![Kumirei](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/kumirei/32/480522_2.png) [@Kumirei](https://community.wanikani.com/u/Kumirei)
#### Post date: [April 26, 2018, 7:40pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/9 "2018-04-26T19:40:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![PaperbackAddict](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/paperbackaddict/32/50079_2.png) [@PaperbackAddict](https://community.wanikani.com/u/PaperbackAddict)
#### Post date: [April 27, 2018, 2:54am UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/10 "2018-04-27T02:54:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![oldbonsai](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/oldbonsai/32/33394_2.png) [@oldbonsai](https://community.wanikani.com/u/oldbonsai)
#### Post date: [April 27, 2018, 5:03pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/11 "2018-04-27T17:03:00Z")

</div>

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

```javascript
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. 😉

---

<div class="post-metadata">

### Author: ![Kumirei](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/kumirei/32/480522_2.png) [@Kumirei](https://community.wanikani.com/u/Kumirei)
#### Post date: [April 27, 2018, 5:07pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/12 "2018-04-27T17:07:57Z")

</div>

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](https://global.discourse-cdn.com/wanikanicommunity/original/3X/4/b/4bba835ebe725a2f243f107effa2ade7783ed6ba.png)

---

<div class="post-metadata">

### Author: ![Momoiro](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/momoiro/32/503546_2.png) [@Momoiro](https://community.wanikani.com/u/Momoiro)
#### Post date: [May 5, 2018, 5:11pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/13 "2018-05-05T17:11:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![irrelephant](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/irrelephant/32/69530_2.png) [@irrelephant](https://community.wanikani.com/u/irrelephant)
#### Post date: [May 5, 2018, 5:26pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/14 "2018-05-05T17:26:35Z")

</div>

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:

```auto
 ' .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.

---

<div class="post-metadata">

### Author: ![Lexadis](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/lexadis/32/177215_2.png) [@Lexadis](https://community.wanikani.com/u/Lexadis)
#### Post date: [May 5, 2018, 6:02pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/15 "2018-05-05T18:02:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Momoiro](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/momoiro/32/503546_2.png) [@Momoiro](https://community.wanikani.com/u/Momoiro)
#### Post date: [May 5, 2018, 6:06pm UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/16 "2018-05-05T18:06:49Z")

</div>

Awesome! Thank you!

---

<div class="post-metadata">

### Author: ![omoide](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/omoide/32/180788_2.png) [@omoide](https://community.wanikani.com/u/omoide)
#### Post date: [May 16, 2018, 7:16am UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/17 "2018-05-16T07:16:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kumirei](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/kumirei/32/480522_2.png) [@Kumirei](https://community.wanikani.com/u/Kumirei)
#### Post date: [May 16, 2018, 8:51am UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/18 "2018-05-16T08:51:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![omoide](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/omoide/32/180788_2.png) [@omoide](https://community.wanikani.com/u/omoide)
#### Post date: [May 16, 2018, 9:23am UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/19 "2018-05-16T09:23:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kumirei](https://sea1.discourse-cdn.com/wanikanicommunity/user_avatar/community.wanikani.com/kumirei/32/480522_2.png) [@Kumirei](https://community.wanikani.com/u/Kumirei)
#### Post date: [May 16, 2018, 9:24am UTC](https://community.wanikani.com/t/userscript-level-duration-20/30668/20 "2018-05-16T09:24:33Z")

</div>

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

[Next page](https://community.wanikani.com/t/userscript-level-duration-20/30668.md?page=2)
