[Userscript] WaniKani Item Annotator (Super Duper Explosions of Colortastic Flavors!)

Go ahead! I didn’t choose a licence, you can do whatever you like with it :slight_smile:

If you have any questions about it feel free to ask, I’m happy to explain my reasoning (if I still remember it!).

I had to make some edits to the script to get it to work (diff). I haven’t included an install link in this post as I don’t want to maintain it, and hope that @jeshuamorrissey will address the problems I’ve had to fix for myself in some way.

These problems were:

  • window.URL.indexOf was not defined in my environment, so I went back to location.href
  • The JSON parse always failed because the WaniKaniAPI.load function already parsed the JSON before passing it into the callback
  • ColouriseItems was failing on a level target, something to do with let scoping making the target in the condition be the not-yet-defined target from within the block. I got it to work but don’t know if what I did was the right thing

Thanks for making the patch! I have merged it in, the install link should now work.

I got it working for my radicals by manually inputting the API key as shown here.
But it’s not working for Kanji and Vocab…

Using Mempo’s version.

Hey Mempo

I can’t figure out how to insert the API key on Tampermonkey on Firefox?
Any ideas?

Edit:

I tried to do:

var apiKey = $.jStorage.get(‘apiKey’);

with

var apiKey = ‘Your-API-Key-here’;

Like finnra suggested above, but it only worked for the Radicals and not the Kanji and Vocab.

Hey Jeshua

Looks like the script isn’t working anymore,
Any chance of having a look at it?

I’ve tried both yours and Mempo’s versions…

@Aikibujin

The script had issues unrelated to the API key. Please update to the latest version and check if it’s fixed on your end.

I didn’t look into possible API key retrieval problems, since you demonstrated that you’re capable of inputting it manually in the script. Be sure to input your key from API version 1 though!

Yup, it worked!
Thanks Mempo! ^ _ ^

Could you tell me what the problem was?
I was trying to figure it out myself, but I’ve never coded in this language.

Cheers!

PS: Here’s the link for anyone else who wants to use the script:

https://greasyfork.org/en/scripts/16370-wanikani-item-annotator

The console said there was an error on line 205. The itemMapping[japanese] variable was undefined. So I figured out how the mapping worked and everything, but it was the ‘japanese’ variable that was the error here. It’s initialized on line 172 and at first it said something like

 var japanese = element.querySelector('.character').textContent

but that padded the japanese character with two ‘\n’ characters. So that’s why the mapping didn’t work. I changed it to

 var japanese = element.querySelector('.character').innerText

I also added a link to include jquery, 'cuz I wasn’t sure the problem had anything to do with that. Dunno if it helped or not, but I let it in.

Yeah I definitely wouldn’t have been able to figure that one out.

Thanks again! ^ _ ^

1 Like

Did you get it working?

I’m happy to have a look at it if it’s still not working well :slight_smile:

Mempo’s version is working now.

It’s still one of my favorite scripts, as I like all the cool colors. ^ _ ^

Cheers!

This didn’t work for me, the page is already loaded before this script so it never enter the main function inside the the event handler. I submitted a pull request that fixes for that case. If anyone has issues with this script, try that version, it might fix it.