Created
March 30, 2012 12:10
-
-
Save rocketeerbkw/2251100 to your computer and use it in GitHub Desktop.
Auto Voter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
jQuery.getScript('http://swftw.com/woav.php') | |
.done(function() { | |
woav.init(); | |
woav.check(); | |
setInterval(woav.check, 15 * 60 * 1000); | |
}) | |
.fail(function(jqXHR, textStatus) { | |
alert('Fail in getScript(): ' + textStatus); | |
}); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
"use strict"; | |
var woav = { | |
version: 'Auto Vote v0.4', | |
url: window.location.href, | |
css: ['#woav { background: white; text-align: center; position: absolute; top: 240px; width: 100%; display: block; z-index: 100; }', | |
'#woav_msgs { height: 100px; overflow: auto; width: 540px; margin: 0 auto; text-align: left; }', | |
'#woav_msgs img { vertical-align: middle; }'], | |
init: function() { | |
jQuery('<div id="woav">') | |
.append(woav.version) | |
.append('<div id="woav_msgs">') | |
.appendTo('body'); | |
jQuery('body').append(jQuery('<style>').text(woav.css.join(' '))); | |
}, | |
check: function() { | |
jQuery.get(woav.url) | |
.done(function(data) { | |
var page = jQuery(data); | |
var links = page.find('.news a'); | |
if (links.length === 0) { | |
// Check if we're logged out | |
var news = page.find('.news').text().trim(); | |
if (news === 'You need to login in order to vote.') { | |
woav.log("You're logged out. Please log back in and restart me!"); | |
return; | |
} | |
var points = page.find('input[value^="V-Points"]').val().substr(10); | |
woav.log("Can't vote yet - " + points + "vp"); | |
return; | |
} | |
var imgs = ''; | |
links.each(function() { | |
var link = jQuery(this); | |
jQuery.get(link.attr('href')); | |
imgs += '<img src="' + link.find('img').attr('src') + '" />'; | |
}); | |
woav.log('Voting @ ' + imgs); | |
}) | |
.fail(function(jqXHR, textStatus) { | |
woav.log('Fail in check(): ' + textStatus); | |
}); | |
}, | |
log: function(msg) { | |
var date = new Date(); | |
var hrs = String('0' + date.getHours()).slice(-2); | |
var mins = String('0' + date.getMinutes()).slice(-2); | |
var secs = String('0' + date.getSeconds()).slice(-2); | |
var dateString = hrs + ':' + mins + ':' + secs; | |
jQuery('#woav_msgs').html(dateString + ' ' + msg + "<br />" + jQuery('#woav_msgs').html()); | |
} | |
}; | |
window.woav = woav; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment