使用Tampermonkey Chrome循环“自动点击特定按钮”的jquery代码

时间:2015-05-31 21:46:58

标签: javascript jquery html google-chrome button

更新:实际的代码和间隔函数可以工作,但是我仍然无法让它像Tampermonky脚本那样正常运行。控制台将为甚至不属于脚本的字符吐出错误。 所以我唯一需要使用chrome作为扩展或者使用tampermonkey用户工作,我会成为一个快乐的露营者。

这是我收到的错误:

Syntax error @ '********.com Auto Clicker'!
##########################
JSHINT output:
require: (E030) Expected an identifier and instead saw '<' on line: 2 at character: 1
require: (E033) Expected an operator and instead saw '!' on line: 2 at character: 2
require: (W030) Expected an assignment or function call and instead saw an expression on line: 2 at character: 2
require: (W033) Missing semicolon on line: 2 at character: 3
require: (W030) Expected an assignment or function call and instead saw an expression on line: 2 at character: 3
require: (W033) Missing semicolon on line: 2 at character: 10
require: (E030) Expected an identifier and instead saw '<' on line: 3 at character: 1
require: (E033) Expected an operator and instead saw '!' on line: 3 at character: 2
require: (E033) Expected an operator and instead saw '--' on line: 3 at character: 3
require: (E033) Expected an operator and instead saw '[' on line: 3 at character: 5
require: (E041) Unrecoverable syntax error. (0% scanned) on line: 3 at character: 6
##########################

SyntaxError: Unexpected token <
at Function (native)
at d (eval at <anonymous> (unknown source), <anonymous>:27:37)
at eval (eval at <anonymous> (eval at <anonymous> (unknown source)), <anonymous>:1:24)
at eval (native)
at m (eval at <anonymous> (unknown source), <anonymous>:53:418)
at Z (eval at <anonymous> (unknown source), <anonymous>:27:80)
at aa (eval at <anonymous> (unknown source), <anonymous>:63:497)
at chromeEmu.extension.onMessage.addListener.b (eval at <anonymous> (unknown source), <anonymous>:64:398)
at eval (eval at <anonymous> (unknown source), <anonymous>:31:339)(anonymous function) @ VM1109:28Context.chromeEmu.f.runResponse @ VM1109:13(anonymous function) @ VM1120:1(anonymous function) @ VM1120:1copy.exec @ VM1106:1copy.Eventing.d @ VM1106:8copy.Eventing.c.eventHandlerPage @ VM1106:12c.standardEventSource.element.dispatchEvent @ content.js:22c.fireEvent @ content.js:24g.sendMessage @ content.js:8d.onResponse @ content.js:16(anonymous function) @ content.js:18messageListener @ extensions::messaging:352propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19EventImpl.dispatchToListener @ extensions::event_bindings:395propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19$Array.forEach.publicClass.(anonymous function) @ extensions::utils:94EventImpl.dispatch_ @ extensions::event_bindings:379EventImpl.dispatch @ extensions::event_bindings:401propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19$Array.forEach.publicClass.(anonymous function) @ extensions::utils:94dispatchOnMessage @ extensions::messaging:316

原文:所以我正在摆弄一个小项目;我已经多次被问到这个问题,但在搜索谷歌,这个网站等几个小时后,我必须说我完全被难倒了。我目前有

这已根据以下一些评论进行了更新。

// ==UserScript==
// @name         *******.com Auto Clicker
// @version      0.1
// @description  Made this for fun, simply clicks for you on *******.com
// @author       Cole Smith
// @match        *********************
// @require      http://code.jquery.com/jquery*
// @grant        none
// ==/UserScript==

setInterval(function(){ 
    if ($(timerValue).hasClass("timer hide")) {
        $('a.btn.btn-small.button_next.btn-advance').click();
   } 
},1000);

明星是混淆。 除了JQuery之后的明星,因为我只是想要它需要任何版本。

我只是希望它在页面上处于活动状态,并以重复的方式继续这样做。如果我可以使用chrome中的键击来禁用它,那将是不错的,但这不是我现在太在意的事情。

注意: 我确实有@match设置,它会在tampermonkey扩展程序中显示为已启用但 NOT 运行一次。

2 个答案:

答案 0 :(得分:1)

您需要更改 @require 以加载jQuery而不是网站。当前语句导致http://code.jquery.com/jquery*的HTML被解释为Javascript。这导致了

  

SyntaxError:意外的标记&lt;

错误消息。因此,解决方案是将此行更改为:

// @require    http://code.jquery.com/jquery-1.11.3.min.js

答案 1 :(得分:0)

编辑:在建立代码目标后更改了答案。

setInterval(function(){ 
    if ($(timerValue).hasClass("hide")) {
        $('a.btn.btn-small.button_next.btn-advance').click();
    } 
},500); //change 500 to the time in MS to wait before each run.