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 7 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")
}
}
}
5 changes: 2 additions & 3 deletions features/video-recorder/data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Video Recorder",
"description": "Record videos of Scratch projects.",
"title": "Record Stage",
"description": "Allows you to record the stage for projects while in the editor or on the project page.",
"credits": [
{
"username": "blob2763",
Expand All @@ -13,7 +13,6 @@
],
"type": ["Editor"],
"tags": ["New", "Featured"],
"dynamic": true,
"scripts": [
{
"file": "video-recorder.js",
Expand Down
1 change: 1 addition & 0 deletions features/video-recorder/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
.STE-ReactModalPortal .video-format-select {
width: 100%;
}

1 change: 1 addition & 0 deletions features/video-recorder/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default async function ({ feature, console }) {
if (row.querySelector(".ste-video-recorder-open")) return;
openPopup = document.createElement("div");
openPopup.className = "menu-bar_menu-bar-item_oLDa- menu-bar_hoverable_c6WFB";
openPopup.style.padding = "0 0.75rem"
let rem = document.createElement("div");
rem.textContent = "Record Video";
openPopup.append(rem);
Expand Down
Loading