转换 JavaScript 书签以便与 Greasemonkey 一起使用?
我正在尝试获取以下书签作为 Greasemonkey 脚本来解决 stackexchange 站点的可访问性错误。
javascript:(function(){$('a,%20.vote-up-off,%20.vote-down-off,%20.star-off').attr({role:'link',tabindex:'0'});})()
当我删除 function() 并将其放入以下 Greasemonkey 脚本中时,它不起作用。
// ==UserScript==
// @name StackExchange access
// @description Enables y-aria stuff on stackoverflow
// @include *
// ==/UserScript==
$('a,%20.vote-up-off,%20.vote-down-off,%20.star-off').attr({role:'link',tabindex:'0'});
alert("worldzz");
我猜测我需要以某种方式从 Greasemonkey 访问文档对象,但不知道如何执行此操作。
我知道脚本被调用,因为如果我注释掉 $('a,%20.vote-up-off,%20.vote-down-off,%20.star-off').attr( {role:'link',tabindex:'0'})
行我的警报被触发。
I'm trying to get the following bookmark to act as a Greasemonkey script to work around an accessibility bug with the stackexchange sites.
javascript:(function(){$('a,%20.vote-up-off,%20.vote-down-off,%20.star-off').attr({role:'link',tabindex:'0'});})()
When I remove the function() and put it in the following Greasemonkey script it does not work.
// ==UserScript==
// @name StackExchange access
// @description Enables y-aria stuff on stackoverflow
// @include *
// ==/UserScript==
$('a,%20.vote-up-off,%20.vote-down-off,%20.star-off').attr({role:'link',tabindex:'0'});
alert("worldzz");
I'm guessing that I need to access the document object somehow from Greasemonkey but am not sure how to do this.
I know the script is getting called because if I comment out the $('a,%20.vote-up-off,%20.vote-down-off,%20.star-off').attr({role:'link',tabindex:'0'})
line my alert gets hit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
window.wrappedJSObject
访问%20 在 Greasemonkey 版本中带有空格字符
代码:
window.wrappedJSObject
%20
in your Greasemonkey version with a space charCode:
由于 Greasemonkey 脚本不会对其源代码进行 URL 解码,因此您需要将所有
%20
替换为 空格 字符。然后,要访问页面的 jQuery,如果页面有它,只需使用:
1.注意:这两种方法,尤其是 JAAulde 的答案,都存在轻微风险该网页可以攻击您的系统。
一种替代方法,(1) 没有安全风险,并且 (2) 适用于不使用 jQuery 的页面;是让 GM 脚本使用它自己的 jQuery。
这样做:
Because a Greasemonkey script does not URL decode its source, you need to replace all
%20
with the space character.Then, to access the page's jQuery, if the page even has it, just use:
1. Note: Both this method, and especially JAAulde's answer, carry a slight risk that the web page can pwn your system.
An alternate method, (1) without the security risk, and that (2) works on pages that don't use jQuery; is for the GM script to use it's own jQuery.
Do that like so: