What do you want now? (Request extensions here)


#605

So the exact behaviour you want is double tap the space bar?

Might look into that.

In the meantime, I’ve got a little known script that let’s you enter your own key to submit an answer: https://www.greasyfork.org/en/scripts/23847-wanikani-little-pinky-protector

Requires the editing of the script itself. Keycodes can be found here: https://keycode.info/


#606

This is probably going to sound really stupid, but I’d love an “easy suspend” button on the dashboard which triggers suspend reviews and resume reviews. I have bursts of incredibly busy/stressful periods with my job/life in which WK is the first thing to get dropped for a few days, at which point it starts to become difficult to catch up (as you can probably tell my me being here for a year+ and being on level 13). While I’m going to endeavour to push through this time, being able to just open the tab and click a button would definitely be helpful. :slight_smile:


#607

You mean a button for vacation mode?


#608

Sorry yes, that’s exactly what I mean. Brain is fried :sweat_smile:


#609

I made a script like that for someone already… let me see if I can find it


#610

Found it but it’s not working anymore and I can’t fix it. @rfindley Is there a way of accessing the /settings/account page from the dashboard with a script by using the right headers? I don’t know that stuff works. Previously I just made a plain GET and fetched the vacation mode button (including the token) from there.


#611

@Kumirei,

Here you go:

function get_vacation_status() {
	$.ajax('/settings/account')
		.then(extract_vacation_form)
		.then(function(form){
			var active = (form.data.commit.match(/deactivate/i) != null);
			console.log('Vacation mode is '+(active?'active':'inactive'));
		});
}

function click_vacation_button() {
	$.ajax('/settings/account')
		.then(extract_vacation_form)
		.then(function(form){
			$.post(form.url, form.data);
		});
}

function extract_vacation_form(html){
	var form = $(html).find('#edit_user_vacation');
	var url = form.attr('action');
	var data = {};
	form.find('input').toArray().forEach(function(i){
		var name = $(i).attr('name');
		var value = $(i).attr('value');
		data[name] = value;
	});
	return ({url:url, data:data});
}

#612

Oh, thanks! You’re always so helpful :hugs:

Question: I thought #edit_user_vacation wouldn’t be found in the response because $(html) in extract_vacation_form only returns text, link, comment, and script nodes; but apparently it’s in there somewhere? Why doesn’t it return a normal DOM?


#613

$.ajax() actually just returns the whole raw html as a string, which does include the #edit_user_vacation. Wrapping it in $() turns it into a jQuery-formatted object, and I think the #edit_user_vacation is a nested object under one of those top-level nodes, which $(html).find() is able to locate.

[geez… trying to type $() is a pain. Discourse treats it as a math formula, and even putting it in backticks doesn’t help]


#614

Hmm. I knew that it returned it as a string and that you could parse it with jQuery and that you can search that with .find(), but for some reason I thought you would normally get a normal looking DOM after parsing. Do you get a normal DOM when the response is XML and I’m just confusing this with that? I feel like I’ve made requests before and got a normal DOM after parsing the response

Sorry if I’m using any terms in an incorrect and confusing way, I’m trying to be as clear as I can, but as you know I don’t really know enough about this stuff


#615

I figured you knew most of that, but wasn’t sure what you mean by “normal DOM”. I’m not a master of the terminology either.

In my mind, DOM is just the model, and doesn’t necessarily imply a specific representation as long as the objects are nested in the same heirarchical structure.

If you do $(html).toArray(), you get an array of all the top-level DOM elements (I think), with children that form the heirarchy. Is that not what you mean by “normal DOM”?


#616

Looking at it another way:

$(’#edit_user_vacation’) is equivalent to $(document).find(’#edit_user_vacation’), because jquery is smart enough to know that if you don’t specify an object to search, then you want to search document.


#617

I think a normal document might be a better way to explain it. I suppose I was expecting something that looked like what you would find in the elements tab in the debug window. So $(html) would be similar to $(document) (with document being the current page’s document)


#618

Makes sense. Apparently, jquery doesn’t construct a top-level ‘document’ (or even <html> or <body>) from the HTML string. I don’t know if it’s a security thing or what.

Edit: I’ll add, though, that I think the Elements tab is just an interpretation of the underlying model.


#619

Anyway, thank you so much for your help. Guess I just got confused. I thought the (to me) strange response might have been due a security thing, and sending a token or something else with the request would return what I expected. I hope you don’t mind too much that I keep asking you about things.


#620

Well, I am extracting a token from the form data. I didn’t see what “strange response” you were getting with your method. What did you try?

Not at all, I love being both student and teacher. When we build each other up, we all rise together.


#621

Oh, I meant maybe you needed some CSRF-token in the header to access /account/settings, but clearly you don’t. By “strange” I just mean that it was a bunch of text, script, and meta nodes rather than what I was expecting. I got the same response as you did.


#622

Ahh, got it.

Honestly, I never really thought about it. I probably just googled one day, “find element in ajax response”, saw how they did it, and just did it that way ever since. Ignorance is bliss :slight_smile:


#623

Yeah, basically a double tap of the space bar instead of enter, although, like I said, I’d like it to also be compatible with or also work the way WaniKani Improve 2.2.2 works, which is, when you press enter just once, it submits your answer and immediately moves on to the next question, although there is a box you can click to read information about the previous one as well. It’d be nice if it could function like WaniKani Improve 2.2.2 because, otherwise, you’d have to press the space bar 4 times to move on, which would be pretty annoying.

It’s nice to hear that you’ve already made something similar, but even with the keycode information, unless someone can tell me how to edit the script in a pretty detailed fashion (I really don’t know anything about scripting! (>///<) ) I’m not going to be able to use it. There’s also the fact that only a double tap for the space bar would work, considering some English answers have spaces in them, and I’d really not know how to do that.

Thank you for showing some interest though! (^ _ ^)


#624

Almost forgot to actually fix the script after rfindley so kindly helped. Here it is, tell me if it’s not working as you want it to. The button is located to the right of the search bar.

https://greasyfork.org/en/scripts/377319-wanikani-dashboard-vacation-mode