Map Updator

Update Map

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

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