Skip to content

Commit a35b2e7

Browse files
authored
Merge pull request #824 from rgantzos/main
Summarized Descriptions
2 parents 87c8cf0 + 049fb57 commit a35b2e7

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-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-descriptions",
5+
"versionAdded": "v3.8.0"
6+
},
27
{
38
"version": 2,
49
"id": "pin-comments",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"title": "Summarized Descriptions",
3+
"description": "Uses artificial intelligence to summarize project descriptions when you choose to, and shortens long descriptions down to important information, such as gameplay instructions.",
4+
"credits": [
5+
{
6+
"username": "rgantzos",
7+
"url": "https://scratch.mit.edu/users/rgantzos/"
8+
}
9+
],
10+
"dynamic": true,
11+
"styles": [{ "file": "style.css", "runOn": "/projects/*" }],
12+
"scripts": [
13+
{ "file": "script.js", "runOn": "/projects/*" }
14+
],
15+
"tags": ["New"],
16+
"type": ["Website"],
17+
"resources": [{ "name": "ai-star", "path": "/star.svg" }]
18+
}
19+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export default async function ({ feature, console }) {
2+
ScratchTools.waitForElements(".flex-row.project-notes", function(notes) {
3+
if (notes.querySelector(".project-textlabel")) {
4+
let description = notes.querySelector(".project-description")
5+
6+
if (description.textContent.replaceAll(" ", "")) {
7+
let label = notes.querySelector(".project-textlabel")
8+
9+
let img = document.createElement("img")
10+
img.src = feature.self.getResource("ai-star")
11+
img.className = "ai-star"
12+
label.appendChild(img)
13+
14+
img.addEventListener("click", async function() {
15+
img.remove()
16+
notes.innerHTML = ""
17+
18+
let div = document.createElement("div")
19+
div.className = "description-block ai-description"
20+
21+
let inner = document.createElement("div")
22+
inner.className = "project-description"
23+
inner.textContent = "Loading summarization..."
24+
div.appendChild(inner)
25+
notes.appendChild(div)
26+
27+
let data = await (await fetch(`https://data.scratchtools.app/description/${window.location.pathname.split("/")[2]}/`)).json()
28+
inner.textContent = data.response
29+
30+
let p = document.createElement("p")
31+
p.textContent = "AI description provided by ScratchTools."
32+
div.appendChild(p)
33+
})
34+
}
35+
}
36+
})
37+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.ai-star {
2+
height: 1.4rem;
3+
position: relative;
4+
top: .4rem;
5+
margin-left: .3rem;
6+
cursor: pointer;
7+
transform: none;
8+
transition: transform .3s;
9+
}
10+
11+
.ai-star:hover {
12+
transform: scale(1.1);
13+
}
14+
15+
.ai-description div {
16+
background-color: rgb(112 0 255 / 20%) !important;
17+
flex: none !important;
18+
height: fit-content;
19+
font-weight: 500;
20+
color: rgb(82, 35, 118);
21+
}
22+
23+
.ai-description p {
24+
margin: 0px;
25+
font-size: .8rem;
26+
font-weight: 500;
27+
width: 100%;
28+
text-align: right;
29+
margin-top: .2rem;
30+
opacity: .6;
31+
}

0 commit comments

Comments
 (0)