jQuery 用作谷歌浏览器书签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18872679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
function as google chrome bookmark
提问by Brentg
Let me first say the problem I have: I need to fill in the same web page a lot of times, and the content that I need to fill in is for the biggest part the same, but is scattered all over the webpage.
先说一下我遇到的问题:同一个网页我要填很多次,而且我要填的内容大部分都一样,但是分散在整个网页上。
The solution i was thinking of: I know there is a way to create some javascript function that you put behind a google bookmark so that when you are on the page, you just click that bookmark, and it will do some things.
我正在考虑的解决方案:我知道有一种方法可以创建一些 javascript 函数,将其放在 google 书签后面,这样当您在页面上时,只需单击该书签,它就会执行一些操作。
I was wondering if anyone used (or created) something like this. If you can make this yourself, how do you start with it? And can you use jquery?
我想知道是否有人使用(或创建)了这样的东西。如果你可以自己做这个,你如何开始呢?你能用jquery吗?
If it's possible to create this, I was also wondering if it would be possible to, when you click, show a pop-up to ask a few parameters, so that I don't need to fill in the same thing 3,4 times
如果可以创建这个,我也想知道是否可以在您单击时显示一个弹出窗口来询问几个参数,这样我就不需要填写相同的内容 3,4 次
回答by T.J. Crowder
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.
您可以使用书签来完成此操作。bookmarklet 是一个书签,其 URI 以伪协议javascript:
开头,后跟 URI 编码的 JavaScript 代码。当您触发书签时,浏览器将在当前页面的上下文中运行代码。所以你会去那个页面,然后使用那个书签来填写你的标准信息,然后你就可以了。
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:
例如,这里有一个书签,当运行时,它将id
someElement
在页面上查找带有 的元素,如果找到,则分配"some value"
给它的value
属性:
javascript:(function(){var d=document,e=d.getElementById("someElement");e.value="some value";})();
回答by diazdeteran
This bookmarklet creator will come in handy to squish your JavaScript into one line: http://mrcoles.com/bookmarklet/
这个书签创建者将派上用场将您的 JavaScript 压缩成一行:http: //mrcoles.com/bookmarklet/
回答by Hari Gillala
javascript : { document.getElementById('PlateNo').value='0815';document.getElementById('AppRef').value='013007';document.getElementById('VehicleReg').value='MX53 YMD'; void(0) }
回答by Matthias S
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
回答by goldenfire64
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:
你可以使用提示和警报并确认窗口,我创建了一个游戏,有点。不过也不是那么干净。这是javascript代码:
To the editor: there needs to be a "javascript:" at the start for it to work btw
致编辑器:开始时需要有一个“javascript:”才能正常工作
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)
回答by Umanath
For Mozilla use like as
对于 Mozilla 使用像作为
javascript:function myFun(){
var d=document;
var e=d.getElementById("someElement");
var e.value="some value";
}myFun();