PostDoc71 / SpellingBeeHelp

0 stars 1 forks source link

Fix for getGeniusScore when logged in #1

Open bmarcotte opened 1 year ago

bmarcotte commented 1 year ago

Hi @PostDoc71! I'm the guy that's been commenting on your posts on Reddit. I've been working on a fix for the issue I've been having where getGeniusScore never returns if I'm logged in to the site. I've got a code fix now that seems work for both forms of the Rankings modal. Basically, instead of awaiting the list element (which is different between to two types of modal), it awaits the modal title element, and then tries two different ways to find the appropriate element.

Feel free to incorporate it if you wish: `async function getGeniusScore() { [...document.querySelectorAll(".pz-dropdown__menu-item")][1].click();

// Wait for Rankings modal to open.
// Both forms of this modal have a title element with this class:
await waitForElement('.sb-modal-title');

const geniusElement =
  document.querySelector('.sb-modal-ranks__list')?.querySelectorAll('td')[3] ||
  document.querySelector('.sb-modal-list')?.querySelector('li:last-of-type');
const score = +geniusElement?.innerText.replace(/\D/g, '');

document.querySelector('.sb-modal-close').click();
return score;

function waitForElement(selector) {
    return new Promise(resolveElement => {
        const checkForElement = () => {
            let element = document.querySelector(selector);
            if (element) {
                resolveElement(element);
            } else {
                setTimeout(checkForElement, 10);
            }
        };
        checkForElement();
    });
}

}`

Also, for reference, I'm attaching a couple of screenshots that show the differences I see between the two types of this modal.

Logged in:

logged-in-rankings

Logged out:

logged-out-rankings
PostDoc71 commented 1 year ago

Ben,

I'm not sure that my first github reply got sent, so here is a recap. Thanks for putting in the work. I implemented your change requests, and things seem copacetic on my end. Interestingly, I cannot replicate your experience when logged out; I can only pull up the Spelling Bee site when logged in. Also, what you labeled logged out is what I see when logged in. I suspect there may be older versions of SB floating around that muddy the water.

I hope my code was readable. I recently retired as a pediatrician, and decided to take up coding after a 30 year hiatus. Back then I mostly wrote in assembler (favorite "front end" was Pascal). Javascript had not yet been invented, and communication was by floppy disk or snail mail. Javascript is quite a change, and on today's machines runs faster than well optimized assembler on machines of the 1980's.

Once again, big thanks! Karl Chun

bmarcotte commented 1 year ago

Poking around with it some more, I'm tending to think this has something to do with caching, maybe more on the server side than the client side, since I've already cleaned out what I can on my end. I've seen this happen before with places that use CDN services, but don't properly expire old content when they push out new versions.

And, yes, your code was definitely readable. I do this for a living and deal with many different coders' unique styles. 😃