我想在选项卡获得焦点后短暂延迟后单击按钮
我希望在选择[聚焦]选项卡时执行 setTimeout
函数。我正在使用 Mozilla(Greasemonkey)。
这是我尝试过的:
// ==UserScript==
// @name [udit]click stumble button on pages
// @namespace uditeewd
// @include http://www.stumbleupon.com/interest/*
// @include http://www.stumbleupon.com/channel/*
// @include http://www.stumbleupon.com/stumbler/*
// @exclude http://www.stumbleupon.com/stumbler/*/likes/interest*
// @exclude http://www.stumbleupon.com/interest/*/followers*
// @exclude http://www.stumbleupon.com/channel/*/followers*
// @exclude file:///*
// ==/UserScript==
setTimeout(function(ButtonClickAction) {
var stumbButt = document.querySelector ("div.stumbler-card a.stumble-button");
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
stumbButt.dispatchEvent (clickEvent);
}, 0);
document.addEventListener ("onfocus", ButtonClickAction, true);
I want the setTimeout
function to execute when I've selected[focused] the tab. I am using Mozilla (Greasemonkey).
Here's what I've tried:
// ==UserScript==
// @name [udit]click stumble button on pages
// @namespace uditeewd
// @include http://www.stumbleupon.com/interest/*
// @include http://www.stumbleupon.com/channel/*
// @include http://www.stumbleupon.com/stumbler/*
// @exclude http://www.stumbleupon.com/stumbler/*/likes/interest*
// @exclude http://www.stumbleupon.com/interest/*/followers*
// @exclude http://www.stumbleupon.com/channel/*/followers*
// @exclude file:///*
// ==/UserScript==
setTimeout(function(ButtonClickAction) {
var stumbButt = document.querySelector ("div.stumbler-card a.stumble-button");
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
stumbButt.dispatchEvent (clickEvent);
}, 0);
document.addEventListener ("onfocus", ButtonClickAction, true);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将其分解为几个步骤:
请注意,您需要定义哪些节点构成“选项卡”。您当前的代码会在整个页面上聚焦。
所以,代码会是这样的:
Break it down to steps:
Note that you need to define what node(s) constitute the "tab". Your current code fires on focus for the whole page.
So, the code would be something like:
window.onblur 和 window.onfocus ?
window.onblur and window.onfocus ?