When coding a chrome extension, how can i listen to the event when either player makes a move?

Sort:
yodavid

So, on my content.js file i'm currently able to do what i want, but i want this function to be called again everytime a player makes a move. How can i achieve that?

Omed

um this sounds like a cheat tbh

MasterMatthew52

What are you trying to do?

yodavid

it's not a cheat

knightpawnerchesss

MutationObserver

krasibiel
knightpawnerchesss wrote:

MutationObserver

However, for some reason, this sometimes breaks, especially when you leave the site and come back. When I've tried experimenting, the best way I have found is to just check whether the player nametag has changed every few seconds.

26gy2
yodavid wrote:

it's not a cheat

what is it

krasibiel
26gy2 wrote:
yodavid wrote:

it's not a cheat

what is it

I mean I made an extension which automatically provides you with stats related to your opponent and displays them next to the game, so not everything is gonna be a cheat. Additionally, if this guy asks simple questions in this forum, he's likely incapable of coding a cheat chess bot himself, of which many free and open source versions already exist, so I don't see the point of.

yodavid
krasibiel escreveu:
knightpawnerchesss wrote:

MutationObserver

However, for some reason, this sometimes breaks, especially when you leave the site and come back. When I've tried experimenting, the best way I have found is to just check whether the player nametag has changed every few seconds.


from what i understand, the fact that the board is generated dynamically rather than being there from the moment the page is loaded might be the source of the problem, no?

krasibiel
yodavid wrote:
krasibiel escreveu:
knightpawnerchesss wrote:

MutationObserver

However, for some reason, this sometimes breaks, especially when you leave the site and come back. When I've tried experimenting, the best way I have found is to just check whether the player nametag has changed every few seconds.


from what i understand, the fact that the board is generated dynamically rather than being there from the moment the page is loaded might be the source of the problem, no?

Normally when you first load a new game, it detects your opponents username, but after subsequent new games, mutation observer no longer detects changes for some reason in the testing I have done.

yodavid

could you please explain what did you mean by checking if the player nametag changed?

krasibiel
yodavid wrote:

could you please explain what did you mean by checking if the player nametag changed?

Where it says your opponents name.

Hyper-Dragon
yodavid wrote:

So, on my content.js file i'm currently able to do what i want, but i want this function to be called again everytime a player makes a move. How can i achieve that?

For move detection (by polling) take a look at this: https://github.com/Hyper-Dragon/DgtAngel/tree/main/sourceExt/DgtAngelCdcPlay

trapgodbeckett

Every piece that's being rendered on the board has a unique attribute that denotes the type of piece, the color, and the location. They're all stored as children of the same element, so you could iterate through that element's children and parse the information on each mousedown event.