【问题标题】:Greasemonkey: click a linkGreasemonkey:点击链接
【发布时间】:2014-08-01 20:42:49
【问题描述】:

我想使用 Greasemonkey 点击此链接:

<a class="bbbx-button bbbx-button-grey" id="vote-button" data-bbbx-trigger="module.vote.submit" data-bbbx-id="51526" data-bbbx-score="10" data-bbbx-vote-type="up"><img src="//du3rc6beq6sv9.cloudfront.net/release1406643004647-5-1-2-1/assets/skins/default/images/vote/heart.png"> vote! <small id="vote-count">( 14 )</small></a>

我试过这段代码:

// ==UserScript==
// @name        test
// @namespace   test
// @include     *
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant       GM_addStyle
// ==/UserScript==
console.log("Start");


window.setTimeout(start, 7000);

function start()
{
    $("a#vote-button")[0].click();

    console.log("End clicktime");
}

但很遗憾,我找不到问题所在。

【问题讨论】:

  • 您当前的代码在我的测试用例中按预期工作。什么是完整的控制台输出?
  • 请尝试bit.ly/1uH4QUP

标签: greasemonkey


【解决方案1】:

您的 GM 脚本中没有加载 jQuery。

添加这个:

// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js

随时更改版本。

看看这个问题,它还为已经加载了jQuery的网站提供了一些解决方案:How can I use jQuery in Greasemonkey?

【讨论】:

  • 我进行了编辑。但是 End clicktime 日志现在也没有出现。
  • 你能再看看吗?
  • 我不确定你还能做什么。能否请您检查一下 jQuery 是否可用?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-03
  • 2013-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多