Advertisement
Guest User

StackEgg Bot modified

a guest
Apr 1st, 2015
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Javascript (and jQuery) bot for "Stack Egg" on Stack Exchange (April Fools 2015).
  2. //Paste this into the console of your browser. It has only been tested in Google Chrome.
  3. //Stop it with clearInterval(egger)
  4. // Original by Calvin's Hobbies
  5. (function () {
  6.     function vote() {
  7.        
  8.         var attr = {
  9.             'questions': {
  10.                 'val': 4,
  11.                 'btn': 'Ask'
  12.             },
  13.             'answers': {
  14.                 'val': 4,
  15.                 'btn': 'Answer'
  16.             },
  17.             'users': {
  18.                 'val': 4,
  19.                 'btn': 'Upvote'
  20.             },
  21.             'quality': {
  22.                 'val': 4,
  23.                 'btn': 'Downvote'
  24.             },
  25.         }
  26.        
  27.         var red = '';
  28.         $.each(attr, function(key, val) {
  29.             var s = $('#egg-stat-' + key)
  30.             if (s.length > 0) {
  31.                 s = parseInt(s.attr('title')[0])
  32.                 var v = (isNaN(s) ? -1 : s);
  33.                 val.val = v;
  34.                 if(v < 0) red = key;
  35.                 attr[key] = val;
  36.             }
  37.         });
  38.        
  39.        
  40.         // Maximize Ask, then Answer, then Quality, then Users. Upvote if a question is in red.
  41.        
  42.         //determine what button to press, press Ask by default
  43.         var btn;
  44.         if(red != '')
  45.         {
  46.             btn = attr[red].btn;
  47.         }
  48.         else
  49.         {
  50.             if(attr['questions'].val < 4)
  51.                 btn = attr['questions'].btn;
  52.             else if(attr['questions'].val > attr['answers'].val)
  53.                 btn = attr['answers'].btn;
  54.             else if(attr['users'].val > 0 && attr['quality'].val < attr['answers'].val)
  55.                 btn = attr['quality'].btn;
  56.             else if(attr['users'].val < 4)
  57.                 btn = attr['users'].btn;
  58.             else
  59.                 btn = attr['questions'].btn;
  60.         }
  61.  
  62.         //click the button selected, or click Continue then Restart if button not found
  63.         var clickPriority = [btn, 'Continue', 'Restart'], b = $('button')
  64.         for(var i = 0; i < clickPriority.length; i++) {
  65.             b.each(function() {
  66.                 var t = $(this)
  67.                 if (t.text() == clickPriority[i]) {
  68.                     t.click()
  69.                     console.log('Voted for ' + clickPriority[i] + ' at ' + (counter * 10).toString() + ' seconds in.')
  70.                     i = clickPriority.length
  71.                 }
  72.             })
  73.         }
  74.         ++counter
  75.     }
  76.     counter = 0
  77.     vote()
  78.     egger = setInterval(vote, 10000) //10 seconds instead of 20 ensures there are no sync problems
  79. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement