TP Maptest U-M button

Adds a button to the tagpro-test map test page to test a map from a U-M ID.

  1. // ==UserScript==
  2. // @name TP Maptest U-M button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Adds a button to the tagpro-test map test page to test a map from a U-M ID.
  6. // @author E. Lek-Tro
  7. // @match http://tagpro-maptest.koalabeast.com/testmap
  8. // @match http://tagpro-maptest.koalabeast.com/
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. $(".form").parent().append("<button id='umIDBtn' class='btn btn-primary'>U-M ID</button>")
  15.  
  16. $("#umIDBtn").click(e => {
  17. changeMapFromID(prompt("Map ID:")).then(() => {
  18. $(".form .form-group:last-child button[type='submit']").click();
  19. });
  20. });
  21.  
  22. $("#play-now").attr("href", "http://tagpro-maptest.koalabeast.com/testmap");
  23.  
  24. function changeMapFromID(id){
  25. return new Promise(async (resolve, reject) => {
  26. console.log("id:", id);
  27. if(isNaN(Number(id)) || id === "") id = Math.floor(Math.random() * 60000);
  28. let pngBlob = await fetch(`https://parretlabs.xyz:8006/proxy?isBlob=1&type=image/png&link=http://unfortunate-maps.jukejuice.com/static/maps/${id}.png`)
  29. .then(res => res.blob());
  30. let jsonBlob = await fetch(`https://parretlabs.xyz:8006/proxy?type=application/json&link=http://unfortunate-maps.jukejuice.com/static/maps/${id}.json`)
  31. .then(res => res.blob());
  32.  
  33. const pngTransfer = new ClipboardEvent('').clipboardData || new DataTransfer();
  34. const jsonTransfer = new ClipboardEvent('').clipboardData || new DataTransfer();
  35. pngTransfer.items.add(new File([pngBlob], 'map.png', {type: "image/png"}));
  36. jsonTransfer.items.add(new File([jsonBlob], 'map.json', {type: "application/json"}));
  37.  
  38. document.querySelector("input[name='layout']").files = pngTransfer.files;
  39. document.querySelector("input[name='logic']").files = jsonTransfer.files;
  40.  
  41. console.log(pngBlob, jsonBlob)
  42.  
  43. setTimeout(function(){
  44. resolve();
  45. }, 100);
  46. });
  47. }
  48.  
  49. // Your code here...
  50. })();