Skip to content

Commit e47dabf

Browse files
authored
Merge pull request #603 from rgantzos/main
2 parents 90ad0fa + 1124cd0 commit e47dabf

File tree

4 files changed

+88
-73
lines changed

4 files changed

+88
-73
lines changed

extras/feedback/page.js

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,67 @@
11
document.querySelectorAll("body > *").forEach(function (el) {
2-
el.remove();
3-
});
4-
document.body.style.backgroundColor = "white";
5-
document.body.style.textAlign = "center";
6-
document.body.style.padding = "3rem";
7-
var h1 = document.createElement("h1");
8-
h1.textContent = "ScratchTools Authentication";
9-
document.body.appendChild(h1);
10-
h1.style.fontFamily = "Inter";
11-
h1.style.color = "#ff9f00";
12-
var style = document.createElement("style");
13-
style.textContent =
14-
'@import url("https://fonts.googleapis.com/css2?family=Inter&display=swap");';
15-
document.body.appendChild(style);
16-
var p = document.createElement("p");
17-
p.textContent = "Thank you for your patience while we authorize you.";
18-
p.style.color = "black";
19-
p.style.opacity = ".5";
20-
p.style.fontSize = "1rem";
21-
document.body.appendChild(p);
22-
23-
var verifyUser = async function (callback) {
24-
var code = await (
25-
await fetch(`https://data.scratchtools.app/verification/code/`)
2+
el.remove();
3+
});
4+
document.body.style.backgroundColor = "white";
5+
document.body.style.textAlign = "center";
6+
document.body.style.padding = "3rem";
7+
var h1 = document.createElement("h1");
8+
h1.textContent = "ScratchTools Authentication";
9+
document.body.appendChild(h1);
10+
h1.style.fontFamily = "Inter";
11+
h1.style.color = "#ff9f00";
12+
var style = document.createElement("style");
13+
style.textContent =
14+
'@import url("https://fonts.googleapis.com/css2?family=Inter&display=swap");';
15+
document.body.appendChild(style);
16+
var p = document.createElement("p");
17+
p.textContent = "Thank you for your patience while we authorize you.";
18+
p.style.color = "black";
19+
p.style.opacity = ".5";
20+
p.style.fontSize = "1rem";
21+
document.body.appendChild(p);
22+
23+
var verifyUser = async function (callback) {
24+
var code = await (
25+
await fetch(`https://data.scratchtools.app/verification/code/`)
26+
).json();
27+
var PROJECT_ID = "854593681";
28+
var user = Scratch.INIT_DATA.LOGGED_IN_USER.model.username;
29+
var connection = new WebSocket("wss://clouddata.scratch.mit.edu");
30+
connection.onerror = console.error;
31+
connection.onopen = async () => {
32+
connection.send(
33+
JSON.stringify({ method: "handshake", project_id: PROJECT_ID, user }) +
34+
"\n"
35+
);
36+
await new Promise((r) => setTimeout(r, 100));
37+
connection.send(
38+
JSON.stringify({
39+
value: code.code.toString(),
40+
name: "☁ verify",
41+
method: "set",
42+
project_id: PROJECT_ID,
43+
user,
44+
}) + "\n"
45+
);
46+
connection.close();
47+
var data = await (
48+
await fetch("https://data.scratchtools.app/verify/", {
49+
method: "POST",
50+
headers: {
51+
Accept: "application/json",
52+
"Content-Type": "application/json",
53+
},
54+
body: JSON.stringify({ secret: code.secret }),
55+
})
2656
).json();
27-
var PROJECT_ID = "854593681";
28-
var user = Scratch.INIT_DATA.LOGGED_IN_USER.model.username;
29-
var connection = new WebSocket("wss://clouddata.scratch.mit.edu");
30-
connection.onerror = console.error;
31-
connection.onopen = async () => {
32-
connection.send(
33-
JSON.stringify({ method: "handshake", project_id: PROJECT_ID, user }) +
34-
"\n"
35-
);
36-
await new Promise((r) => setTimeout(r, 100));
37-
connection.send(
38-
JSON.stringify({
39-
value: code.code.toString(),
40-
name: "☁ verify",
41-
method: "set",
42-
project_id: PROJECT_ID,
43-
user,
44-
}) + "\n"
45-
);
46-
connection.close();
47-
var data = await (
48-
await fetch("https://data.scratchtools.app/verify/", {
49-
method: "POST",
50-
headers: {
51-
Accept: "application/json",
52-
"Content-Type": "application/json",
53-
},
54-
body: JSON.stringify({ secret: code.secret }),
55-
})
56-
).json();
57-
callback(data.code);
58-
};
57+
callback(data.code);
5958
};
60-
59+
};
60+
61+
if (Scratch?.INIT_DATA?.LOGGED_IN_USER?.model?.username) {
6162
verifyUser(function (code) {
62-
chrome.runtime.sendMessage(steSupportId, { msg: "openFeedbackPage", code });
63+
chrome.runtime.sendMessage(steSupportId, { msg: "openFeedbackPage", code });
6364
});
64-
65+
} else {
66+
window.location.href = "/login/";
67+
}

extras/index.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@
2323
<hr style="border: none; height: 1.5rem" />
2424
<div class="sectionwrap">
2525
<div class="news">
26-
<div class="note blue">
27-
<h3>ScratchTools is Going Multilingual!</h3>
28-
<span
29-
>ScratchTools is becoming available in even more languages! Our
30-
beta version supports Polish and Russian, and more languages such
31-
as Spanish, Turkish, German and Japanese are coming soon! If you
32-
know a language other than English, you can help translate and get
33-
credit for it
34-
<a href="https://explore.transifex.com/scratchtools/scratchtools/"
35-
>here</a
36-
>!</span
37-
>
38-
</div>
3926
</div>
4027
<br />
4128
<div class="note purple blocked" style="display: none">

extras/popup/popup.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,4 +1044,21 @@ async function parseFile(file) {
10441044
function importSettingsInput() {
10451045
var input = document.querySelector(".settings-load-input")
10461046
input.click()
1047+
}
1048+
1049+
if (document.querySelector(".news")) {
1050+
getNews()
1051+
}
1052+
1053+
async function getNews() {
1054+
var data = await (await fetch("https://data.scratchtools.app/news/")).json()
1055+
var note = document.createElement("div")
1056+
note.className = "note blue"
1057+
var h3 = document.createElement("h3")
1058+
h3.textContent = data.title
1059+
var span = document.createElement("span")
1060+
span.innerHTML = data.description
1061+
note.appendChild(h3)
1062+
note.appendChild(span)
1063+
document.querySelector(".news").appendChild(note)
10471064
}

extras/support/page.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,13 @@ var verifyUser = async function (callback) {
5959
};
6060

6161
verifyUser(function (code) {
62-
chrome.runtime.sendMessage(steSupportId, { msg: "openSupportChat", code });
62+
chrome.runtime.sendMessage(steSupportId, { msg: "openSupportChat", code });
6363
});
64+
65+
if (Scratch?.INIT_DATA?.LOGGED_IN_USER?.model?.username) {
66+
verifyUser(function (code) {
67+
chrome.runtime.sendMessage(steSupportId, { msg: "openFeedbackPage", code });
68+
});
69+
} else {
70+
window.location.href = "/login/";
71+
}

0 commit comments

Comments
 (0)