Skip to content

Commit ce6efc8

Browse files
committed
feat: use faretek api instead of pyodide
faretek api is open source and hosted on vercel: https://github.com/FAReTek1/faretek-api/
1 parent 13a3953 commit ce6efc8

11 files changed

Lines changed: 14 additions & 38655 deletions
-21.5 KB
Binary file not shown.

addons/goboscript/userscript.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* global chrome */
2-
import * as sb2gs from "./sb2gs.js";
3-
import * as pyodidePkg from "./../../libraries/thirdparty/pyodide/pyodide.mjs";
1+
import downloadBlob from "../../libraries/common/cs/download-blob.js";
42

53
/**
64
* @param addon {UserscriptAddon}
@@ -13,32 +11,26 @@ export default async function ({ addon, console }) {
1311
decompileButton.title = "Decompile to goboscript code & download.";
1412
decompileButton.appendChild(document.createElement("span")).innerText = "Decompile";
1513

16-
const pyodidePromise = pyodidePkg.loadPyodide();
14+
decompileButton.onclick = async (e) => {
15+
decompileButton.classList.remove("waiting");
16+
decompileButton.classList.add("loading");
1717

18-
const pyodidePackagingPromise = pyodidePromise.then(async (pyodide) => {
19-
// console.log("PYODIDE LOADED");
18+
const username = await addon.auth.fetchUsername();
19+
const projectAuthor = addon.tab.redux.state.preview.projectInfo.author?.username;
2020

21-
const loadMicropipPromise = pyodide.loadPackage("micropip");
21+
const isOwn = username === projectAuthor;
2222

23-
const sb2gsWhlFile = await (await fetch(`${addon.self.dir}/${sb2gs.sb2gsWhlName}`)).bytes();
23+
const title = isOwn ? document.querySelector(".project-title input") : document.querySelector(".project-title");
24+
const titleStr = isOwn ? title.value : title.innerText;
2425

25-
pyodide.FS.writeFile(`/${sb2gs.sb2gsWhlName}`, sb2gsWhlFile);
26+
const projectId = window.location.pathname.split("/")[2];
2627

27-
await loadMicropipPromise;
28+
try {
29+
const beginFilenameWithId = e.shiftKey !== addon.settings.get("beginFilenameWithId");
2830

29-
// console.log("EXITING PYODIDE PACKAGING");
30-
return pyodide;
31-
});
31+
const data = await (await fetch(`https://faretek-api.vercel.app/api/sb2gs/?id=${projectId}`)).blob();
32+
downloadBlob((beginFilenameWithId ? `${projectId} ` : "") + titleStr + ".zip", data);
3233

33-
decompileButton.onclick = async (e) => {
34-
// console.log("DECOMPILE BUTTON CLICKED");
35-
const pyodide = await pyodidePackagingPromise;
36-
// console.log("AWAITED PYODIDE PACKAGING");
37-
38-
decompileButton.classList.remove("waiting");
39-
decompileButton.classList.add("loading");
40-
try {
41-
await sb2gs.decompile(addon, console, pyodide, e.shiftKey !== addon.settings.get("beginFilenameWithId"));
4234
} catch (err) {
4335
window.alert(err);
4436
}

0 commit comments

Comments
 (0)