Open jsjoeio opened 2 years ago
yeah def PR this :) Didnt even think about how its a SPA. Some sort of history change event
Leaving some notes here...
I see the main function called is go
https://github.com/wesbos/who-blue/blob/main/scripts/content.js#L31-L40
Basically we need to "subscribe" to some sort of history change event. Maybe this one:
Listening to hashchange, popstate events:
window.addEventListener('hashchange', e => {
console.log('URL hash changed', e);
doSomething();
});
window.addEventListener('popstate', e => {
console.log('State changed', e);
doSomething();
});
I tested both of those by putting them in the console
on twitter.com and then navigating to a new profile via Twitter Search but neither logged. Ditching that approach.
Maybe one of these:
Leaving some notes here...
I see the main function called is
go
https://github.com/wesbos/who-blue/blob/main/scripts/content.js#L31-L40
Basically we need to "subscribe" to some sort of history change event. Maybe this one:
Listening to hashchange, popstate events:
window.addEventListener('hashchange', e => { console.log('URL hash changed', e); doSomething(); }); window.addEventListener('popstate', e => { console.log('State changed', e); doSomething(); });
Hey, so I did test both popstate
and hashchange
, popstate
works only when you are going back and forth between pages using "back" and "forward" buttons (realised this after making the PR 😓) but what we can actually do is a combination of popstate
and click
to run when you click on a profile/page.
Might also consider doing this on scroll
, as new elements appear as you do so.
Potentially a MutationObserver
looking for SVGs where aria-label
is Verified account
might be a better option?
See video:
https://user-images.githubusercontent.com/3806031/201135148-ca06d6ef-121f-44e4-b9cb-c4fa9e36e9b9.mov