Hi there
Can you tell me more about the site that you want to implement this feature? What I can offer to you is to create a Chrome extension that will run the script on some command, and then run the processes that you have defined.
If you like the idea of extension, feel free to hit me up so we can talk more about this. I am very responsive. All the best
Edit: I see that you want this for Instagram, but I was confused because they use JS on their desktop view of the website. So, that's why I need more info on this.