Advertisement
Guest User

Untitled

a guest
Aug 15th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name       Auto vote for CSC
  3. // @namespace  http://casinocoin.org/
  4. // @version    0.1
  5. // @description  Auto votig for casinocoin on swisscx
  6. // @match      https://www.swisscex.com/voting
  7. // @copyright  2014+, JohnnyM, Licence: WTFPL (http://www.wtfpl.net/txt/copying/)
  8. // ==/UserScript==
  9.  
  10. // @include https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  11.  
  12. var cscButton = null;
  13. var clickCount = 0;
  14.  
  15. function getRandomInt(min, max) {
  16.     return Math.floor(Math.random() * (max - min + 1)) + min;
  17. }
  18.  
  19. function clickVote() {
  20.     if (cscButton.is(':disabled')) {
  21.         console.log('Button disabled. Reload in 5 sec.');
  22.         setTimeout(function(){ window.location.reload(true); }, 1000*5);
  23.         return;
  24.     }
  25.     cscButton.click();
  26.     clickCount++;
  27.     console.log('Clicks: '+ clickCount);
  28.     return;
  29.  
  30.    
  31. }
  32.  
  33.  
  34. function doVote() {
  35.     var csctd = $("tr td:contains('CasinoCoin')");
  36.     if (csctd.length !== 1) {
  37.         console.log('Error: More then 1 or no csc rows in voting table!');
  38.         setTimeout(function(){ window.location.reload(true) }, 5000);
  39.         return;
  40.     }
  41.     console.log('Got CSC td');
  42.     var button = $(csctd[0]).parent().find('button')[0];
  43.     //console.log(button);
  44.     if (button.disabled === true) {
  45.         console.log('Button is disabled');
  46.         var timer = $('p[data-ng-hide="canVote"] > strong');
  47.         if (timer.length === 1) {
  48.             console.log('Found timer');
  49.             // refresh each 10 min to stay logged in
  50.             var reload = ['00:00:01', '00:10:00', '00:20:00', '00:30:00', '00:40:00', '00:50:00', '23:59:45'];
  51.             var left;
  52.             timer.on('DOMSubtreeModified', function() {
  53.                 left = timer.html();
  54.                 if (reload.indexOf(left) !== -1) {
  55.                     window.location.reload(true);
  56.                 }
  57.             });
  58.         } else {
  59.             var timeout = getRandomInt(30, 60);
  60.             console.log('Can\'t find timer. Refresh in '+ timeout + ' seconds');
  61.             setTimeout(function(){ window.location.reload(true) }, 1000*timeout);        
  62.         }
  63.         return;
  64.     }
  65.     console.log('Button is enabled. Clicking');
  66.     cscButton = $(button);
  67.    
  68.     clickVote();
  69.     setTimeout(function(){ clickVote(); }, 1000*3);
  70.     setTimeout(function(){ clickVote(); }, 1000*6);
  71. }
  72.  
  73. $(document).ready(function() {
  74.     console.log('doc ready');
  75.     setTimeout(function() { doVote(); }, 1000);
  76.     //$('p[data-ng-hide="canVote"] > strong').html(); // time to next vote
  77.     //$('p[data-ng-hide="canVote"]').prev().find('strong').html(); // votes left
  78.    
  79.     // connection issues? refresh page after 15 min.
  80.     setTimeout(function() { window.location.reload(true); }, 1000*60*15);
  81. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement