Yes anything's possible, especially this
in order to run a script every time a page loads, you would want to make a browser extension (usually chrome extension, but same principles would apply to firefox also or possibly other browsers).
But first you need to just think of what that script would be. If you want to change to class nameof the body to something, in this case web dark
, then the JavaScript would be
document.body.className = "web dark"
now the slightly hard part is making the actual extension I'll go over the instructions in chrome but similar concepts may apply to other browsers.
First open up a text editor. It can even be notepad, just when you go to file -> save as, change the extension ".txt" to "all files".
Anyways, name the new file "manifest.json" in a brand new folder somewhere, making sure to change the type of "all files" when you save it
Now we need to add some content to it. There are a few mandatory fields for every extension to hae, you can just copy the following and change the parts you want:
{
"name": "the actual name of it",
"version": "1.0",
"description": "put anything you want here!?",
"manifest_version": 2
}
OK now go open chrome, go to the extensions page (usually under tools, or chrome://extensions
), then there should be a little tick mark that says "developer mode". If you see it, click it, now you should see a new menu appear that says, as one of the options "load unpacked". Click it.
Now select that new folder you made, that contains the manifest.json file.
If all goes well so far, meaning it loads with no errors, then we can move on.
Now we just need to add whats called a Content Script, which will execute some JS when the page loads.
To do so, add a new field in the manifest.json file, called "content_scripts", with a field called "matches" that contains the base URL of the ste you want to inject the scirpt to (in this case probably whatsapp.com), and another field called "js", containg the path to a new JS file that we are about to make, let's call it myscript.js (which we will get to in a sec). So so far the manifest.json should look like this:
{
"name": "the actual name of it",
"version": "1.0",
"description": "put anything you want here!?",
"manifest_version": 2,
"content_scripts": [{
"matches": ["https://*.whatsapp.com/*"],
"js":["myscript.js"]
}]
}
then reload it to see if there are any errors.
If not, we can move on.
now, create a new file in that same directory as manifest.json, called myscript.js
. You can use notepad even, just make sure to set the type to "all files".
In that new file, simply add
function doIt() {
document.body.className = "web dark"
}
if(document.readyState == "complete")
doIt()
else
addEventListener("load", doIt)