speedrun timer (death%)

stop time alive percicely

  1. // ==UserScript==
  2. // @name speedrun timer (death%)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description stop time alive percicely
  6. // @author Marlis
  7. // @match https://takepoint.io/
  8. // @icon https://www.google.com/s2/favicons?domain=takepoint.io
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. let foot = document.getElementById("footers");
  15. let play = document.getElementById("p");
  16. let timer;
  17. let gTime, rTime; //gameTime (lag dependend), realTime
  18. let pB = 10000; //in milliseconds, just to have a starting value. Can be adjusted
  19. let attemps = 0;
  20.  
  21. let observer = new MutationObserver(function(mutations){
  22. mutations.forEach(function(mutation){
  23. if(mutation.type == "attributes"){
  24. if(document.getElementById("footers").style.display == "flex"){
  25. stopTimer(); //stops timer on death
  26. }
  27. }
  28. });
  29. });
  30. observer.observe(foot, {
  31. attributes: true //configure it to listen to attribute changes
  32. });
  33.  
  34. setTimeout(function(){ //to give the page time to load
  35. play.onclick = function(){eg(); restartTimer();}; //restart the timer when the play-button is pressed
  36. }, 5000);
  37.  
  38.  
  39.  
  40. function restartTimer(){
  41. gTime = 0;
  42. rTime = new Date().getTime(); //get starting time
  43. clearInterval(timer);
  44. timer = setInterval(function(){ //restart the timer function
  45. let elem = document.getElementById("show_global");
  46. if(elem){
  47. elem.innerHTML = gTime + "</br>Personal best: " + pB/1000 + "</br>attemps: " + attemps;
  48. }
  49. else{
  50. createHUD();
  51. }
  52. gTime = ((gTime*10)+1) / 10; //to prevent rounding errors
  53. if(gTime*1000 > pB+2000){ //restart, when you pass 2 seconds afte your personal Best
  54. Module.switchServers("Frankfurt|tak-fra-pggcj.io-8.com"); //reload the page
  55. attemps++;
  56. }
  57. }, 100); //gTime updates every 100ms
  58.  
  59. }
  60.  
  61. function stopTimer(){
  62. clearInterval(timer);
  63. rTime = new Date().getTime() - rTime; //get the passed time
  64. attemps++;
  65. if(pB > rTime){ //if you got a new personal Best..
  66. pB = rTime;
  67. timer = setInterval(function(){ //shows the new time
  68. let elem = document.getElementById("show_global");
  69. if(elem){
  70. elem.innerHTML = gTime + "</br> After re-time: " + rTime/1000;
  71. }
  72. else{
  73. createHUD();
  74. }
  75. }, 1000);
  76. }
  77. else{ //else just restart
  78. restartTimer();
  79. Module.switchServers("Frankfurt|tak-fra-pggcj.io-8.com");
  80. }
  81. }
  82.  
  83. function createHUD(){ //create the overlay to display the time, credits go to pureskillz (KiranV)
  84. let elem1 = document.createElement("div");
  85. //#overlay {display: block;z-index: 10;position: absolute;top: 50px; left: 10px;}
  86. elem1.id = "show_global";
  87. elem1.style.display = "block";
  88. elem1.style.zIndex = "10";
  89. elem1.style.position = "absolute";
  90. elem1.style.top = "50px";
  91. elem1.style.left = "10px";
  92. elem1.style.backgroundColor = "black";
  93. elem1.style.color = "white";
  94. document.body.appendChild(elem1);
  95. }
  96.  
  97. // Your code here...
  98. })();