开发者

Greasemonkey autoclick script cracked by site update [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

Would appreciate your help with something.

I have an autoclick Greasemonkey for Firefox script that autoclicks a link on the site I work at when a job comes in. The script is this:

var BEEP_URL = 'file:///C:/Users/Home/beep.html'; //local url to beep.html for     example 'file:///C:/deploy/html/beep.html'
var REFRESH_DELAY = 8; // in seconds
var CLICK_DELAY = 0; // in seconds
var LENGTH_MIN = 15 // min length of audio in minutes
var LENGTH_MAX = 600 // max length of audio in minutes 

function init() {
var refreshTimer = window.setTimeout(function() {
    location.reload();
}, REFRESH_DELAY * 1000);

if(!$('a:contains(Read now)').length){
    href = false;
    $('a:contains(Start)').each(function() {
        time = parseInt($(this).parents('td').nextAll('td').contents('small').html());
        if (!href && time >= LENGTH_MIN && time <= LENGTH_MAX) {
            GM_openInTab(BEEP_URL); 
            href = this.href;
            clearTimeout(refreshTimer);
            window.setTimeout(function() {
                top.location.href = href;
            }, CLICK_DELAY * 1000);
        }
    })
}
}

if (window.addEventListener) {
window.addEventListener('load', init, false);
} else {
document.attachEvent('onload', init);
}

The important bits of the page on the site I work at looks like this:

<tr>
<td><a title = 'Job'>Job</a></td>

<td>4</td>

<td><i>Group</i></td>

<td>3/10/2011</td>

<td><a href=http://www.site.com>Start</a></td>

<td><a href='/sound/job_sound.mp3' ><img border=0 src=/images/audio.gif title='79 min uploaded 3/10/2011 7:39:31 AM' ></a><br /><small>80 min <br />7:39:31 AM</small></TD>

<td>&nbsp;</td>
</tr>

As you can see, the script refreshes the page and if a job comes in with the link 'Start' and the right amount of minutes for the LENGTH_MIN and LENGTH_MAX variables in the small tag in the table (second last td cell), then the script will click the 'Start' link.

Recently, however, the site has changed the structure of the page slightly so that it now looks like this:

<tr>
<td><a title = 'Job'>Job</a></td>

<td>4</td>

<td><i>Group</i></td>

<td>3/10/2011</td>

<td><a href=http://www.site.com>Start</a></td>

<td><small>Audio 1: </small><a href='/sound/job_sound.mp3' ><img border=0 src=/images/audio.gif title='Audio 1: 39 min uploaded 10/4/2011 7:13:06 AM' alt='Audio 1 39 min uploaded 10/4/2011 7:13:06 AM'></a><small>40 min 7:13:06 AM</small><BR><small>Audio 2: </small><a href='/audio/job_sound2.mp3' ><img border=0 src=/images/audio.gif title='Audio 2: 40 min uploaded 10/4/2011 7:15:19 AM' alt='Audio 2 40 min uploaded 10/4/2011 7:15:19 AM'></a><small>41 min 7:15:19 AM</small><br>&nbsp;<br></TD>

<td>&nbsp;</td>
</tr>

As you can see, the bit that the LENGTH_MIN and LENGTH_MAX variables is called by has been changed (at least, that's where I think the problem is) and now the script doesn't work anymore. Two or more audio files are shown now on the page and the time is inserted in the small tag. Is there anything you can see there that I can change in the script to get it to work with this page? It seems like it gets called by data in the page wrappe开发者_StackOverflow中文版d in small tags, and the site has changed how that section of the table is laid out which is causing the script problems. I'm not sure what to tweak in the script to make it still click the 'Start' link.

Would really appreciate your help. Thanks a lot.


The minimal change to fix this might be to replace .contents('small') (which, as far as I can tell from the docs, probably doesn't do what you think anyway) with .find('small').eq(1). This might not be a very robust solution (i.e. it might break again in the future if there are more changes to the document structure), but it's hard to say what might be better without knowing more details.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜