[Userscript] Niai 似合い Visually Similar Kanji

My only experience with the unsafeWindow stuff is from years ago when I was first learning the userscripting model. Once I discovered that I didn’t need any of the GM functions for my own purposes, I haven’t used it since.

Anyway, I’ve installed your script now. Next time I have reviews, I’ll see if I can replicate the issue to better understand it. (Though I can’t afford more than a few minutes here and there, or I’ll get a buffer overflow :slight_smile: )

Thanks for your help! I don’t think I can figure out what is going on here on my own, it feels like it’s some weird Tampermonkey bug again in the end.

Did you get the previous version 1.3.1? At the moment wkof related code will never be called.

https://raw.githubusercontent.com/mwil/wanikani-userscripts/42748acc0df6efad42424064544b4d83bc1baebe/wanikani-similar-kanji/wk_niai.user.js

Exactly this. I overstated; Not with every wrong answer, but from time to time, and random too. And when loading the reviews page.

That’s what it’s saying!

After updating the script to the latest version, and making many mistakes while reviewing (sigh… one of those days) I can confirm that the script doesn’t have the error at the moment! It shows the “loading assignments” box shortly when starting up the reviews, but haven’t seen it after that. Nice work! Thanks for the fast response.

It seems that the visually similar Kanji still work, with WKOF disabled, so why not just keep it this way? :slight_smile:

It works, but it uses a database (for showing reading and meaning) from a year or two ago, and I didn’t want to generate it myself from WK and put a new version into the script continuously. The long-term goal is to get rid of storing data from WK completely in the script, I’m not a fan of just providing their content outside of the API (even though I use it WK-only).

So at the moment without WKOF the meaning of a kanji might have changed but the script uses the old one, what people found confusing. The display if a kanji is locked is based on your level, the script just marks everything on your level or higher as locked. With WKOF it shows what is actually locked.

If the popup would show up once per day or so that wouldn’t be a problem. But I didn’t anticipate that a slow connection or custom setting can make WKOF act frequently.

For your setup there is definitely an issue anyway, I never saw the WKOF popup ever except for not using WK for a couple of days. Definitely not before reviews.

Well… I was wrong. WKOF does indeed re-query for updates after 1min.

However, I was unable to reproduce the pop-up because there were no updates to the WK data, so the queries took significantly less than the 1sec necessary for the popup to occur.

If someone has a slow connection to Wanikani’s API server, or if they’re using scripts on a mobile device (which typically runs Javascript much slower), or their cache is disabled somehow (not likely, unless they manually enabled the “ignore_missing_indexeddb” flag in WKOF), then it’s not surprising that it would sometimes take longer than 1sec to fetch data.

For now, you could try suppressing the Progress dialog.
Just before running your queries, temporarily replace wkof.Progress.update() with an empty function:

var saved_progress_func = wkof.Progress.update;
wkof.Progress.update = function(){};

Then restore it after your data is loaded:

wkof.Progress.update = saved_progress_func;

wkof.Progress is purely cosmetic, so suppressing it shouldn’t cause any problems.


Also, a side note:
I noticed you are using backticks (a.k.a. template literals) instead of single-quotes in your code. I doubt it will make a significant performance difference in this case, but backticks are evaluated for expressions before being used as strings, so they are less efficient that single-quoted strings. Also, IE doesn’t support them… but who cares :grin:

2 Likes

It did ! I just had a 100 reviews session with version 1.3.2 and no more loading data pop-up. Thanks.

For your information, I’m using an old laggy laptop right now, with a spotty wifi, so it make sense that slowness issue almost invisible for the majority could be triggered on my setup…

I think I will just cache the results from WKOF myself and only refresh them every few hours or so. The information I’m using is quite static anyway, and wrong data for a while is not really an issue. No need to keep the slow laptops or mobiles busy.


I was using the backticks quite often and had to change the quotes around. After the nth time trying to remember what the vim surround command for replacing them was again, I decided to invest a few CPU cycles for my sanity :slight_smile:

There are a few cases where they are not allowed or behave strange, but I like when it’s consistent.

You could just query all kanji once, leaving the results in a variable for the duration of the page life, then just use the array filter function each time you need to select subset of results. I think that’s pretty much what I do in all of my scripts, which is why the 1-min update never affected me.

function startup() {
  wkof.ItemData.get_items('subjects,assignments')
  .then(process_data);
}

var items, kanji;
function process_data(data) {
  items = data;
  kanji = items.filter(item => item.object=='kanji');
}
3 Likes

Hi @acm2010
is this feature currently working? I am reached level 32, and I see is dark pink despite being level 48.

Would it be possible to add a hover tooltip showing the WK level of each kanji?

Thanks

The current level is still used atm. The level is read when you visit a page with the dropdown menu on top, if you never visit there it will be out of data.

But it looks like you are using the dark style, it usually nukes all styles away with !important. I guess the style showing the lock is removed by the theme.

[Adding the level to the tooltip is no problem.]

I added the level tooltips to Niai and Keisei in new versions.

1 Like

I can confirm it works really well, in both scripts. Thanks!
image

I dont think its working anymore :frowning:

It works great for me on Firefox with Win7! :blush:

Going to try on Fedora 31 after I’m finished updating.

Hmmm how do I know if this script is working? I just did some lessons and it said it was running but I noticed no difference in my URL. Does it still work with the new layout?

@IgorTheGreat It won’t change your URL. During lessons, it should display visually similar kanji on the examples tab, under the examples of vocabulary that use the kanji. I don’t think any of the pages it touches/adds to were affected by the new layout.

1 Like

I see it now! Thanks so much for the reply

1 Like

I’m getting a
" Something unexpected happened while trying to load similar kanji. ごめんなさい。

API url: http://wk-similarkanji.rhcloud.com/kanji

If this bothers you, please drop a line here!"

on an individual kanji’s page.