Tagpro map stats

Tagpro map stats duh

  1. // ==UserScript==
  2. // @name Tagpro map stats
  3. // @namespace https://tagpro.koalabeast.com/
  4. // @version 0.4
  5. // @description Tagpro map stats duh
  6. // @author You
  7. // @match https://tagpro.koalabeast.com/game
  8. // @icon https://www.google.com/s2/favicons?domain=koalabeast.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function waitForMapname () {
  16. var waitForLoaded = new MutationObserver(function (mutations) {
  17. var elem = document.querySelector('#mapInfo');
  18. if (elem && elem.textContent) {
  19. waitForLoaded.disconnect();
  20. var mapname = elem.textContent.match(/Map:\s(.+)\sby/)[1];
  21. getMapStat(mapname);
  22. }
  23. });
  24. var config = {attributes: true, childList: true, subtree: true};
  25. waitForLoaded.observe(document.body, config)
  26. }
  27.  
  28. function ucfirst(string) {
  29. return string.charAt(0).toUpperCase() + string.slice(1);
  30. }
  31.  
  32. function getMapStat(mapname){
  33. var xhttp = new XMLHttpRequest();
  34. xhttp.onreadystatechange = function() {
  35. if (this.readyState == 4 && this.status == 200) {
  36. var allmaps = JSON.parse(xhttp.responseText);
  37. var i, maptype;
  38. for(maptype in allmaps){
  39. var maps = allmaps[maptype];
  40. for(i in maps){
  41. var map = maps[i];
  42. if(map.name == mapname){
  43. var msg = mapname + " (" + ucfirst(maptype) + " map) / rating: " + map.averageRating + "% / total plays: " + map.totalPlays;
  44. // + (i + 1) + ". place in rotation";
  45. console.log(msg);
  46. setTimeout(function(){
  47. tagpro.socket.emit("chat", {
  48. message: msg,
  49. toAll: 1,
  50. });
  51. }, 8000);
  52. return;
  53. }
  54. }
  55. }
  56.  
  57. }
  58. };
  59. xhttp.open("GET", "https://tagpro.koalabeast.com/maps.json", true);
  60. xhttp.send();
  61. }
  62.  
  63. waitForMapname();
  64.  
  65. })();