(function () { var WAIT_MS = 8000; // durata avviso e blocco dei click ripetuti (alza se serve) var busy = false; function isDownload(url) { return /\/slingshot\/node\/content\//.test(url) && /[?&]a=true/.test(url); } function banner(msg) { var el = document.getElementById("dl-banner"); if (!el) { el = document.createElement("div"); el.id = "dl-banner"; el.style.cssText = "position:fixed;top:12px;left:50%;transform:translateX(-50%);" + "background:#333;color:#fff;padding:10px 20px;border-radius:4px;" + "font:14px sans-serif;z-index:100000;box-shadow:0 2px 8px rgba(0,0,0,.4)"; document.body.appendChild(el); } el.textContent = msg; el.style.display = "block"; } function startDownload(url) { if (busy) { return; } busy = true; document.body.style.cursor = "progress"; banner("Downloading ... attendere"); var a = document.createElement("a"); a.href = url; a.style.display = "none"; document.body.appendChild(a); a.click(); document.body.removeChild(a); setTimeout(function () { busy = false; document.body.style.cursor = ""; var el = document.getElementById("dl-banner"); if (el) { el.style.display = "none"; } }, WAIT_MS); } var origOpen = XMLHttpRequest.prototype.open; var origSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.open = function (method, url) { this.__dlUrl = (String(method).toUpperCase() === "GET" && isDownload(String(url))) ? String(url) : null; return origOpen.apply(this, arguments); }; XMLHttpRequest.prototype.send = function () { if (this.__dlUrl) { startDownload(this.__dlUrl); return; } return origSend.apply(this, arguments); }; })();