Map Updator

Update Map

当前为 2017-02-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Map Updator
  3. // @namespace http://api.micetigri.fr/
  4. // @version 0.9
  5. // @description Update Map
  6. // @author Billysmille
  7. // @match http://api.micetigri.fr/maps/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function updateAll(list) {
  12. var lsmap = [];
  13. var i = 0;
  14. var pattern = new RegExp('@\\d+', 'g');
  15. var match;
  16. while ((match = pattern.exec(list))) {
  17. lsmap.push(match[0]);
  18. }
  19. window.setInterval(function () {
  20. if (i < lsmap.length) {
  21. var xmlhttp = new XMLHttpRequest();
  22. xmlhttp.onreadystatechange = function () {
  23. if (this.readyState == 4 && this.status == 200) {
  24. var parser = new DOMParser();
  25. var xmlDoc = parser.parseFromString(this.responseText, 'text/html');
  26. io.connect('http://node.micetigri.fr:443/').emit('map', {
  27. map: xmlDoc.getElementById('mapUpdator').getAttribute('map'),
  28. id: xmlDoc.getElementById('mapUpdator').getAttribute('session')
  29. });
  30. }
  31. };
  32. xmlhttp.open('GET', 'http://api.micetigri.fr/maps/' + lsmap[i], true);
  33. xmlhttp.send();
  34. i++;
  35. }
  36. else {
  37. location.reload();
  38. }
  39. $('.panel-heading').next('.panel-body').html('Updating ' + i + ' of ' + lsmap.length);
  40. }, 6000);
  41. }
  42.  
  43. (function () {
  44. $('title').html('Map Updator');
  45. $('.panel-title').html('<strong>Up to date</strong>');
  46. $('.panel-heading').next('.panel-body').html('-');
  47. $('#MapViewer').parents('.panel-body').html('<textarea class="form-control" id="map-list" rows="5"></textarea>');
  48. $('#mapUpdator').parents('.panel-body').html('<button type="submit" class="btn btn-default" id="update-button" data-loading-text="Update All...">Update All</button>');
  49. $('#copy_this_text').parents('.row').remove();
  50. $('#update-button').click(function (event) {
  51. event.preventDefault();
  52. $(this).button('loading');
  53. updateAll($('#map-list').val());
  54. });
  55. })();