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