Skip to content

Instantly share code, notes, and snippets.

@mashiro
Last active October 12, 2018 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mashiro/2cd6a30353b27326630b93768136fe62 to your computer and use it in GitHub Desktop.
Save mashiro/2cd6a30353b27326630b93768136fe62 to your computer and use it in GitHub Desktop.
(() => {
const togglePIP = (video) => {
if (!video.webkitSetPresentationMode) {
alert("This browser is not support PIP mode.");
return;
}
video.webkitSetPresentationMode(video.webkitPresentationMode === "picture-in-picture" ? "inline" : "picture-in-picture");
};
const video = document.querySelector("video");
const ul = document.querySelector("ul[class$=Share]");
const li = document.createElement("li");
const button = document.createElement("button");
button.type = "button";
button.style.width = "31px";
button.style.height = "31px";
button.style.backgroundColor = "#888";
button.style.borderRadius = "100%";
button.textContent = "P";
button.addEventListener("click", (e) => togglePIP(video));
li.appendChild(button);
ul.insertBefore(li, ul.firstChild);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment