[UserScripting Question] - How to determine correctness of user's answer in 'didAnswerQuestion'?

The ‘didAnswerQuestion’ internal event seemed to have stop returning the event.
Anyone knows of a replacement method to figure out whether the user’s answer is correct?


Background:

I’m debugging [Userscript] WaniKani Pitch Info

The code was listening to didAnswerQuestion and then made use of the event (ev) returned in the callback.

Relevant code section:

window.addEventListener('didAnswerQuestion', (ev) => {
  console.log("didAnswerQuestion");
  // didAnswerQuestion will be triggered whenever the user answers a question
  console.log(`ev: ${JSON.stringify(ev)}`);
  
  if (wkof.settings.wanikani_pitch_info?.display_pitch_beside_question && ev.detail.questionType == 'reading' && ev.detail.results.action == 'pass') {
  ...

However, didAnswerQuestion seems to have stopped returning the event. ev is now empty.

Browser console:

didAnswerQuestion
ev: {}

I understand that didAnswerQuestion is internal to WaniKani and could change.
Anyone knows of a replacement method to figure out whether the user’s answer is correct?
ev.detail.results.action == 'pass' - The user’s answer was correct
Because ev is empty, the checks against ev.detail.XXX fails.

1 Like

I guess I can manually check the response.

  1. Grab the user’s response with: document.querySelector("#user-response")?.value?.trim()
  2. Compare against [For Userscript Authors] WK Item Info Injector 's list of accepted readings wkItemInfo.currentState.reading

Is there anything better?


Edit: I’m going with the above. If anyone has a better idea, please let me know.