wesbos / who-blue

A browser extension to separate lords from peasants
347 stars 27 forks source link

only works on new page load #2

Open jsjoeio opened 2 years ago

jsjoeio commented 2 years ago

See video:

https://user-images.githubusercontent.com/3806031/201135148-ca06d6ef-121f-44e4-b9cb-c4fa9e36e9b9.mov

wesbos commented 2 years ago

yeah def PR this :) Didnt even think about how its a SPA. Some sort of history change event

jsjoeio commented 2 years ago

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();
});

Source

jsjoeio commented 2 years ago

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:

Sync271 commented 2 years ago

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();
});

Source

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.

JeffreyATW commented 2 years ago

Might also consider doing this on scroll, as new elements appear as you do so.

davwheat commented 2 years ago

Potentially a MutationObserver looking for SVGs where aria-label is Verified account might be a better option?