Greasemonkey脚本自动单击javascript按钮(ajax吗?) [英] Greasemonkey script Auto click javascript button (ajax?)

查看:64
本文介绍了Greasemonkey脚本自动单击javascript按钮(ajax吗?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,这是页面的来源.

<div id="socialBox"></div>
<div class="friendButton addFriend">
    <a>+friend</a>
</div>

这是我的润滑脂猴子代码

Here is my greasemonkey code

// ==UserScript==
// @name        Auto click
// @namespace   Auto click
// @description Auto click
// @include     https://*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant       GM_addStyle
// ==/UserScript==

waitForKeyElements ("#friendButton addFriend", triggerMostButtons);

function triggerMostButtons (jNode) {
    triggerMouseEvent (jNode[0], "mouseover");
    triggerMouseEvent (jNode[0], "mousedown");
    triggerMouseEvent (jNode[0], "click");
    triggerMouseEvent (jNode[0], "mouseup");
}


function triggerMouseEvent  (node, eventType) {
    var clickEvent  = document.createEvent ('MouseEvents');
    clickEvent.initEvent (eventType, true, true);
    node.dispatchEvent (clickEvent);
}

greasemonkey说它正在执行代码,因此显然不起作用.让我知道您是否需要更多信息

greasemonkey says its executing the code so it clearly doesn't work. Let me know if you need more info

推荐答案

我想知道下面的代码是否是您想要的.

I wonder if the code below is what you want.

document.querySelector('.friendButton.addFriend a').click()

演示

您最好提供指向您要在其上执行脚本的页面之一的链接,以便我可以确保该脚本能够按预期运行.

You'd better provide a link to one of the pages on which you want your script executed, so that I can make sure the script will work as expected.

这篇关于Greasemonkey脚本自动单击javascript按钮(ajax吗?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆