Skip to content

Commit

Permalink
Merge pull request #603 from rgantzos/main
Browse files Browse the repository at this point in the history
  • Loading branch information
rgantzos authored Jul 27, 2023
2 parents 90ad0fa + 1124cd0 commit e47dabf
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 73 deletions.
121 changes: 62 additions & 59 deletions extras/feedback/page.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,67 @@
document.querySelectorAll("body > *").forEach(function (el) {
el.remove();
});
document.body.style.backgroundColor = "white";
document.body.style.textAlign = "center";
document.body.style.padding = "3rem";
var h1 = document.createElement("h1");
h1.textContent = "ScratchTools Authentication";
document.body.appendChild(h1);
h1.style.fontFamily = "Inter";
h1.style.color = "#ff9f00";
var style = document.createElement("style");
style.textContent =
'@import url("https://fonts.googleapis.com/css2?family=Inter&display=swap");';
document.body.appendChild(style);
var p = document.createElement("p");
p.textContent = "Thank you for your patience while we authorize you.";
p.style.color = "black";
p.style.opacity = ".5";
p.style.fontSize = "1rem";
document.body.appendChild(p);

var verifyUser = async function (callback) {
var code = await (
await fetch(`https://data.scratchtools.app/verification/code/`)
el.remove();
});
document.body.style.backgroundColor = "white";
document.body.style.textAlign = "center";
document.body.style.padding = "3rem";
var h1 = document.createElement("h1");
h1.textContent = "ScratchTools Authentication";
document.body.appendChild(h1);
h1.style.fontFamily = "Inter";
h1.style.color = "#ff9f00";
var style = document.createElement("style");
style.textContent =
'@import url("https://fonts.googleapis.com/css2?family=Inter&display=swap");';
document.body.appendChild(style);
var p = document.createElement("p");
p.textContent = "Thank you for your patience while we authorize you.";
p.style.color = "black";
p.style.opacity = ".5";
p.style.fontSize = "1rem";
document.body.appendChild(p);

var verifyUser = async function (callback) {
var code = await (
await fetch(`https://data.scratchtools.app/verification/code/`)
).json();
var PROJECT_ID = "854593681";
var user = Scratch.INIT_DATA.LOGGED_IN_USER.model.username;
var connection = new WebSocket("wss://clouddata.scratch.mit.edu");
connection.onerror = console.error;
connection.onopen = async () => {
connection.send(
JSON.stringify({ method: "handshake", project_id: PROJECT_ID, user }) +
"\n"
);
await new Promise((r) => setTimeout(r, 100));
connection.send(
JSON.stringify({
value: code.code.toString(),
name: "☁ verify",
method: "set",
project_id: PROJECT_ID,
user,
}) + "\n"
);
connection.close();
var data = await (
await fetch("https://data.scratchtools.app/verify/", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ secret: code.secret }),
})
).json();
var PROJECT_ID = "854593681";
var user = Scratch.INIT_DATA.LOGGED_IN_USER.model.username;
var connection = new WebSocket("wss://clouddata.scratch.mit.edu");
connection.onerror = console.error;
connection.onopen = async () => {
connection.send(
JSON.stringify({ method: "handshake", project_id: PROJECT_ID, user }) +
"\n"
);
await new Promise((r) => setTimeout(r, 100));
connection.send(
JSON.stringify({
value: code.code.toString(),
name: "☁ verify",
method: "set",
project_id: PROJECT_ID,
user,
}) + "\n"
);
connection.close();
var data = await (
await fetch("https://data.scratchtools.app/verify/", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ secret: code.secret }),
})
).json();
callback(data.code);
};
callback(data.code);
};

};

if (Scratch?.INIT_DATA?.LOGGED_IN_USER?.model?.username) {
verifyUser(function (code) {
chrome.runtime.sendMessage(steSupportId, { msg: "openFeedbackPage", code });
chrome.runtime.sendMessage(steSupportId, { msg: "openFeedbackPage", code });
});

} else {
window.location.href = "/login/";
}
13 changes: 0 additions & 13 deletions extras/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@
<hr style="border: none; height: 1.5rem" />
<div class="sectionwrap">
<div class="news">
<div class="note blue">
<h3>ScratchTools is Going Multilingual!</h3>
<span
>ScratchTools is becoming available in even more languages! Our
beta version supports Polish and Russian, and more languages such
as Spanish, Turkish, German and Japanese are coming soon! If you
know a language other than English, you can help translate and get
credit for it
<a href="https://explore.transifex.com/scratchtools/scratchtools/"
>here</a
>!</span
>
</div>
</div>
<br />
<div class="note purple blocked" style="display: none">
Expand Down
17 changes: 17 additions & 0 deletions extras/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,4 +1044,21 @@ async function parseFile(file) {
function importSettingsInput() {
var input = document.querySelector(".settings-load-input")
input.click()
}

if (document.querySelector(".news")) {
getNews()
}

async function getNews() {
var data = await (await fetch("https://data.scratchtools.app/news/")).json()
var note = document.createElement("div")
note.className = "note blue"
var h3 = document.createElement("h3")
h3.textContent = data.title
var span = document.createElement("span")
span.innerHTML = data.description
note.appendChild(h3)
note.appendChild(span)
document.querySelector(".news").appendChild(note)
}
10 changes: 9 additions & 1 deletion extras/support/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@ var verifyUser = async function (callback) {
};

verifyUser(function (code) {
chrome.runtime.sendMessage(steSupportId, { msg: "openSupportChat", code });
chrome.runtime.sendMessage(steSupportId, { msg: "openSupportChat", code });
});

if (Scratch?.INIT_DATA?.LOGGED_IN_USER?.model?.username) {
verifyUser(function (code) {
chrome.runtime.sendMessage(steSupportId, { msg: "openFeedbackPage", code });
});
} else {
window.location.href = "/login/";
}

0 comments on commit e47dabf

Please sign in to comment.