Skip to content

Commit ae2d17b

Browse files
committed
Update index.html and index.js
This commit includes necessary updates to the index.html and index.js files. The changes are intended to improve the functionality of the loadWorkspaceFromPastebin function, enabling it to handle requests server-side through a PHP script.
1 parent 38a2ee7 commit ae2d17b

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<input type="text" name="fileName" id="fileName" value="program">
1515
<button id="downloadButton">Download</button>
1616
<button id="uploadButton">Upload to Pastebin</button>
17-
<input type="text" name="pastebinKey" id="pastebinKey" value="">
18-
<button id="loadFromPastebinButton">Load from Pastebin</button>
17+
<button id="uploadWorkspaceButton">Upload Workspace to Pastebin</button>
18+
<button id="loadWorkspaceButton">Load Workspace from Pastebin</button>
1919
<button id="loadButton">Load</button>
2020

2121
</div>

src/index.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,56 @@ const loadWorkspace = () => {
6666
};
6767
};
6868

69+
const uploadToPastebin = () => {
70+
const code = luaGenerator.workspaceToCode(ws);
71+
const xhr = new XMLHttpRequest();
72+
xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
73+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
74+
xhr.onreadystatechange = () => {
75+
if (xhr.readyState == 4 && xhr.status == 200) {
76+
const url = xhr.responseText;
77+
const a = document.createElement('a');
78+
a.href = url;
79+
a.target = '_blank';
80+
a.click();
81+
}
82+
};
83+
xhr.send(`api_dev_key=nSfNmQEF3ttNwx-zjU5MvguXnz8Oruw7&api_user_key=d43a286490fa94b7d413dd2f5eb8d38d&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(code)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | lua (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=lua`);
84+
}
85+
86+
const uploadWorkspaceToPastebin = () => {
87+
const workspace = save(ws);
88+
const xhr = new XMLHttpRequest();
89+
xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
90+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
91+
xhr.onreadystatechange = () => {
92+
if (xhr.readyState == 4 && xhr.status == 200) {
93+
const url = xhr.responseText;
94+
const a = document.createElement('a');
95+
a.href = url;
96+
a.target = '_blank';
97+
a.click();
98+
}
99+
};
100+
xhr.send(`api_dev_key=nSfNmQEF3ttNwx-zjU5MvguXnz8Oruw7&api_user_key=d43a286490fa94b7d413dd2f5eb8d38d&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(workspace)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | workspace (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=json`);
101+
}
102+
103+
const loadWorkspaceFromPastebin = () => {
104+
const id = prompt('Enter pastebin ID');
105+
if (!id) return;
106+
const xhr = new XMLHttpRequest();
107+
xhr.open('GET', `pastebin.php?id=${id}`, true);
108+
xhr.onreadystatechange = () => {
109+
if (xhr.readyState == 4 && xhr.status == 200) {
110+
load(ws, xhr.responseText);
111+
console.log(xhr.responseText);
112+
}
113+
};
114+
xhr.send();
115+
}
116+
69117
downloadButton.onclick = downloadWorkspace;
118+
uploadButton.onclick = uploadToPastebin;
119+
uploadWorkspaceButton.onclick = uploadWorkspaceToPastebin;
120+
loadWorkspaceButton.onclick = loadWorkspaceFromPastebin;
70121
loadButton.onclick = loadWorkspace;

0 commit comments

Comments
 (0)