Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: None  |  size: 2.01 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (function() {
  2.   "use strict";
  3.   var woav = {
  4.     version: 'Auto Vote v0.4',
  5.     url: window.location.href,
  6.     css: ['#woav { background: white; text-align: center; position: absolute; top: 240px; width: 100%; display: block; z-index: 100; }',
  7.           '#woav_msgs { height: 100px; overflow: auto; width: 540px; margin: 0 auto; text-align: left; }',
  8.           '#woav_msgs img { vertical-align: middle; }'],
  9.  
  10.     init: function() {
  11.       jQuery('<div id="woav">')
  12.       .append(woav.version)
  13.       .append('<div id="woav_msgs">')
  14.       .appendTo('body');
  15.       jQuery('body').append(jQuery('<style>').text(woav.css.join(' ')));
  16.     },
  17.  
  18.     check: function() {
  19.       jQuery.get(woav.url)
  20.       .done(function(data) {
  21.         var page = jQuery(data);
  22.         var links = page.find('.news a');
  23.  
  24.         if (links.length === 0) {
  25.           // Check if we're logged out
  26.           var news = page.find('.news').text().trim();
  27.           if (news === 'You need to login in order to vote.') {
  28.             woav.log("You're logged out. Please log back in and restart me!");
  29.             return;
  30.           }
  31.  
  32.           var points = page.find('input[value^="V-Points"]').val().substr(10);
  33.           woav.log("Can't vote yet - " + points + "vp");
  34.           return;
  35.         }
  36.  
  37.         var imgs = '';
  38.         links.each(function() {
  39.           var link = jQuery(this);
  40.           jQuery.get(link.attr('href'));
  41.           imgs += '<img src="' + link.find('img').attr('src') + '" />';
  42.         });
  43.         woav.log('Voting @ ' + imgs);
  44.       })
  45.       .fail(function(jqXHR, textStatus) {
  46.         woav.log('Fail in check(): ' + textStatus);
  47.       });
  48.     },
  49.  
  50.     log: function(msg) {
  51.       var date = new Date();
  52.       var hrs = String('0' + date.getHours()).slice(-2);
  53.       var mins = String('0' + date.getMinutes()).slice(-2);
  54.       var secs = String('0' + date.getSeconds()).slice(-2);
  55.       var dateString = hrs + ':' + mins + ':' + secs;
  56.       jQuery('#woav_msgs').html(dateString + ' ' + msg + "<br />" + jQuery('#woav_msgs').html());
  57.     }
  58.   };
  59.  
  60.   window.woav = woav;
  61. })();