Advertisement
Guest User

TagPro Game Notification

a guest
Sep 24th, 2016
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         TagPro Game Notification
  3. // @version      0.1
  4. // @description  Show a notification when a game started, and when the tab is not active.
  5. // @author       Comakip
  6. // @include      http://*.koalabeast.com:8*
  7. // @include      http://*.jukejuice.com:8*
  8. // @include      http://*.newcompte.fr:8*
  9. // @grant        GM_notification
  10. // ==/UserScript==
  11.  
  12. var timeNotifyBeforeGame = 5; //change this to the amount of time (in seconds) you want a notification before the game starts.
  13.  
  14. tagpro.ready(function(){
  15.     setTimeout(function(){
  16.             start();
  17.     },1000);
  18. });
  19.  
  20. function start(){
  21.   if(tagpro.spectator === false && document.hidden === true){ //when we're not spectating, and tab isn't acive; continue
  22.  
  23.     if (tagpro.state == 2){ //game ended (don't know if this would ever happen but whatever)
  24.       return;
  25.     }
  26.  
  27.     else if (tagpro.state == 1){ //game started
  28.       notify("Game started!");
  29.     }
  30.  
  31.     else if (tagpro.state == 3){ //waiting for game to start
  32.       var timeTillStart = tagpro.gameEndsAt - new Date().getTime();
  33.  
  34.       if (timeTillStart < timeNotifyBeforeGame * 1000){
  35.         notify("Game starts very soon!");
  36.       }
  37.       else {
  38.         var notifyTime = timeTillStart - timeNotifyBeforeGame * 1000;
  39.         setTimeout(function(){
  40.           notify("Game starts in " + timeNotifyBeforeGame + " seconds.");
  41.         }, notifyTime);
  42.       }
  43.     }
  44.   }
  45. }
  46.  
  47. function notify(message){
  48.   GM_notification(message, "TagPro", "https://pbs.twimg.com/profile_images/734800641072234496/aJpDBeF6_400x400.jpg" , function() { window.focus(); this.cancel(); });
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement