Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Auto-Refresh
  3. // @namespace    tf-ingame
  4. // @version      0.81
  5. // @description  Auto-refreshes when it's your turn.
  6. // @author       Triad Freak
  7. // @match        http://www.ttadvance.ca/play.php?game_iden=*
  8. // @grant        none
  9. // @require      https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  10. // ==/UserScript==
  11. function playSound(){
  12.     // Add a real http path to a sound file and uncomment (remove the two slashes) for sound
  13.     //(new Audio('http://path.com/to/sound.mp3')).play();
  14. }
  15. function checkTurn(de, first){
  16.     var forms = de.getElementsByTagName('form');
  17.     if((first && forms.length===0) || (forms.length==2 &&
  18.     forms[0].innerHTML.substr(36, 9)!=='You Have ')) return false;
  19.     return true;
  20. }
  21. function checkTurnData(data){
  22.     var de = document.createElement('html');
  23.     de.innerHTML = data;
  24.     if(checkTurn(de, false)) window.location.assign(location.href+'&sound=1');
  25. }
  26. // Checks if it's your turn again. Reloads page if it is or network issues.
  27. // If not, then just wait 3 seconds and check again!
  28. function checking(){
  29.     $.get(location.href, checkTurnData)
  30.     .fail(()=>{window.location.assign(location.href+'&sound=1');});
  31.     setTimeout(checking, 3000);
  32. }
  33. // This function makes it so a sound plays when there's 30 and 15 seconds left of your turn
  34. // A true game saver, but remember to fix audio path.
  35. function clockTimeout(){
  36.     var clock = document.frm.clock.value*1000;
  37.     if(clock>15000){
  38.         setTimeout(playSound, clock-15000);
  39.         if(clock>30000){
  40.             setTimeout(playSound, clock-30000);
  41.         }
  42.     }
  43. }
  44. // Waits 5 seconds before starting to check if it's your turn.
  45. // Once it starts it will check again every 3rd second (checking).
  46. if(!checkTurn(document.documentElement, true)) setTimeout(checking, 5000);
  47. else{
  48.     document.getElementsByName('clock')[0].style.fontSize = 50;
  49.     if(window.location.search.indexOf('sound')!=-1) playSound();
  50.     else if(document.referrer.indexOf('waiting')!=-1) playSound();
  51.     setTimeout(clockTimeout, 5000);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement