vis*_*hal 7 firefox bookmarks passwords javascript bookmarklet
我创建了一个脚本,它在悬停时显示密码,就像 Windows 8 在眼睛点击时一样。
我使用以下代码通过 JavaScript 实现了此功能。
function text(){this.type="text"}function password(){this.type="password"}function addHandlers(){var e=false;var t=document.evaluate("//input[@type='password']",document,null,6,null);for(var n=t.snapshotLength-1,r;r=t.snapshotItem(n);n--){if(!e){r.addEventListener("mouseover",text,false);r.addEventListener("mouseout",password,false)}else{r.addEventListener("focus",text,false);r.addEventListener("blur",password,false)}}}addHandlers()
Run Code Online (Sandbox Code Playgroud)
抱歉打包的 JavaScript 代码,但我想创建一个运行此脚本的书签或书签...
我试过:
javascript:(mycode);
Run Code Online (Sandbox Code Playgroud)
但它没有用...
为了解决您的具体问题,我设法让您的 JavaScript 代码在此版本中执行而没有任何错误:
javascript:(function(){function text(){this.type="text"};function password(){this.type="password"};function addHandlers(){var e=false;var t=document.evaluate("//input[@type='password']",document,null,6,null);for(var n=t.snapshotLength-1,r;r=t.snapshotItem(n);n--){if(!e){r.addEventListener("mouseover",text,false);r.addEventListener("mouseout",password,false)}else{r.addEventListener("focus",text,false);r.addEventListener("blur",password,false)}}};addHandlers();alert("bookmarklet loaded");})();
Run Code Online (Sandbox Code Playgroud)
为了查看您的代码是否有效,我alert("bookmarklet loaded");
在书签的末尾添加了一个。所以你可以尝试并且应该 - 因为我在 Firefox 17 上测试过 - 结果会出现一个消息框。如果您的代码有效或无效,我无法说,但这当然不是问题。
有一些事情你可以记住,或者让<script></script>
标签内的 JavaScript 代码转换更容易被书签采用
让我们举个例子。让我们有两个带有两条指令的源代码片段:
var anumber=1
var atext="hallo"
Run Code Online (Sandbox Code Playgroud)
当将所有内容放在一行中(= 将换行符改为空格)时,您首先会得到以下结果:
var anumber=1 var atext="hallo"
Run Code Online (Sandbox Code Playgroud)
这不再是有效的 JavaScript 代码。如果你想在一行中合并两条指令,你需要使用这样的分号来分隔/分隔两条指令:
var anumber=1; var atext="hallo"
Run Code Online (Sandbox Code Playgroud)
javascript:(function(){ [...here your code...] })();
有很多网站可以调查解决方案。喜欢这里。
你实际上非常接近。你只需要这样说:
javascript:(function(){mycode})();
Run Code Online (Sandbox Code Playgroud)
在你的例子中,你可以试试这个:
javascript:(function(){function text(){this.type="text"};function password(){this.type="password"};function addHandlers(){var e=false;var t=document.evaluate("//input[@type='password']",document,null,6,null);for(var n=t.snapshotLength-1,r;r=t.snapshotItem(n);n--){if(!e){r.addEventListener("mouseover",text,false);r.addEventListener("mouseout",password,false)}else{r.addEventListener("focus",text,false);r.addEventListener("blur",password,false)}}};addHandlers()})();
Run Code Online (Sandbox Code Playgroud)
当您缩小代码时请注意分号,您遗漏了其中的一些。
归档时间: |
|
查看次数: |
14298 次 |
最近记录: |