From 68c64a63f3bf1e85c73c3829aafc8cfdde35c48e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 16 Jan 2022 06:58:56 +0200 Subject: [PATCH] bb --- files/assets/js/comments_v.js | 31 +++++++++++++++++++------- files/assets/js/header.js | 5 ++++- files/assets/js/post_toast2.js | 5 ++++- files/assets/js/userpage_v.js | 2 ++ files/templates/changelog.html | 2 +- files/templates/comments.html | 2 +- files/templates/default.html | 2 +- files/templates/header.html | 2 +- files/templates/userpage.html | 2 +- files/templates/userpage_comments.html | 2 +- files/templates/userpage_private.html | 2 +- 11 files changed, 40 insertions(+), 17 deletions(-) diff --git a/files/assets/js/comments_v.js b/files/assets/js/comments_v.js index eae89f4a2..c0779f354 100644 --- a/files/assets/js/comments_v.js +++ b/files/assets/js/comments_v.js @@ -8,6 +8,8 @@ function post(url) { }; function post_toast3(url, button1, button2) { + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." + var xhr = new XMLHttpRequest(); xhr.open("POST", url, true); var form = new FormData() @@ -24,7 +26,8 @@ function post_toast3(url, button1, button2) { xhr.withCredentials=true; xhr.onload = function() { - let data = JSON.parse(xhr.response) + try {let data = JSON.parse(xhr.response)} + catch(e) {} if (xhr.status >= 200 && xhr.status < 300 && data && data["message"]) { document.getElementById('toast-post-success-text').innerText = data["message"]; new bootstrap.Toast(document.getElementById('toast-post-success')).show(); @@ -107,9 +110,9 @@ function delete_commentModal(id) { }; function post_reply(id){ + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." var form = new FormData(); - form.append('formkey', formkey()); form.append('parent_id', id); form.append('body', document.getElementById('reply-form-body-'+id).value); @@ -122,8 +125,11 @@ function post_reply(id){ commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '').replace('comment-collapse-desktop d-none d-md-block','d-none').replace('border-left: 2px solid','padding-left:0;border-left: 0px solid') } else { - let data = JSON.parse(xhr.response) - if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"]; + try{ + let data = JSON.parse(xhr.response) + document.getElementById('toast-post-error-text').innerText = data["error"]; + } + catch(e) {} new bootstrap.Toast(document.getElementById('toast-post-error')).show(); } } @@ -131,6 +137,7 @@ function post_reply(id){ } function comment_edit(id){ + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." var form = new FormData(); @@ -148,8 +155,11 @@ function comment_edit(id){ document.getElementById('cancel-edit-'+id).click() } else { - let data = JSON.parse(xhr.response) - if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"]; + try{ + let data = JSON.parse(xhr.response) + document.getElementById('toast-post-error-text').innerText = data["error"]; + } + catch(e) {} new bootstrap.Toast(document.getElementById('toast-post-error')).show(); } } @@ -157,6 +167,8 @@ function comment_edit(id){ } function post_comment(fullname){ + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." + const btn = document.getElementById('save-reply-to-'+fullname) btn.classList.add('disabled'); @@ -177,8 +189,11 @@ function post_comment(fullname){ commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '') } else { - let data = JSON.parse(xhr.response) - if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"]; + try{ + let data = JSON.parse(xhr.response) + document.getElementById('toast-post-error-text').innerText = data["error"]; + } + catch(e) {} new bootstrap.Toast(document.getElementById('toast-post-error')).show(); btn.classList.remove('disabled'); } diff --git a/files/assets/js/header.js b/files/assets/js/header.js index f57475963..8a089a43f 100644 --- a/files/assets/js/header.js +++ b/files/assets/js/header.js @@ -12,6 +12,8 @@ document.addEventListener("DOMContentLoaded", function(){ }); function post_toast(url, reload, data) { + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." + var xhr = new XMLHttpRequest(); xhr.open("POST", url, true); var form = new FormData() @@ -26,7 +28,8 @@ function post_toast(url, reload, data) { xhr.withCredentials=true; xhr.onload = function() { - let data = JSON.parse(xhr.response) + try {let data = JSON.parse(xhr.response)} + catch(e) {} if (xhr.status >= 200 && xhr.status < 300 && data && data['message']) { document.getElementById('toast-post-success-text').innerText = data["message"]; new bootstrap.Toast(document.getElementById('toast-post-success')).show(); diff --git a/files/assets/js/post_toast2.js b/files/assets/js/post_toast2.js index 8c4de293a..a2591140a 100644 --- a/files/assets/js/post_toast2.js +++ b/files/assets/js/post_toast2.js @@ -1,4 +1,6 @@ function post_toast2(url, button1, button2) { + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." + var xhr = new XMLHttpRequest(); xhr.open("POST", url, true); var form = new FormData() @@ -15,7 +17,8 @@ function post_toast2(url, button1, button2) { xhr.withCredentials=true; xhr.onload = function() { - let data = JSON.parse(xhr.response) + try {let data = JSON.parse(xhr.response)} + catch(e) {} if (xhr.status >= 200 && xhr.status < 300 && data && data["message"]) { document.getElementById('toast-post-success-text').innerText = data["message"]; new bootstrap.Toast(document.getElementById('toast-post-success')).show(); diff --git a/files/assets/js/userpage_v.js b/files/assets/js/userpage_v.js index a8856d145..32d347b8c 100644 --- a/files/assets/js/userpage_v.js +++ b/files/assets/js/userpage_v.js @@ -124,6 +124,8 @@ function transferBux(mobile=false) { } function submitFormAjax(e) { + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." + document.getElementById('message').classList.add('d-none'); document.getElementById('message-mobile').classList.add('d-none'); document.getElementById('message-preview').classList.add('d-none'); diff --git a/files/templates/changelog.html b/files/templates/changelog.html index b4954559d..347ede925 100644 --- a/files/templates/changelog.html +++ b/files/templates/changelog.html @@ -104,6 +104,6 @@ {% endif %} - + {% endblock %} \ No newline at end of file diff --git a/files/templates/comments.html b/files/templates/comments.html index 3d9921289..0c026cfe4 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -848,7 +848,7 @@ {% if v %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 6878b51cd..791d707b5 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -317,7 +317,7 @@ {% if v %} - + {% endif %} diff --git a/files/templates/header.html b/files/templates/header.html index f55590467..b9c60c467 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -207,7 +207,7 @@ - +