简体   繁体   中英

How to run a javascript file on your local machine on the chrome console?

There is a website I have to access frequently which puts strings to a stack. There are two inputs on the browswer that have a default value, so the page opens with them filled out.

I have two commands which replaces the values in both of these to the inputs I'd like:

document.getElementsByName("input1")[0].value = "input1";
document.getElementsByName("input2")[0].value = "input2";

if I run this in the chrome browser console it works just fine, and I can click the up arrow to pull this up again next time I sent a string which is useful. However, I'd like to be able to save those two lines as a file on my local machine, so I can just run the file name once instead of having to copy the two lines for whichever inputs I want:

For example, instead of having to copy the above 2 lines at the beginning of my testing, I could just type in setInputs.js.

And for other inputs, I would have other files, so I could type in setInputsVersion2, 3, 4... etc. as I need to.

Is this possible?

You may want to look at using "tampermonkey" or "greasemonkey". you can define what website to run javascript code on and at what time etc. You can run the javascript code on the domain and then type the function into the JVM (javascript console) onto chrome to save you time as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM