作为谷歌浏览器的书签

让我先说说我的问题: 我需要填写相同的网页很多次,我需要填写的内容是最大的部分相同,但分散在整个网页。

我想到的解决办法是: 我知道有一种方法可以创建一些 javascript 函数,你把它放在谷歌书签后面,这样当你在页面上的时候,你只要点击那个书签,它就会做一些事情。

我想知道是否有人使用(或创建)这样的东西。 如果你可以自己做这个,你怎么开始使用它? 你能使用 jquery 吗?

如果有可能创建这个,我还想知道是否有可能,当你点击,显示一个弹出窗口询问一些参数,这样我就不需要填写同样的东西3,4次

107474 次浏览

You can do this using a bookmarklet. A bookmarklet is a bookmark with a URI starting with the pseudo-protocol javascript: followed by URI-encoded JavaScript code. When you trigger the bookmark, browser will run the code in the context of the current page. So you'd go to that page, then use that bookmarklet to fill in your standard information, and there you go.

For example, here's a bookmarklet that, when run, will look for an element with the id someElement on the page and, if found, assign "some value" to its value property:

javascript:(function(){var d=document,e=d.getElementById("someElement");e.value="some value";})();
javascript : { document.getElementById('PlateNo').value='0815';document.getElementById('AppRef').value='013007';document.getElementById('VehicleReg').value='MX53 YMD'; void(0) }

For Mozilla use like as

javascript:function myFun(){
var d=document;
var e=d.getElementById("someElement");
var e.value="some value";
}myFun();

This bookmarklet creator will come in handy to squish your JavaScript into one line: http://mrcoles.com/bookmarklet/

Here is an example of one that lets you edit the webpage like a document.

javascript:document.body.contentEditable = 'true'; document.designMode='on'; void 0

You can use prompts and alerts and confirm windows, and I created a game, kind of. It's not that clean though. Here's the javascript-code:

To the editor: there needs to be a "javascript:" at the start for it to work btw

javascript:
var totalClicks = 0;
for (var i = 0; i < 1000000; i++){
var message1 = prompt("Clicker Game!\nClicks: "+totalClicks,"remove this text to end the game");
totalClicks++;
if (message1 !== "remove this text to end the game"){
i = Math.Infinity;
}
}
alert("Thanks for playing my game!\nClicks: "+totalClicks)