- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我要修改的页面,我想绕过倒计时,脚本应该怎么写?有没有一种方法可以使用 Greasemonkey 将变量 document.licenseform.btnSubmit.disabled
更改为 yes?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>dsfsdf</title>
</head>
<body>
<form name="licenseform" method="post" action="">
<input name="btnSubmit" type="button" value="我同意">
</form>
<SCRIPT language=javascript type=text/javascript>
<!--
var secs = 9;
var wait = secs * 1000;
document.licenseform.btnSubmit.value = "我同意 [" + secs + "]";
document.licenseform.btnSubmit.disabled = true;
for(i = 1; i <= secs; i++)
{
window.setTimeout("Update(" + i + ")", i * 1000);
//这一句很关键,记得参数写法为("update("+i+")",i*1000)
}
window.setTimeout("Timer()", wait);
function Update(num)
{
if(num != secs)
{
printnr = (wait / 1000) - num;
document.licenseform.btnSubmit.value = "我同意 [" + printnr + "]";
}
}
function Timer()
{
document.licenseform.btnSubmit.disabled = false;
document.licenseform.btnSubmit.value = " 我同意 ";
}
-->
</SCRIPT>
</td>
<!--网页中部中栏代码结束-->
</body>
</html>
最佳答案
使用 unsafeWindow
更安全的替代方法是将代码注入(inject)文档。您注入(inject)的代码将在与页面代码相同的上下文中运行,因此它将可以直接访问那里的所有变量。但它无法访问用户脚本代码其他部分中的变量或函数。
注入(inject)代码的另一个好处是,以这种方式编写的用户脚本可以在 Chrome 和 Firefox 中运行。 Chrome 根本不支持 unsafeWindow
。
我最喜欢的注入(inject)代码的方式是编写一个函数,然后使用这个可重用的代码来取回该函数的源代码:
// Inject function so that in will run in the same context as other
// scripts on the page.
function inject(func) {
var source = func.toString();
var script = document.createElement('script');
// Put parenthesis after source so that it will be invoked.
script.innerHTML = "("+ source +")()";
document.body.appendChild(script);
}
要切换btnSubmit
,您可以编写如下脚本:
function enableBtnSubmit() {
document.licenseform.btnSubmit.disabled = false;
document.licenseform.btnSubmit.value = " 我同意 ";
// Or just invoke Timer()
}
function inject(func) {
var source = func.toString();
var script = document.createElement('script');
script.innerHTML = "("+ source +")()";
document.body.appendChild(script);
}
inject(enableBtnSubmit);
请记住,当您以这种方式使用函数的序列化形式时,正常的闭包作用域将不起作用。您注入(inject)的函数将无法访问脚本中的变量,除非它们是在该函数内部定义的。
关于javascript - 如何使用 Greasemonkey 更改 JavaScript 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5722075/
这个问题在这里已经有了答案: How to call Greasemonkey's GM_ functions from code that must run in the target page s
是否可以使用 Greasemonkey 脚本跨域存储数据?我想允许从使用相同 Greasemonkey 脚本的多个网站访问 Javascript 对象。 最佳答案 是的,这就是 GM_setvalue
我有一个简单的 Greasemonkey 脚本: // ==UserScript== // @name hello // @namespace http://www.webmonkey.com //
我想写一个非常简单的 greasemonkey 脚本,因为我讨厌“你确定吗?”我经常使用的网站上的 javascript 确认。我只是将它用于个人用途,不会发布它或任何东西。经过一番谷歌搜索后,我找到
这是一个有点奇怪的具体问题。 我正在编写一个可以跨十个域运行的 Greasemonkey 脚本。这些网站都具有相同的结构,但每个网站的域名不同。例如,脚本将运行: http://first-domai
我为一个域制作了一个greasemonkey脚本,现在如何让它只运行一次?就像每次访问域时它都会启动一样,我不希望这样。如何使其仅运行一次,然后删除自身或使其处于非事件状态? 谢谢。 最佳答案 如果您
我发现了很多类似的问题,但没有一个是平等的,也没有正确的解决方案。这是一个非常奇怪的问题。 我有一个简单的 Greasemonkey 脚本来测试这个问题: // ==UserScript== // @
我正在写一个 Greasemonkey 脚本,如何实现自动更新? 可以将脚本放入 GitHub 存储库并设置 @version数字? 然后......是一些自动的方式如何做到这一点?或者我必须手动检查
我现在正在研究用户脚本。我知道 Opera 与 Greasemonkey 脚本的许多方面兼容,但与其他方面不兼容。 GM functions emulation script在 Opera 上将需要,
最近在写一个用户脚本时,我发现页面上下文中的变量是可用的。 console.log(window) 在 Tampermonkey 和 Greasemonkey 中都没有导致错误。 我很困惑。全局变量不
看完后Greasemonkey recommends users to install Tampermonkey or Violentmonkey . 我已经安装了 Tampermonkey,现在我正
我在一堆 div 和一个表单中包含了一些输入值。我对 js 的了解有限,想在页面加载时使用油脂猴来设置值。 下面显示了获取值的 div 和表单的顺序。
有没有办法使用用户脚本将一些设置保存到不是 cookie 的本地计算机? 如果设置不是全局的,则很难制作用于多个域的用户脚本。 来自评论: "I am using scriptish " 。 最佳答案
我有一个带有以下元块的油脂猴脚本- // ==UserScript== // @name TDF Improved Dark Skin // @namespace TDF // @incl
我有用于Firefox的Greasemonkey脚本。该脚本包括此元块和一些代码行。 我想在服务器上更新脚本,然后自动更新浏览器的脚本。 requireSecureUpdates选项已关闭。 我究竟做
我正在按照说明将 Greasemonkey 脚本传输到 Tampermonkey:How to Transfer All Greasemonkey userscripts to Tampermonke
This question already has an answer here: My very simple Greasemonkey script is not running? (1个答案)
我需要在公司内部网站上托管用户脚本。我如何构建 href这样 Greasemonkey 会在点击链接时安装用户脚本吗? 我尝试了一个简单的 Install Userscript但是 Chrome 和
例如,在远程网页中,有如下代码片段: function foo(){ this.bar = 0; } 在我的油脂猴子脚本中,我想创建此类的对象: var _foo= unsafeWindow['fo
我想在文档中选择文本后调用函数。以下代码无效 var showSelWin = document.getElementById('innerwindow'); var txt = ' '; if (d
我是一名优秀的程序员,十分优秀!