2020-02-13 19:58:27 +03:00
|
|
|
function remoteRender(event) {
|
|
|
|
const data = event.data;
|
|
|
|
|
|
|
|
const img = document.createElement("img");
|
|
|
|
img.id = "img";
|
|
|
|
img.src = data.imgSrc;
|
|
|
|
img.style = data.imgStyle;
|
|
|
|
|
|
|
|
const a = document.createElement("a");
|
|
|
|
a.id = "a";
|
2020-02-24 01:14:29 +03:00
|
|
|
a.rel = "noreferrer noopener";
|
2020-02-13 19:58:27 +03:00
|
|
|
a.download = data.download;
|
|
|
|
a.style = data.style;
|
|
|
|
a.style.fontFamily = "Arial, Helvetica, Sans-Serif";
|
|
|
|
a.href = window.URL.createObjectURL(data.blob);
|
|
|
|
a.appendChild(img);
|
|
|
|
a.appendChild(document.createTextNode(data.textContent));
|
|
|
|
|
|
|
|
const body = document.body;
|
|
|
|
// Don't display scrollbars if the link takes more than one line to display.
|
|
|
|
body.style = "margin: 0px; overflow: hidden";
|
|
|
|
body.appendChild(a);
|
2020-03-03 16:23:33 +03:00
|
|
|
|
|
|
|
if (event.data.auto) {
|
|
|
|
a.click(); // try to trigger download automatically
|
|
|
|
}
|
2020-02-13 19:58:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function remoteSetTint(event) {
|
|
|
|
const data = event.data;
|
|
|
|
|
|
|
|
const img = document.getElementById("img");
|
|
|
|
img.src = data.imgSrc;
|
|
|
|
img.style = data.imgStyle;
|
|
|
|
|
|
|
|
const a = document.getElementById("a");
|
|
|
|
a.style = data.style;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onmessage = function(e) {
|
2021-02-16 21:03:12 +03:00
|
|
|
if (e.origin === window.location.origin) {
|
2020-02-13 19:58:27 +03:00
|
|
|
if (e.data.blob) remoteRender(e);
|
|
|
|
else remoteSetTint(e);
|
|
|
|
}
|
|
|
|
};
|