ryukra / Roll20BackgroundMOD

// ==UserScript==
// @name Roll20BackgroundMOD
// @namespace rukasoft
// @version 0.1
// @description Adds support for images made in extern graphictools
// @match https://app.roll20.net/editor/
// @copyright ruka
// @run-at document-end
// @require https://code.jquery.com/jquery-3.3.1.min.js
// @grant GM.xmlHttpRequest
// @license MIT
// ==/UserScript==


var lastmod = "XX";
var t=setInterval(mapModified,4000);

function mapModified(){
    var d = new Date();
    GM.xmlHttpRequest({
        method: "GET",
        url: 'http://88.66.37.211:8080/map.png?ver='+d.getTime(),
        onload: function(response) {
            var headers = response.responseHeaders;
            var regex = /last-modified:.*/gm;
            var result = headers.match(regex);
            var r = new RegExp(result, "i");
            if(!r.test(lastmod)){
                refresh();
            }
            lastmod = result;

        }
    });
}

jQuery("#zoomslider").css("opacity",0);

function refresh(){
    var d = new Date();
    jQuery("#editor").html('<img src="http://88.66.37.211:8080/map.png?ver='+d.getTime()+'">');
}