Map Updator

Update Map

目前為 2017-02-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Map Updator
// @namespace    api.micetigri.fr
// @version      1.6
// @description  Update Map
// @author       Billysmille
// @match        http://api.micetigri.fr/maps
// @grant        none
// ==/UserScript==

(function () {
    function updateAll(list) {
        var lsmap = list.match(/@\d+/g);
        var i = 0;
        var loop = function () {
            if (lsmap && i < lsmap.length) {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                        var parser = new DOMParser();
                        var xmlDoc = parser.parseFromString(this.responseText, 'text/html');
                        io.connect('http://node.micetigri.fr:443/').emit('map', {
                            map: xmlDoc.getElementById('mapUpdator').getAttribute('map'),
                            id: xmlDoc.getElementById('mapUpdator').getAttribute('session')
                        });
                        window.setTimeout(loop, 10000);
                    }
                };
                xmlhttp.open('GET', 'http://api.micetigri.fr/maps/' + lsmap[i], true);
                xmlhttp.send();
                $('.panel-heading').next('.panel-body').html(i + ' of ' + lsmap.length);
                i++;
            }
            else {
                location.reload();
            }
        };
        loop();
    }
    $('title').html('Map Updator');
    $('.panel-title').html('<strong>Up to date</strong>');
    $('.panel-heading').next('.panel-body').html('-');
    $('#MapViewer').parents('.panel-body').html('<textarea class="form-control" id="map-list" rows="5"></textarea>');
    $('#mapUpdator').parents('.panel-body').html('<button type="submit" class="btn btn-default" id="update-button" data-loading-text="Update All...">Update All</button>');
    $('#copy_this_text').parents('.row').remove();
    $('#update-button').click(function (event) {
        event.preventDefault();
        $(this).button('loading');
        updateAll($('#map-list').val());
    });
})();