forked from ScratchAddons/ScratchAddons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserscript.js
More file actions
107 lines (101 loc) · 3.6 KB
/
Copy pathuserscript.js
File metadata and controls
107 lines (101 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
let dangorain = false,
dangoContainerLeft,
dangoContainerRight,
visibleDangos,
noticeTimeout;
const div = () => document.createElement("div");
const noticeText = div();
noticeText.className = "sa-dango-notice";
const checkForDango = (text) => {
if (!text.toLowerCase().includes("dango")) {
if (dangorain && dangoContainerLeft) {
dangoContainerLeft?.remove();
dangoContainerRight?.remove();
noticeText?.remove();
}
dangorain = false;
return;
}
if (dangorain) return;
dangorain = true;
dangoContainerLeft = div();
dangoContainerLeft.className = "sa-dangos-left";
for (let i = 0; i < 20; i++) {
const dango = div();
dango.className = "sa-dango";
dango.style.left = (i % 10) * 10 + "%";
dango.style.animationDelay = `${Math.random() * 8}s, ${Math.random() * 8}s`;
dangoContainerLeft.append(dango);
}
setEltWidth(dangoContainerLeft);
dangoContainerRight = dangoContainerLeft.cloneNode(true);
dangoContainerRight.className = "sa-dangos-right";
document.querySelector("#content").append(dangoContainerLeft, dangoContainerRight);
// if (!localStorage.getItem("scratchAddonsAprilFoolsModal2021")) document.querySelector("#content").append(noticeText);
};
const setEltWidth = (elt) => {
if (!elt) return;
let sideWidth = (document.body.clientWidth - document.querySelector("#profile-data").clientWidth) / 2;
sideWidth = sideWidth - 25;
elt.style.width = sideWidth + "px";
visibleDangos = sideWidth > 0;
if (visibleDangos) {
clearTimeout(noticeTimeout);
/* if (!old && !localStorage.getItem("scratchAddonsAprilFoolsModal2021")) {
document.querySelector("#content").append(noticeText);
} */
} else {
// Window resizing is very weird on some devices...
// Some devices might make the notice text "flicker".
clearTimeout(noticeTimeout);
noticeTimeout = setTimeout(() => {
noticeText?.remove();
}, 1000);
}
};
addEventListener("resize", () => {
setEltWidth(dangoContainerLeft);
setEltWidth(dangoContainerRight);
});
export default async function ({ addon, console, msg }) {
const notifClose = Object.assign(document.createElement("span"), {
style: `
float: right;
cursor:pointer;
background-color: #ffffff26;
line-height: 10px;
width: 10px;
text-align: center;
padding:5px;
border-radius: 50%;`,
textContent: "x",
});
notifClose.onclick = () => {
noticeText.style.display = "none";
localStorage.setItem("scratchAddonsAprilFoolsModal2021", "true");
};
noticeText.appendChild(notifClose);
const boldSpan = document.createElement("span");
boldSpan.innerText = ""; // msg("addedBy");
boldSpan.style.fontWeight = "bold";
noticeText.appendChild(boldSpan);
const normalSpan = document.createElement("span");
normalSpan.innerText = ""; // `\n${msg("happyAprilFools")}\n${msg("howToGet")}\n${msg("howToStop")}`;
noticeText.appendChild(normalSpan);
const getAboutMeAndWiwo = () => {
if (document.querySelector("textarea[name=bio]")) {
// Own profile
return `${document.querySelector("textarea[name=bio]").value}/${
document.querySelector("textarea[name=status]").value
}`;
} else {
const ps = document.querySelectorAll("p.overview");
return `${ps[0].textContent}/${ps[1].textContent}`;
}
};
checkForDango(getAboutMeAndWiwo());
if (document.querySelector("textarea[name=bio]")) {
document.querySelector("textarea[name=bio]").addEventListener("input", () => checkForDango(getAboutMeAndWiwo()));
document.querySelector("textarea[name=status]").addEventListener("input", () => checkForDango(getAboutMeAndWiwo()));
}
}