Is it possible for someone to download or extract the index.html file of a web game from Iitch and publish it illegally on some other website? I looked around on the web and didn't find anything about this.
what about if I place some JavaScript that looks at the url the web game is on, and if it's not www.itch.io stops the the game from running would something like that work?
I advise against implementing drm without a very good reason. You will hurt your legit players first and hardest.
There is a current thread somewhere, that itch is moving servers behind the scenes. If you are unlucky, your homebrew drm will brick your own game.
A much simpler solution is to unmistakenly tell the player where the game is hosted, so the player knows, something "unofficial" is going on. It is much harder to automatically remove watermarks from assets, that tell players where the game should be. But url misdirections and checks can very likely automatically be corrected for the use case you are concerned about.
I looked around on the web and didn't find anything about this.
Maybe you should look harder. But the use case you describe is not what people search for. They want to know, how to play such games for offline use.
But you might be glad to hear, that there is no one-button solution for this. To the dismay of users that witnessed the death of flash. So, it is possible in principle, but there is effort involved. A thing illegal websites shy away from. (Oh, and I would totally use a one button save to disk for my favorite web games, but luckily most creators provide such a file themselves)
Also, there is a plethora of games, free games even, to illegally host. Doing this for webgames sounds overly complicated and with not much gain involved. The visitors of such sites usually know that the site is shady. If you imagine yourself to do this, would you want to spend extensive time on such a site, to play a game that probably is free to play on the legit site? Are there even web games behind a pay wall, that could be pirated?