Skip to content

Commit e27acad

Browse files
authored
Merge pull request #825 from Masaabu/project-miniplayer
Add feature "project-miniplayer"
2 parents a35b2e7 + d25bf99 commit e27acad

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

features/features.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "project-miniplayer",
5+
"versionAdded": "v3.8.0"
6+
},
27
{
38
"version": 2,
49
"id": "project-descriptions",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"title": "Project Miniplayer",
3+
"description": "Scroll down on the project page and you will automatically see the project miniplayer.",
4+
"credits": [
5+
{ "username": "Masaabu-YT", "url": "https://scratch.mit.edu/users/Masaabu-YT/" }
6+
],
7+
"type": ["Website"],
8+
"tags": ["New", "Featured"],
9+
"dynamic": true,
10+
"options": [
11+
{ "id": "position-right", "name": "Place the player to the right.", "type": 1 },
12+
{ "id": "position-bottom", "name": "Place the player to the bottom.", "type": 1 },
13+
{ "id": "opacity", "name": "Player Transparency (0% - 90%)", "type": 2 }
14+
],
15+
"scripts": [{ "file": "script.js", "runOn": "/projects/*" }],
16+
"styles": [{ "file": "style.css", "runOn": "/projects/*" }]
17+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
export default async function ({ feature, console }) {
2+
const miniplayerElement = document.createElement('div');
3+
miniplayerElement.className = 'ste-project-miniplayer';
4+
document.body.appendChild(miniplayerElement);
5+
await ScratchTools.waitForElement("div.guiPlayer")
6+
const guiPlayer = document.getElementsByClassName("guiPlayer")[0]
7+
const projectHeader = document.querySelector('.description-block');
8+
const title = projectHeader.closest('.flex-row.project-notes');
9+
10+
function updateSetting (key, value) {
11+
switch (key) {
12+
case 'position-right':{
13+
if (value===true) {
14+
miniplayerElement.style.right = '0'
15+
miniplayerElement.style.left = ''
16+
} else {
17+
miniplayerElement.style.right = ''
18+
miniplayerElement.style.left = '0'
19+
}
20+
break;
21+
}
22+
case 'position-bottom':{
23+
if (value===true) {
24+
miniplayerElement.style.bottom = '0'
25+
miniplayerElement.style.top = ''
26+
} else {
27+
miniplayerElement.style.bottom = ''
28+
miniplayerElement.style.top = '0'
29+
}
30+
break;
31+
}
32+
case 'opacity': {
33+
if (!value) {
34+
miniplayerElement.style.opacity = 1
35+
} else if (value<=90) {
36+
miniplayerElement.style.opacity = 1-value/100
37+
} else {
38+
miniplayerElement.style.opacity = 0.1
39+
}
40+
break;
41+
}
42+
43+
default:
44+
break;
45+
}
46+
}
47+
48+
updateSetting('position-right', await feature.settings.get("position-right"));
49+
updateSetting('position-bottom', await feature.settings.get("position-bottom"));
50+
updateSetting('opacity', await feature.settings.get("opacity"));
51+
52+
window.addEventListener('scroll', () => {
53+
if (window.scrollY > 700) {
54+
miniplayerElement.style.display = 'block';
55+
miniplayerElement.appendChild(guiPlayer);
56+
} else {
57+
miniplayerElement.style.display = 'none';
58+
title.insertAdjacentElement('beforebegin', guiPlayer);
59+
60+
}
61+
});
62+
63+
feature.settings.addEventListener("changed", function({ key, value }) {
64+
updateSetting(key, value)
65+
})
66+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.ste-project-miniplayer {
2+
position: fixed;
3+
z-index: 100;
4+
background-color: #000000aa;
5+
padding: 5px;
6+
border-radius: 10px;
7+
max-width: 485px;
8+
display: none;
9+
}

0 commit comments

Comments
 (0)