-
Notifications
You must be signed in to change notification settings - Fork 0
/
frameover.js
33 lines (33 loc) · 1.35 KB
/
frameover.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module.exports = {
"create": (backgroundColor) => {
return new Promise((resolve) => {
let frame = document.createElement("iframe");
frame.style.zIndex = 1000;
frame.style.position = "absolute";
frame.style.border = 0;
frame.style.width = frame.style.height = "100%";
frame.srcdoc = `<html><head></head><body style="background-color: ${backgroundColor}"></body></html>`;
frame.onload = () => {
let frameDestroyed = false;
resolve({
"document": frame.contentDocument,
"window": frame.contentWindow,
"destroy": () => {
if (frameDestroyed) return;
frameDestroyed = true;
document.body.removeChild(frame);
},
"pause": () => {
if (frameDestroyed) throw new Error("Frame already destroyed");
frame.style.display = "none";
},
"resume": () => {
if (frameDestroyed) throw new Error("Frame already destroyed");
frame.style.display = "inherit";
}
})
};
document.body.prepend(frame);
});
}
}