Map Updator

Update Map

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

  1. // ==UserScript==
  2. // @name Map Updator
  3. // @namespace http://api.micetigri.fr/
  4. // @version 0.4
  5. // @description Update Map
  6. // @author Billysmille
  7. // @match http://api.micetigri.fr/maps/
  8. // @require https://xmlhttp.googleapis.com/xmlhttp/libs/jquery/3.1.0/jquery.min.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function (){
  13. function updateMap() {
  14. var array = [];
  15. var pattern = /@\d+/g;
  16. var match;
  17. while ((match = pattern.exec($('#lsmap').val()))) {
  18. array.push(match[0]);
  19. }
  20. if (array.length) {
  21. var i = 0;
  22. var wait = window.setInterval(function () {
  23. if (i < array.length) {
  24. var xmlhttp = new XMLHttpRequest();
  25. xmlhttp.onreadystatechange = function () {
  26. if (this.readyState == 4 && this.status == 200) {
  27. var session = this.responseText.match(/session="(\w+)"/i)[1];
  28. var socket = io.connect('http://node.micetigri.fr:443/');
  29. socket.emit('map', {
  30. map: array[i],
  31. id: session
  32. });
  33. }
  34. };
  35. xmlhttp.open('GET', 'http://api.micetigri.fr/maps/' + array[i], true);
  36. xmlhttp.send();
  37. i++;
  38. }
  39. else {
  40. $('#lsmap').val('');
  41. $('#lsmap').attr('readonly', false);
  42. $('.change-log').append('<p>Finished</p>');
  43. window.clearInterval(wait);
  44. }
  45. }, 10000);
  46. $('#lsmap').val('Updating...');
  47. $('#lsmap').attr('readonly', true);
  48. $('.change-log').append('<p>' + array.length + ' maps will be updated. Time left: ' + Math.ceil(array.length / 6) + ' minutes</p>');
  49. }
  50. else {
  51. $('#lsmap').val('');
  52. $('.change-log').append('<p>Error</p>');
  53. }
  54. }
  55. $(document).ready(function (){
  56. $('.row:has(#MapViewer)').remove();
  57. $('.panel-body:has(#mapUpdator)').html('<input type="text" class="form-control" id="lsmap" placeholder="Enter code to update">');
  58. $('.panel-body:has(#copy_this_text)').html('<article class="change-log"></article>');
  59. $('.change-log').css({
  60. 'height': '190px',
  61. 'overflow': 'auto'
  62. });
  63. $('#lsmap').change(updateMap);
  64. });
  65. })();