开发者

Help Troubleshooting 1st Greasemoney Script

开发者 https://www.devze.com 2023-03-15 15:59 出处:网络
I\'m trying to do my first greasemoney script.I\'m fairly new to jquery and 开发者_C百科javascript, so be easy on me.

I'm trying to do my first greasemoney script. I'm fairly new to jquery and 开发者_C百科javascript, so be easy on me.

Here is what I have so far.

setTimeout(function(){
    $('a').each(function(i){
        if(this.href && this.innerHTML.indexOf('load more comments') > -1){
            toggle(this);
        }
    });
}, 4000);

The goal here is to click on all of the "load more comments" page on a sample reddit page like this, and to loop doing it every four seconds.

http://www.reddit.com/r/AskReddit/comments/i7hb5/why_assign_gender_to_public_bathrooms_if_there_is/

Right now, nothing happens at all. I'm not sure how to troubleshoot. Is the script not being launched at all? Is indexOf the right syntax for clicking the links?

Is there an online guide that would walk me though writing a basic greasemoney / jquery script like this?

Any help greatly appreciated. Thanks!

Edit:

Based on Tomalak's response,

// ==UserScript==
// @name           load all page comments
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @namespace      none
// @include        http://www.reddit.com/*
// ==/UserScript==

setInterval( function () {
  $('a:contains(load more comments)').click();
}, 4000);


It's much easier than you think:

setInterval( function () {
  $('a:contains(load more comments)').click();
}, 4000);

Note that I use setInterval instead of setTimeout.

jQuery works in such a way that click is called on every matched element, i.e. there's no need for each() in this situation. Also see the docs on the :contains selector.

0

精彩评论

暂无评论...
验证码 换一张
取 消