nabbynz

Tagpro Play x Games

Oct 19th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name            Play x Games
  3. // @description     closes the tab after a set number of games
  4. //                  (requested thread: https://redd.it/3pf4y0)
  5. // @version         0.1.2
  6. // @include         http://tagpro-*.koalabeast.com*
  7. // @include         http://tangent.jukejuice.com*
  8. // @include         http://*.newcompte.fr*
  9. // @grant           GM_setValue
  10. // @grant           GM_getValue
  11. // @grant           GM_deleteValue
  12. // @license         GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  13. // @run-at          document-end
  14. // @author          nabby
  15. // ==/UserScript==
  16.  
  17. console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')');
  18.  
  19. function WhichPageAreWeOn(){
  20.     if (window.location.port) { //In a real game
  21.         return('ingame');
  22.     } else if (document.URL.indexOf('/games/find') > 0) { //Joining page
  23.         return('joining');
  24.     } else if ($('#play').length) { //Chosen server homepage
  25.         return('server');
  26.     } else if (document.URL.indexOf('/profile/') > 0) {
  27.         if ($('#showSettings').length) {
  28.             return('profile'); //Profile page and logged in
  29.         } else {
  30.             return('profileNotOurs'); //Profile page, but not our one (or we're logged out)
  31.         }
  32.     } else if ( ((window.location.host == 'tagpro.koalabeast.com') || (window.location.host == 'tagpro.gg')) && (window.location.pathname === '/') ) { //Choose server homepage
  33.         return('home');
  34.     }
  35. }
  36. var PageLoc = WhichPageAreWeOn();
  37.  
  38.  
  39. if (PageLoc === 'server') { //chosen server homepage
  40.     GM_deleteValue('gamesCount');
  41.     //$('#play').parent('div').prepend('<a id="playX" class="button" href="/games/find">Play X<span>pls</span></a>');
  42.  
  43.     $('#play').click(function(e) {
  44.         e.preventDefault();
  45.         e.stopPropagation();
  46.         e.stopImmediatePropagation();
  47.  
  48.         var response = prompt("How many games do you want to play?");
  49.         if (response !== null) { //cancel was not clicked
  50.             if ($.isNumeric(response)) {
  51.                 GM_setValue('gamesCount', parseInt(response));
  52.                 window.location.href = "/games/find";
  53.             } else { //enter or invalid was typed - just continue with no limit...
  54.                 GM_setValue('gamesCount', 'unlimited');
  55.                 window.location.href = "/games/find";
  56.             }
  57.         }
  58.     });
  59. }
  60.  
  61. if (PageLoc === 'joining') { //joiner
  62.     $('#message').after('<div style="text-align:center; font-size:20px; color:#ff0; background:#b0b; border-radius:5px">Games Remaining: ' + GM_getValue('gamesCount') + '</div>');
  63. }
  64.  
  65.  
  66. tagpro.ready(function() {
  67.     if (PageLoc === 'ingame') { //in a game
  68.        
  69.         tagpro.socket.on('settings', function(data) {
  70.             if (!tagpro.spectator) {
  71.                 $('#exit').after('<div style="margin:10px 0 0 5px; font-size:10px; color:#ff0">Games Remaining: <span id="playX_Message">' + (GM_getValue('gamesCount') === 1 ? 'None! (last game!)' : ($.isNumeric(GM_getValue('gamesCount')) ? (GM_getValue('gamesCount')-1) + ' (after this one)' : 'Unlimited!')) + '</span></div>');
  72.             }
  73.         });
  74.  
  75.         tagpro.socket.on('end', function(data) {
  76.             if (!tagpro.spectator) {
  77.                 if ($.isNumeric(GM_getValue('gamesCount'))) {
  78.                     var gamesCount = GM_getValue('gamesCount') - 1;
  79.                     GM_setValue('gamesCount', gamesCount);
  80.                     if (gamesCount <= 0) {
  81.                         var counter = 10;
  82.                         var redirectHandle = setInterval(function() {
  83.                             $('#playX_Message').html('None! (Quitting in '+(counter-1)+' Seconds)...').css('background', '#f00');
  84.                             if (counter > 0) {
  85.                                 counter--;
  86.                             } else {
  87.                                 clearInterval(redirectHandle);
  88.                                 window.close();
  89.                                 window.location.href = 'http://' + tagpro.serverHost; //just in case .close() doens't work
  90.                             }
  91.                         }, 1000);
  92.                     } else {
  93.                         $('#playX_Message').html(gamesCount + ' more to play...');
  94.                     }
  95.                 }
  96.             }
  97.         });
  98.     }
  99. });
Advertisement
Add Comment
Please, Sign In to add comment