36 lines
942 B
JavaScript
36 lines
942 B
JavaScript
function pipSupported() {
|
|
return window.documentPictureInPicture && document.pictureInPictureEnabled;
|
|
}
|
|
|
|
function pipEnabled() {
|
|
return pipSupported() && localStorage.getItem("pip-enabled") != 0;
|
|
}
|
|
|
|
function setPipEnabled(enabled) {
|
|
localStorage.setItem("pip-enabled", +enabled);
|
|
}
|
|
|
|
function openPipWindow(link, w, h) {
|
|
return new Promise(function(resolve) {
|
|
window.documentPictureInPicture.requestWindow({ width: w, height: h }).then(function(win) {
|
|
var iframe = document.createElement("iframe");
|
|
iframe.src = link;
|
|
iframe.style.width = w + "px";
|
|
iframe.style.height = h + "px";
|
|
iframe.style.border = "none";
|
|
|
|
win.document.body.style.margin = "0";
|
|
win.document.body.style.overflow = "hidden";
|
|
|
|
win.document.body.appendChild(iframe);
|
|
|
|
win.onpagehide = resolve;
|
|
win.onresize = function() {
|
|
iframe.style.width = win.innerWidth + "px";
|
|
iframe.style.height = win.innerHeight + "px";
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|