Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picture in Picture #936

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/features.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"version": 2,
"id": "video-recorder",
"id": "picture-in-picture",
"versionAdded": "v4.0.0"
},
{
Expand Down
23 changes: 23 additions & 0 deletions features/picture-in-picture/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"title": "Picture in Picture",
"description": "Adds a button to the project page that allows you to open the stage up and continue to view it while using other tabs or apps.",
"credits": [
{
"username": "stio_studio",
"url": "https://stio.studio/"
}
],
"type": ["Website"],
"tags": ["New", "Featured"],
"dynamic": true,
"scripts": [
{
"file": "picture-in-picture.js",
"runOn": "/projects/*"
}
],
"components": [{
"type": "info",
"content": "Picture in Picture will not allow you to interact with the project. You must be on the project page to interact with it."
}]
}
56 changes: 56 additions & 0 deletions features/picture-in-picture/picture-in-picture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export default async function ({ feature, console }) {
const canvas = feature.traps.vm.renderer.canvas;

let video = document.createElement("video");
// video.setAttribute("controls", "controls");
video.setAttribute("autoplay", "autoplay");
video.setAttribute("style", "width: 100%; height: 100%");
// document.querySelector(".preview .inner").append(video);

video.srcObject = canvas.captureStream(30)

await new Promise(async (resolve, reject) => {
(async () => {
const rem = await ScratchTools.waitForElement(".preview .inner .flex-row.action-buttons")
resolve(rem);
})();
(async () => {
const rem = await ScratchTools.waitForElement(".menu-bar_account-info-group_MeJZP")
resolve(rem);
})();
})

let openPopup = document.createElement("button");

ScratchTools.waitForElements(".preview .inner .flex-row.action-buttons", async function (row) {
if (row.querySelector(".ste-picture-in-picture")) return;
openPopup = document.createElement("button");
openPopup.className = "button action-button ste-picture-in-picture";
openPopup.textContent = "Picture in Picture";
row.insertAdjacentElement("afterbegin", openPopup);
openPopup.addEventListener('click', () => {
popup()
})
})
ScratchTools.waitForElements(".menu-bar_account-info-group_MeJZP", async function (row) {
if (row.querySelector(".ste-picture-in-picture")) return;
openPopup = document.createElement("div");
openPopup.className = "menu-bar_menu-bar-item_oLDa- menu-bar_hoverable_c6WFB";
let rem = document.createElement("div");
rem.textContent = "Picture in Picture";
openPopup.append(rem);
row.insertAdjacentElement("afterbegin", openPopup);
openPopup.addEventListener('click', () => {
popup()
})
})

function popup() {
try {
video.requestPictureInPicture()
}
catch {
console.log("Picture in Picture not supported or failed to request")
}
}
}
35 changes: 0 additions & 35 deletions features/video-recorder/data.json

This file was deleted.

50 changes: 0 additions & 50 deletions features/video-recorder/popup.html

This file was deleted.

21 changes: 0 additions & 21 deletions features/video-recorder/style.css

This file was deleted.

179 changes: 0 additions & 179 deletions features/video-recorder/video-recorder.js

This file was deleted.