Skip to content

Commit

Permalink
Update index.html and index.js
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sarxzer committed Mar 16, 2024
1 parent 38a2ee7 commit ae2d17b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<input type="text" name="fileName" id="fileName" value="program">
<button id="downloadButton">Download</button>
<button id="uploadButton">Upload to Pastebin</button>
<input type="text" name="pastebinKey" id="pastebinKey" value="">
<button id="loadFromPastebinButton">Load from Pastebin</button>
<button id="uploadWorkspaceButton">Upload Workspace to Pastebin</button>
<button id="loadWorkspaceButton">Load Workspace from Pastebin</button>
<button id="loadButton">Load</button>

</div>
Expand Down
51 changes: 51 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,56 @@ const loadWorkspace = () => {
};
};

const uploadToPastebin = () => {
const code = luaGenerator.workspaceToCode(ws);
const xhr = new XMLHttpRequest();
xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
const url = xhr.responseText;
const a = document.createElement('a');
a.href = url;
a.target = '_blank';
a.click();
}
};
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`);
}

const uploadWorkspaceToPastebin = () => {
const workspace = save(ws);
const xhr = new XMLHttpRequest();
xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
const url = xhr.responseText;
const a = document.createElement('a');
a.href = url;
a.target = '_blank';
a.click();
}
};
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`);
}

const loadWorkspaceFromPastebin = () => {
const id = prompt('Enter pastebin ID');
if (!id) return;
const xhr = new XMLHttpRequest();
xhr.open('GET', `pastebin.php?id=${id}`, true);
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
load(ws, xhr.responseText);
console.log(xhr.responseText);
}
};
xhr.send();
}

downloadButton.onclick = downloadWorkspace;
uploadButton.onclick = uploadToPastebin;
uploadWorkspaceButton.onclick = uploadWorkspaceToPastebin;
loadWorkspaceButton.onclick = loadWorkspaceFromPastebin;
loadButton.onclick = loadWorkspace;

0 comments on commit ae2d17b

Please sign in to comment.