[Userscript] WK Real Numbers

Yeah… so… I’ve tried to use this a couple of times and I just can’t get it to work. I’ve tried manually inserting my api key into the code but first, I don’t seem to find the place where it fits and, second, I simply don’t know if there is a particular sintaxis in which to put it. All I get is “API Error: User does not exist.” every time I load a WK page, no prompt to introduce my api nor anything else.

I’m using Firefox 50.1.0 and Greasemonkey 3.9. I also have a couple of other scripts for WK but I see no reason for the to interfere with this one… but of course I wouldn’t really know

 


squashedmos said... Yeah... so... I've tried to use this a couple of times and I just can't get it to work.
You probably have an old API key in you browser storage.  But even if that's not the problem try the following:

Open the Javascript console (press F12 and select the Console tab)
Paste the following command (with your API key inserted, and be sure there aren't any spaces around you API key) and press enter:

localStorage.setItem('apiKey', 'enter_your_apikey_here');
rfindley said...
squashedmos said... Yeah... so... I've tried to use this a couple of times and I just can't get it to work.
You probably have an old API key in you browser storage.  But even if that's not the problem try the following:
Magic @_@

Hey guys. This script is a great idea, I understand the joke behind the number 42, but really… it annoys me so much that I can’t see the real numbers.

Anyway, I installed the Tampermonkey extension in Chrome, and then the custom script here. I think it’s enabled (according to Tampermonkey).

But it’s not working on WK. I get a script error in the console. 

Uncaught ReferenceError: is not defined</div><div>&nbsp; &nbsp; at main (script.js:47)</div><div><br></div><div>.getJSON(‘https://www.wanikani.com/api/user/’ + apiKey + ‘/study-queue’, function (data) {

Anyone got any ideas? Seems like it can’t find jQuery?
stuniq said... Hey guys. This script is a great idea, I understand the joke behind the number 42, but really... it annoys me so much that I can't see the real numbers.

Anyway, I installed the Tampermonkey extension in Chrome, and then the custom script here. I think it's enabled (according to Tampermonkey).

But it's not working on WK. I get a script error in the console. 

Uncaught ReferenceError: $ is not defined     at main (script.js:47)
$.getJSON('https://www.wanikani.com/api/user/' + apiKey + '/study-queue', function (data) {

Anyone got any ideas? Seems like it can't find jQuery?
 Did you also accidentally install it once before installing Tampermonkey? If so, it could be trying to run two copies, one as an extension, and one as a Tampermonkey script.  If it's running as a standalone extension, it may not have access to the Javascript running on the page.

Other than that, I can't think of a reason it wouldn't find jquery, since it should be using the version of jquery loaded by WK.  Unless you're running some kind of unusual security plugin, I suppose.  Could try disabling any such security stuff temporarily.

I’d installed it as an extension and a Tampermonkey script. Deleted the extension and it works now, thanks!

Thanks for the script. Very handy to keeps things realistic for me when I don’t only have 42+ Reviews but much much more show haha

I don’t know if too many are using this script, but with the recent changes from Wanikani, the script no longer find the API key like it happened with Ultimate TimeLine Script. I have found that changing the line number 24: window.location = ‘https://www.wanikani.com/account to window.location = ‘https://www.wanikani.com/settings/account solves the problem because it will go to the correct part of the settings for retrieving the API.

Not entirely, but thanks for bringing it to my attention.

@Everyone, update to version 4 if this hasn’t already happened automatically!

I’ll be updating my other scripts too with the new API retrieval method. If anyone continues to experience issues with this, please contact me by @'ing me in any of the script’s threads.

1 Like

Only because I am curious, what were the changes that needed to be made in order to fix the issue? Not in too much detail, only to feed my insane curiosity about how these scripts works. I am learning to make them so I would like to know a little more about them.

Well, like you said, first the script had to redirect you to the correct settings page. But apparently quite a lot has changed on those pages too. So in the ‘retrieveAPIkey’ function (starting at line 64) it’s now much simpler/straightforward then it used to be. You simply ask the element with the user_api_key id (which is unique) and you get the value attribute from that input element. Instead of all input fields having a unique id like they do now, previously, we had to loop through all the elements on that page and check if the element had a certain attribute that indicated it was indeed the API key box we were looking for. That wasn’t very elegant programming.

EDIT: btw, it’s possible to see the changes on greasyfork if you click on the ‘history’ tab and compare two version with each other.

1 Like

It reminds me of my first codes on C# the way you fixed how to find the API on the website. Quick question, wouldn’t be easy to redirect the user to the section where the API is and let him to copy and paste this on the script? It would be… less user friendly, but maybe more economic in code.

Thank for the advise about the history tab!

Don’t know exactly what you mean with ‘economic in code’. It would indeed be less code overall, but you would also lose a very important feature, so omitting it is not necessary. Scripts are often pretty hacky in nature (well mine are) so it doesn’t have to be the most beautiful thing ever; it just has to get the job done.

Like you said, it would be a lot less user friendly. I’ve encountered a lot of people here who are not at all as technically literate like us programmers. I even created a visual guide to help people just install a script. It also includes instructions to edit them, but asking users to install something and then ‘fix’ it themselves immediately afterwards will lose you a lot of potential users that could benefit from your script.

In fact, I probably should have written a function that fetches the api key without redirecting (thus hiding that retrieval from the user completely, for a smoother experience). But by now, most script users have their apiKey variable already set by either my scripts or rfindley’s, so it’s not really worth it anymore.

‘Economic’ may be a mistranslation from my mother tongue, sorry for that. But you have answered my questions. And yes, from that point of view, I think the effort of adding that part of the code is usefull. Thank you for taking the time to answer my questions.

Yeah… All of my scripts fetch the API key in slightly different ways, and honestly, it’s hard to say what effect you end up with if a dozen scripts try to fetch it at the same time.

With my last script (the new forums lesson/review status), I added a #require sub-script to handle the api key for all scripts that want to use it, so it would unify all apikey-related code. It also provides the beginnings of a framework for scripts to add their settings to a global settings page. (Too bad I don’t have time to retrofit all my old scripts!)

1 Like

@Mempo has something changed in WK that affected this script? For some reason the count doesn’t properly reflect the actual amount when below 42; I have 40 reviews now, and I can see that flash a bit and then it’s overwritten by 44, an older amount. If I check localStorage 44 is what’s stored, and even if I clear it, it resets to 44 after a refresh. Am I missing something?

There are other threads talking about review count problems at the moment, so it’s likely a temporary WK bug.

Well, if I disable the script the numbers are correct, but I suppose you could still be right :slight_smile:

I guess I’ll go back to squashing bugs at work while letting viet squash WKs! :slight_smile:

idk, seems to work fine on my account. I’ll check from time to time if it changes.

EDIT: Viet said he fixed it over here

1 Like

I’ve had problems with this script after resetting my key after resetting my level. I’m not skilled enough with scripts to figure out how to fix it.
I tried deleting and reinstalling it. It simply doesn’t trigger at all. I get the 42+ when over, actual number when under.
I love this script, and actually wish they didn’t do the 42+ (fun joke, but highly unuseful and disruptive…)