Rasspy Rasspy - 1 year ago 119
Javascript Question

How do run a command through Google Chrome's console with a hotkey through Tampermonkey

I have been working on a program for "slither.io" and in order to function correctly every time i change servers i need to run a bit of code through Google Chromes console. (You can open it with Shift+Ctrl+J)
I would like to know any possible way to send a certain line of code into Google Chromes console and run it with a hotkey. In other words, when i am on the main page of "slither.io", i should be able to press "e" and without be having to open Google Chromes console it will automatically type in and run that certain command in console.
If possible, i'd like to have a Tampermonkey script to do this.
I have not tried much on my own due to the fact that i am very bad at programming with Tampermonkey.
If anyone else could help me i could greatly appreciate it. :)

Here is a picture of the command i would like to run once "e" is pressed:

picture of command

Answer Source

All you want to do is set a global variable on the page when you press the "e" key. That can simply be achieved in your JavaScript in an Event Handler.

For example:

document.addEventListener("keypress", function(e) {
    if (e.which == 101) {
        window.xhttp = .........; // .... is the code in the screenshot

You just need to inject that into the page via Tampermonkey or a Chrome Extension.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download