forked from rDrama/rDrama
1
0
Fork 0

remove jc bloat

master
Aevann 2023-08-12 13:35:59 +03:00
parent 5cbb95689b
commit 149095d91e
3 changed files with 12 additions and 14 deletions

View File

@ -3,7 +3,7 @@ function submitAddAlt(element, username) {
element.classList.add('disabled'); element.classList.add('disabled');
const form = new FormData(); const form = new FormData();
form.append('other_username', document.getElementById('link-input-other').value); form.append('other_username', document.getElementById('link-input-other').value);
const xhr = createXhrWithFormKey(`/@${username}/alts/`, 'POST', form); const xhr = createXhrWithFormKey(`/@${username}/alts/`, form);
xhr[0].onload = function() { xhr[0].onload = function() {
let data; let data;
try { try {

View File

@ -139,7 +139,7 @@ function post_reply(id) {
} }
catch(e) {} catch(e) {}
const xhr = createXhrWithFormKey("/reply", "POST", form); const xhr = createXhrWithFormKey("/reply", form);
const upload_prog = document.getElementById(`upload-prog-c_${id}`); const upload_prog = document.getElementById(`upload-prog-c_${id}`);
xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
@ -197,7 +197,7 @@ function comment_edit(id){
form.append('file', e); form.append('file', e);
} }
catch(e) {} catch(e) {}
const xhr = createXhrWithFormKey("/edit_comment/"+id, "POST", form); const xhr = createXhrWithFormKey("/edit_comment/"+id, form);
const upload_prog = document.getElementById(`upload-prog-edit-c_${id}`); const upload_prog = document.getElementById(`upload-prog-edit-c_${id}`);
xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};

View File

@ -23,23 +23,23 @@ function showToast(success, message) {
bootstrap.Toast.getOrCreateInstance(document.getElementById(element)).show(); bootstrap.Toast.getOrCreateInstance(document.getElementById(element)).show();
} }
function createXhrWithFormKey(url, method="POST", form=new FormData()) { function createXhrWithFormKey(url, form=new FormData()) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open(method, url); xhr.open('POST', url);
xhr.setRequestHeader('xhr', 'xhr'); xhr.setRequestHeader('xhr', 'xhr');
if (!form) form = new FormData(); if (!form) form = new FormData();
form.append("formkey", formkey()); form.append("formkey", formkey());
return [xhr, form]; // hacky but less stupid than what we were doing before return [xhr, form]; // hacky but less stupid than what we were doing before
} }
function postToast(t, url, data, extraActionsOnSuccess, method="POST") { function postToast(t, url, data, extraActionsOnSuccess) {
let form = new FormData(); let form = new FormData();
if (typeof data === 'object' && data !== null) { if (typeof data === 'object' && data !== null) {
for(let k of Object.keys(data)) { for(let k of Object.keys(data)) {
form.append(k, data[k]); form.append(k, data[k]);
} }
} }
const xhr = createXhrWithFormKey(url, method, form); const xhr = createXhrWithFormKey(url, form);
xhr[0].onload = function() { xhr[0].onload = function() {
const success = xhr[0].status >= 200 && xhr[0].status < 300; const success = xhr[0].status >= 200 && xhr[0].status < 300;
@ -62,11 +62,11 @@ function postToast(t, url, data, extraActionsOnSuccess, method="POST") {
xhr[0].send(xhr[1]); xhr[0].send(xhr[1]);
} }
function postToastReload(t, url, method="POST") { function postToastReload(t, url) {
postToast(t, url, {}, reload, method); postToast(t, url, {}, reload);
} }
function postToastSwitch(t, url, button1, button2, cls, extraActionsOnSuccess, method="POST") { function postToastSwitch(t, url, button1, button2, cls, extraActionsOnSuccess) {
postToast(t, url, postToast(t, url,
{ {
}, },
@ -87,9 +87,8 @@ function postToastSwitch(t, url, button1, button2, cls, extraActionsOnSuccess, m
} }
} }
if (typeof extraActionsOnSuccess == 'function') if (typeof extraActionsOnSuccess == 'function')
extraActionsOnSuccess(xhr); extraActionsOnSuccess(xhr);
} });
, method);
} }
if (!location.pathname.endsWith('/submit')) if (!location.pathname.endsWith('/submit'))
@ -643,7 +642,6 @@ function updateSubscriptionOnServer(subscription, apiEndpoint) {
const xhr = createXhrWithFormKey( const xhr = createXhrWithFormKey(
apiEndpoint, apiEndpoint,
'POST',
formData formData
); );