Unburn Hotkey for Extra Study - collaborative post

Hello!

DISCLAIMER : none of this works

I already talked about this idea of mine in a a couple of posts. I finally decided that I would try to do it on my own.
For fun, and because I believe some developers such as @Kumirei are already slightly overburdened mantaining their scripts.

I know nothing. Never saw Javascripts before in my life.
Therefore I asked for help to chatGPT:

I want you to write a Userscript for a website called Wanikani. The Usersript must work during the Extra study sessions. In these session I review burned items. Burned items are words I have already studied completely. I want to write a script that, after i answer all questions related to the item, allows me to press U. After pressing U, a popup would appear with written: “Do you want to unburn this item?”. If I press Enter the item is added to the reviw queue once again. I I press undo the popup closes.
The userscript can rely on Open Framework, and must be written in Javascrip

I got this:
[Wanikani ExtraStudy Unburn Script]

Then i revised the prompt slightly and got the following:

I want you to write a Userscript for a website called Wanikani. The Usersript must work during the Extra study sessions. In these session I review burned items. Burned items are words I have already studied completely. I want to write a script that, after i answer all questions related to the item, allows me to press U. After pressing U, a popup would appear with written: “Do you want to unburn this item?”. If I press Enter the item is added to the normal reviw queue once again, as an apprentice item. If I press undo the popup closes.
The userscript can rely on Open Framework, and must be written in Javascript

[Wanikani ExtraStudy Unburn Script v2]

Of course they don’t work at all.
I know that life is not that easy.

But I am wondering if someone interested, or capable, or both, would like to pitch in and contribute somehow. (The only currencies I have are gratitude and enthusiasm)
I would accept any kind of help:
For example “They are not that wrong” or “Throw away everything” would be perfectly acceptable answers.

Which version is better?
Is there some part of the code that is absolutely wrong?
Are the codes at least accessing the right varibles?
What should I study to finish the code by myself?
Is there some other code that I could salvage?
How would you do it?

Sorry for the almost nonsense post. Hopefully I will be able to make something good out of it :smiling_face_with_tear:

2 Likes

Haven’t been in this part of the forum for a while, so sorry for the late response…

Nr 2 looks a lot cleaner. You know, for scripts that don’t do anything yet, less is more :supervillain:

Yes and no. That is, yes to wrong and no to right variables. Burned isn’t a badge, it’s a status on the server. To alter the status on the server, you’ll need to post an update => read on

AJAX first of all (XMLHttpRequest). Sound scary? It isn’t. Most people copy paste the code off of stack exchange. (aka you don’t really need to know much about it). Let me save you the trouble

    //======== FIRE THE HTML REQUEST
    function promise(){var a,b,c=new Promise(function(d,e){a=d;b=e;});c.resolve=a;c.reject=b;return c;}
	function postUpdate(url, authToken, authTokenValue) {
		var update_promise = promise();

        var request = new XMLHttpRequest();
        request.onreadystatechange = process_result;
        request.open('POST', url, true);
        request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        request.send("_method=put&"+authToken+"="+ authTokenValue);
        return update_promise;

		function process_result(event){
			if (event.target.readyState !== 4) return;
			if (event.target.status >= 400 || event.target.status === 0) {
                return update_promise.reject(event.target.status);
            }
            update_promise.resolve(event.target.response);
		}
	}

Absolutely - I like the confirmation box.

Would probably add a button to the left top (next to home and settings) that would trigger the confirmation dialog. Upon confirm, post the resurrect request to the server, using the item id and the authtoken, all of which are available on the page. For good measure, I’d probably verify that you’re in the Burned Items section before showing the unburn button, although I think trying to unburn something that isn’t burned probably doesn’t work, it’s better to not allow the request to fire at all.

I’ll admit that I have an easy time talking here, I once wrote a bulk resurrect manager for funsies - I can probably contribute quiet a bit of working code to this project if you want.

1 Like

Thank you so much for your reply ^^
I have started working this month and most of my free time goes into studying Japanese. As soon as I get my timeschedule back together I will prioritize this task.

About what kind of help would i ask/need I yet don’t know. I will come back to you as soon as I figure what I actually need to do…
Thank you once again, you already give me quite a lot to think about! :smiley: