Track daily takepoint stats

track daily stats

  1. // ==UserScript==
  2. // @name Track daily takepoint stats
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description track daily stats
  6. // @author Tobi
  7. // @match https://stats.takepoint.io/gameState
  8. // @match https://takepoint.io/*
  9. // @grant none
  10.  
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var maxReq = 100; //number of requests, 100 for reliable results
  16. var scores = [];
  17. var stats = [];
  18. var num = [];
  19. var state = [];
  20. var hiScoresReq = new XMLHttpRequest();
  21.  
  22. function send(){
  23. hiScoresReq.open('GET', 'https://stats.takepoint.io/gameState');
  24. hiScoresReq.send();
  25. }
  26.  
  27. function processor(){
  28. stats.sort();
  29. state.sort();
  30. var z = 0
  31. for(var i = 0; i < state.length; i++){
  32. z = i + 1;
  33. if(state[i] == state[z]){
  34. stats.splice(z, 1);
  35. state.splice(z, 1);
  36. i--;
  37. }
  38. }
  39. for(var x in stats){
  40. console.log(stats[x]);
  41. }
  42. /* only if you wanna download
  43. if(confirm("Wanna download the daily facts?")){
  44. var blob = new Blob([stats.toString()],
  45. { type: "text/plain;charset=utf-8" });
  46. saveAs(blob, "scores.txt"); //save data to file, filesave.js library required, just add this to the top: // @require https://raw.githubusercontent.com/eligrey/FileSaver.js/master/src/FileSaver.js
  47. }
  48. */
  49. }
  50.  
  51.  
  52. for(var i = 0; i < maxReq; i++){ //do %maxReq% requests at a speed of 1/3 request per second (fastest reliable one)
  53. setTimeout(send, i*300);
  54. }
  55.  
  56. hiScoresReq.onreadystatechange = function(){
  57. if(this.readyState == 4){
  58.  
  59. scores = JSON.parse(this.response);
  60. /* only for highscores
  61. for(var i = 1; i <= 5; i++){
  62. console.log(i + ". " + scores[i-1].username + " - " + scores[i-1].score);
  63. }
  64. */
  65. for(var n in scores){
  66. if(!scores[n].username){
  67. //console.log(scores[n] + " " + n.toLocaleString() + " today!"); print out gamefact immediatly
  68. stats.push(n.toLocaleString() + " " + scores[n]);
  69. num.push(scores[n]);
  70. state.push(n.toLocaleString());
  71. }
  72. }
  73. }
  74. }
  75. //console.log(num);
  76. //console.log(state);
  77. console.log(stats);
  78. setTimeout(processor, maxReq * 300 + 5000); //takes 35 seconds with maxReq = 100 to display facts
  79.  
  80.  
  81.  
  82. // Your code here...
  83. })();