Arbybear

TagPro /testmap Enhancer

Jul 15th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro /testmap Enhancer
  3. // @version 0.1.1
  4. // @description Make the /testmap page a little easier to use by adding drag-and-drop functionality
  5. // @author Some Ball -1
  6. // @include http://tagpro-maptest.koalabeast.com/testmap
  7. // @include http://*.newcompte.fr/testmap
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. $('input').css('display','none').wrap('<div class="wrapped" style="border: 1px solid gray"><a class="fileHandler" style="vertical-align: middle; width: 100%; height: 100px; cursor: pointer; color: inherit"><pre style="width: 100%; height: 100%; margin: 0px; font: inherit; text-align: center; line-height: 50px; /*-webkit-text-stroke: 1px black;*/ font-size: 20px; color: inherit;">No File Chosen\nDrag and drop a file into this area or click to browse for files</pre></a></div>');
  12. $('.fileHandler').on('click',function(event) {
  13. this.children[0].children[0].click();
  14. });
  15. $('.fileHandler').on('dragenter',function(event) {
  16. event.stopPropagation();
  17. event.preventDefault();
  18. });
  19. $('.fileHandler').on('dragover',function(event) {
  20. event.stopPropagation();
  21. event.preventDefault();
  22. });
  23. $('.fileHandler').on('drop',function(event) {
  24. event.stopPropagation();
  25. event.preventDefault();
  26.  
  27. var files = event.originalEvent.dataTransfer.files;
  28. var childinput = this.children[0].children[0];
  29. var $parent = $(this.parentNode);
  30. if(childinput.name==='layout')
  31. {
  32. if(files[0].type==='image/png')
  33. {
  34. $parent.css({backgroundColor: 'darkgreen',color: 'white'});
  35. this.children[0].childNodes[0].nodeValue = files[0].name+'\nDrag and drop or click to change files or click below to test the map';
  36. childinput.files = files;
  37. }
  38. else
  39. {
  40. $parent.css({background: 'none',color: 'red'});
  41. this.children[0].childNodes[0].nodeValue = 'Improper file type\nOnly .png files are an acceptable layout file input';
  42. }
  43. }
  44. else if(childinput.name==='logic')
  45. {
  46. if(files[0].type==='application/json')
  47. {
  48. $parent.css({backgroundColor: 'darkgreen',color: 'white'});
  49. this.children[0].childNodes[0].nodeValue = files[0].name+'\nDrag and drop or click to change files or click below to test the map';
  50. childinput.files = files;
  51. }
  52. else
  53. {
  54. $parent.css({background: 'none',color: 'red'});
  55. this.children[0].childNodes[0].nodeValue = 'Improper file type\nOnly .json files are an acceptable logic file input';
  56. }
  57. }
  58. });
Advertisement
Add Comment
Please, Sign In to add comment