This commit is contained in:
Aevann1 2021-10-08 06:37:25 +02:00
parent d0305675b9
commit d5c078ff78
16 changed files with 934 additions and 933 deletions

View file

@ -1,87 +1,87 @@
function vote(type, id, dir) { function vote(type, id, dir) {
var upvote = document.getElementById(type + '-' + id + '-up'); var upvote = document.getElementById(type + '-' + id + '-up');
var downvote = document.getElementById(type + '-' + id + '-down'); var downvote = document.getElementById(type + '-' + id + '-down');
var scoretext = document.getElementById(type + '-score-' + id); var scoretext = document.getElementById(type + '-score-' + id);
var score = Number(scoretext.textContent); var score = Number(scoretext.textContent);
if (dir == "1") { if (dir == "1") {
if (upvote.classList.contains('active')) { if (upvote.classList.contains('active')) {
upvote.classList.remove('active') upvote.classList.remove('active')
scoretext.textContent = score - 1 scoretext.textContent = score - 1
votedirection = "0" votedirection = "0"
} else if (downvote.classList.contains('active')) { } else if (downvote.classList.contains('active')) {
upvote.classList.add('active') upvote.classList.add('active')
downvote.classList.remove('active') downvote.classList.remove('active')
scoretext.textContent = score + 2 scoretext.textContent = score + 2
votedirection = "1" votedirection = "1"
} else { } else {
upvote.classList.add('active') upvote.classList.add('active')
scoretext.textContent = score + 1 scoretext.textContent = score + 1
votedirection = "1" votedirection = "1"
} }
if (upvote.classList.contains('active')) { if (upvote.classList.contains('active')) {
scoretext.classList.add('score-up') scoretext.classList.add('score-up')
scoretext.classList.remove('score-down') scoretext.classList.remove('score-down')
scoretext.classList.remove('score') scoretext.classList.remove('score')
} else if (downvote.classList.contains('active')) { } else if (downvote.classList.contains('active')) {
scoretext.classList.add('score-down') scoretext.classList.add('score-down')
scoretext.classList.remove('score-up') scoretext.classList.remove('score-up')
scoretext.classList.remove('score') scoretext.classList.remove('score')
} else { } else {
scoretext.classList.add('score') scoretext.classList.add('score')
scoretext.classList.remove('score-up') scoretext.classList.remove('score-up')
scoretext.classList.remove('score-down') scoretext.classList.remove('score-down')
} }
} }
else { else {
if (downvote.classList.contains('active')) { if (downvote.classList.contains('active')) {
downvote.classList.remove('active') downvote.classList.remove('active')
scoretext.textContent = score + 1 scoretext.textContent = score + 1
votedirection = "0" votedirection = "0"
} else if (upvote.classList.contains('active')) { } else if (upvote.classList.contains('active')) {
downvote.classList.add('active') downvote.classList.add('active')
upvote.classList.remove('active') upvote.classList.remove('active')
scoretext.textContent = score - 2 scoretext.textContent = score - 2
votedirection = "-1" votedirection = "-1"
} else { } else {
downvote.classList.add('active') downvote.classList.add('active')
scoretext.textContent = score - 1 scoretext.textContent = score - 1
votedirection = "-1" votedirection = "-1"
} }
if (upvote.classList.contains('active')) { if (upvote.classList.contains('active')) {
scoretext.classList.add('score-up') scoretext.classList.add('score-up')
scoretext.classList.remove('score-down') scoretext.classList.remove('score-down')
scoretext.classList.remove('score') scoretext.classList.remove('score')
} else if (downvote.classList.contains('active')) { } else if (downvote.classList.contains('active')) {
scoretext.classList.add('score-down') scoretext.classList.add('score-down')
scoretext.classList.remove('score-up') scoretext.classList.remove('score-up')
scoretext.classList.remove('score') scoretext.classList.remove('score')
} else { } else {
scoretext.classList.add('score') scoretext.classList.add('score')
scoretext.classList.remove('score-up') scoretext.classList.remove('score-up')
scoretext.classList.remove('score-down') scoretext.classList.remove('score-down')
} }
} }
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", "/vote/" + type.replace('-mobile','') + "/" + id + "/" + votedirection, true); xhr.open("POST", "/vote/" + type.replace('-mobile','') + "/" + id + "/" + votedirection, true);
var form = new FormData() var form = new FormData()
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.send(form); xhr.send(form);
} }
function awardModal(link) { function awardModal(link) {
var target = document.getElementById("awardTarget"); var target = document.getElementById("awardTarget");
target.action = link; target.action = link;
} }
function bruh(kind) { function bruh(kind) {
document.getElementById('giveaward').disabled=false; document.getElementById('giveaward').disabled=false;
document.getElementById('kind').value=kind; document.getElementById('kind').value=kind;
try {document.getElementsByClassName('picked')[0].classList.toggle('picked');} catch(e) {} try {document.getElementsByClassName('picked')[0].classList.toggle('picked');} catch(e) {}
document.getElementById(kind).classList.toggle('picked') document.getElementById(kind).classList.toggle('picked')
} }

View file

@ -1,52 +1,52 @@
function post_toast2(url, button1, button2) { function post_toast2(url, button1, button2) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", url, true); xhr.open("POST", url, true);
var form = new FormData() var 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]);
} }
} }
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload = function() { xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300) {
try { try {
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"]; document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
} catch(e) { } catch(e) {
document.getElementById('toast-post-success-text').innerText = "Action successful!"; document.getElementById('toast-post-success-text').innerText = "Action successful!";
} }
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.show(); myToast.show();
return true return true
} else if (xhr.status >= 300 && xhr.status < 400) { } else if (xhr.status >= 300 && xhr.status < 400) {
window.location.href = JSON.parse(xhr.response)["redirect"] window.location.href = JSON.parse(xhr.response)["redirect"]
} else { } else {
try { try {
data=JSON.parse(xhr.response); data=JSON.parse(xhr.response);
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById('toast-post-error-text').innerText = data["error"]; document.getElementById('toast-post-error-text').innerText = data["error"];
return false return false
} catch(e) { } catch(e) {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById('toast-post-error-text').innerText = "Error. Please try again later."; document.getElementById('toast-post-error-text').innerText = "Error. Please try again later.";
return false return false
} }
} }
}; };
xhr.send(form); xhr.send(form);
document.getElementById(button1).classList.toggle("d-none"); document.getElementById(button1).classList.toggle("d-none");
document.getElementById(button2).classList.toggle("d-none"); document.getElementById(button2).classList.toggle("d-none");
} }

View file

@ -1,74 +1,74 @@
function removeComment(post_id,button1,button2) { function removeComment(post_id,button1,button2) {
url="/ban_comment/"+post_id url="/ban_comment/"+post_id
post(url) post(url)
try { try {
document.getElementById("comment-"+post_id+"-only").classList.add("banned"); document.getElementById("comment-"+post_id+"-only").classList.add("banned");
} catch(e) { } catch(e) {
document.getElementById("context").classList.add("banned"); document.getElementById("context").classList.add("banned");
} }
var button=document.getElementById("remove-"+post_id); var button=document.getElementById("remove-"+post_id);
button.onclick=function(){approveComment(post_id)}; button.onclick=function(){approveComment(post_id)};
button.innerHTML='<i class="fas fa-clipboard-check"></i>Approve' button.innerHTML='<i class="fas fa-clipboard-check"></i>Approve'
if (typeof button1 !== 'undefined') { if (typeof button1 !== 'undefined') {
document.getElementById(button1).classList.toggle("d-md-inline-block"); document.getElementById(button1).classList.toggle("d-md-inline-block");
document.getElementById(button2).classList.toggle("d-md-inline-block"); document.getElementById(button2).classList.toggle("d-md-inline-block");
} }
}; };
function approveComment(post_id,button1,button2) { function approveComment(post_id,button1,button2) {
url="/unban_comment/"+post_id url="/unban_comment/"+post_id
post(url) post(url)
try { try {
document.getElementById("comment-"+post_id+"-only").classList.remove("banned"); document.getElementById("comment-"+post_id+"-only").classList.remove("banned");
} catch(e) { } catch(e) {
document.getElementById("context").classList.remove("banned"); document.getElementById("context").classList.remove("banned");
} }
var button=document.getElementById("remove-"+post_id); var button=document.getElementById("remove-"+post_id);
button.onclick=function(){removeComment(post_id)}; button.onclick=function(){removeComment(post_id)};
button.innerHTML='<i class="fas fa-trash-alt"></i>Remove' button.innerHTML='<i class="fas fa-trash-alt"></i>Remove'
if (typeof button1 !== 'undefined') { if (typeof button1 !== 'undefined') {
document.getElementById(button1).classList.toggle("d-md-inline-block"); document.getElementById(button1).classList.toggle("d-md-inline-block");
document.getElementById(button2).classList.toggle("d-md-inline-block"); document.getElementById(button2).classList.toggle("d-md-inline-block");
} }
} }
function removeComment2(post_id,button1,button2) { function removeComment2(post_id,button1,button2) {
url="/ban_comment/"+post_id url="/ban_comment/"+post_id
post(url) post(url)
document.getElementById("comment-"+post_id+"-only").classList.add("banned"); document.getElementById("comment-"+post_id+"-only").classList.add("banned");
var button=document.getElementById("remove-"+post_id); var button=document.getElementById("remove-"+post_id);
button.onclick=function(){approveComment(post_id)}; button.onclick=function(){approveComment(post_id)};
button.innerHTML='<i class="fas fa-clipboard-check"></i>Approve' button.innerHTML='<i class="fas fa-clipboard-check"></i>Approve'
if (typeof button1 !== 'undefined') { if (typeof button1 !== 'undefined') {
document.getElementById(button1).classList.toggle("d-none"); document.getElementById(button1).classList.toggle("d-none");
document.getElementById(button2).classList.toggle("d-none"); document.getElementById(button2).classList.toggle("d-none");
} }
}; };
function approveComment2(post_id,button1,button2) { function approveComment2(post_id,button1,button2) {
url="/unban_comment/"+post_id url="/unban_comment/"+post_id
post(url) post(url)
document.getElementById("comment-"+post_id+"-only").classList.remove("banned"); document.getElementById("comment-"+post_id+"-only").classList.remove("banned");
var button=document.getElementById("remove-"+post_id); var button=document.getElementById("remove-"+post_id);
button.onclick=function(){removeComment(post_id)}; button.onclick=function(){removeComment(post_id)};
button.innerHTML='<i class="fas fa-trash-alt"></i>Remove' button.innerHTML='<i class="fas fa-trash-alt"></i>Remove'
if (typeof button1 !== 'undefined') { if (typeof button1 !== 'undefined') {
document.getElementById(button1).classList.toggle("d-none"); document.getElementById(button1).classList.toggle("d-none");
document.getElementById(button2).classList.toggle("d-none"); document.getElementById(button2).classList.toggle("d-none");
} }
} }

View file

@ -1,59 +1,59 @@
function post(url) { function post(url) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", url, true); xhr.open("POST", url, true);
var form = new FormData() var form = new FormData()
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.send(form); xhr.send(form);
}; };
function post_toast3(url, button1, button2) { function post_toast3(url, button1, button2) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", url, true); xhr.open("POST", url, true);
var form = new FormData() var 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]);
} }
} }
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload = function() { xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300) {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.show(); myToast.show();
try { try {
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"]; document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
} catch(e) { } catch(e) {
document.getElementById('toast-post-success-text').innerText = "Action successful!"; document.getElementById('toast-post-success-text').innerText = "Action successful!";
} }
return true return true
} else if (xhr.status >= 300 && xhr.status < 400) { } else if (xhr.status >= 300 && xhr.status < 400) {
window.location.href = JSON.parse(xhr.response)["redirect"] window.location.href = JSON.parse(xhr.response)["redirect"]
} else { } else {
try { try {
data=JSON.parse(xhr.response); data=JSON.parse(xhr.response);
} catch(e) {} } catch(e) {}
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById('toast-post-error-text').innerText = "Error. Please try again later."; document.getElementById('toast-post-error-text').innerText = "Error. Please try again later.";
return false return false
} }
}; };
xhr.send(form); xhr.send(form);
document.getElementById(button1).classList.toggle("d-md-inline-block"); document.getElementById(button1).classList.toggle("d-md-inline-block");
document.getElementById(button2).classList.toggle("d-md-inline-block"); document.getElementById(button2).classList.toggle("d-md-inline-block");
} }
report_commentModal = function(id, author) { report_commentModal = function(id, author) {
@ -62,138 +62,139 @@ document.getElementById("comment-author").textContent = author;
document.getElementById("reportCommentButton").onclick = function() { document.getElementById("reportCommentButton").onclick = function() {
this.innerHTML='<span class="spinner-border spinner-border-sm mr-2" role="status" aria-hidden="true"></span>Reporting comment'; this.innerHTML='<span class="spinner-border spinner-border-sm mr-2" role="status" aria-hidden="true"></span>Reporting comment';
this.disabled = true; this.disabled = true;
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", '/flag/comment/'+id, true); xhr.open("POST", '/flag/comment/'+id, true);
var form = new FormData() var form = new FormData()
form.append("formkey", formkey()); form.append("formkey", formkey());
form.append("reason", document.getElementById("reason-comment").value); form.append("reason", document.getElementById("reason-comment").value);
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload=function() { xhr.onload=function() {
document.getElementById("reportCommentFormBefore").classList.add('d-none'); document.getElementById("reportCommentFormBefore").classList.add('d-none');
document.getElementById("reportCommentFormAfter").classList.remove('d-none'); document.getElementById("reportCommentFormAfter").classList.remove('d-none');
}; };
xhr.onerror=function(){alert(errortext)}; xhr.onerror=function(){alert(errortext)};
xhr.send(form); xhr.send(form);
} }
}; };
function openReplyBox(id) { function openReplyBox(id) {
const element = document.getElementById(`reply-to-${id}`); const element = document.getElementById(`reply-to-${id}`);
element.classList.remove('d-none') element.classList.remove('d-none')
element.getElementsByTagName('textarea')[0].focus() element.getElementsByTagName('textarea')[0].focus()
} }
toggleEdit=function(id){ toggleEdit=function(id){
comment=document.getElementById("comment-text-"+id); comment=document.getElementById("comment-text-"+id);
form=document.getElementById("comment-edit-"+id); form=document.getElementById("comment-edit-"+id);
box=document.getElementById('comment-edit-body-'+id); box=document.getElementById('comment-edit-body-'+id);
actions = document.getElementById('comment-' + id +'-actions'); actions = document.getElementById('comment-' + id +'-actions');
comment.classList.toggle("d-none"); comment.classList.toggle("d-none");
form.classList.toggle("d-none"); form.classList.toggle("d-none");
actions.classList.toggle("d-none"); actions.classList.toggle("d-none");
autoExpand(box); autoExpand(box);
}; };
function delete_commentModal(id) { function delete_commentModal(id) {
document.getElementById("deleteCommentButton").onclick = function() { document.getElementById("deleteCommentButton").onclick = function() {
this.innerHTML='<span class="spinner-border spinner-border-sm mr-2" role="status" aria-hidden="true"></span>Deleting comment'; this.innerHTML='<span class="spinner-border spinner-border-sm mr-2" role="status" aria-hidden="true"></span>Deleting comment';
this.disabled = true; this.disabled = true;
post('/delete/comment/' + id) post('/delete/comment/' + id)
location.reload(); location.reload();
} }
}; };
post_reply=function(id){ post_reply=function(id){
var form = new FormData(); var form = new FormData();
form.append('formkey', formkey()); form.append('formkey', formkey());
form.append('parent_id', id); form.append('parent_id', id);
form.append('body', document.getElementById('reply-form-body-'+id).value); form.append('body', document.getElementById('reply-form-body-'+id).value);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("post", "/reply"); xhr.open("post", "/reply");
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload=function(){ xhr.onload=function(){
if (xhr.status==200) { if (xhr.status==200) {
commentForm=document.getElementById('comment-form-space-'+id); commentForm=document.getElementById('comment-form-space-'+id);
commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src'); commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src');
} }
else { else {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById("comment-error-text").textContent = "Error. Please try again later."; document.getElementById("comment-error-text").textContent = "Error. Please try again later.";
} }
} }
xhr.send(form) xhr.send(form)
} }
comment_edit=function(id){ comment_edit=function(id){
var form = new FormData(); var form = new FormData();
form.append('formkey', formkey()); form.append('formkey', formkey());
form.append('body', document.getElementById('comment-edit-body-'+id).value); form.append('body', document.getElementById('comment-edit-body-'+id).value);
form.append('file', document.getElementById('file-edit-reply-'+id).files[0]); form.append('file', document.getElementById('file-edit-reply-'+id).files[0]);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("post", "/edit_comment/"+id); xhr.open("post", "/edit_comment/"+id);
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload=function(){ xhr.onload=function(){
if (xhr.status==200) { if (xhr.status==200) {
commentForm=document.getElementById('comment-text-'+id); commentForm=document.getElementById('comment-text-'+id);
commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src'); commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src');
document.getElementById('cancel-edit-'+id).click() document.getElementById('cancel-edit-'+id).click()
} }
else { else {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById("comment-error-text").textContent = "Error. Please try again later."; document.getElementById("comment-error-text").textContent = "Error. Please try again later.";
} }
} }
xhr.send(form) xhr.send(form)
} }
post_comment=function(fullname){ post_comment=function(fullname){
document.getElementById('save-reply-to-'+fullname).classList.add('disabled');
var form = new FormData(); var form = new FormData();
form.append('formkey', formkey()); form.append('formkey', formkey());
form.append('parent_fullname', fullname); form.append('parent_fullname', fullname);
form.append('submission', document.getElementById('reply-form-submission-'+fullname).value); form.append('submission', document.getElementById('reply-form-submission-'+fullname).value);
form.append('body', document.getElementById('reply-form-body-'+fullname).value); form.append('body', document.getElementById('reply-form-body-'+fullname).value);
form.append('file', document.getElementById('file-upload-reply-'+fullname).files[0]); form.append('file', document.getElementById('file-upload-reply-'+fullname).files[0]);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("post", "/comment"); xhr.open("post", "/comment");
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload=function(){ xhr.onload=function(){
if (xhr.status==200) { if (xhr.status==200) {
commentForm=document.getElementById('comment-form-space-'+fullname); commentForm=document.getElementById('comment-form-space-'+fullname);
commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src'); commentForm.innerHTML = xhr.response.replace(/data-src/g, 'src');
} }
else { else {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById("comment-error-text").textContent = "Error. Please try again later."; document.getElementById("comment-error-text").textContent = "Error. Please try again later.";
} }
} }
xhr.send(form) xhr.send(form)
} }

View file

@ -2,139 +2,139 @@ const observer = lozad();
observer.observe(); observer.observe();
makeBold = function (form) { makeBold = function (form) {
var text = document.getElementById(form); var text = document.getElementById(form);
var startIndex = text.selectionStart, var startIndex = text.selectionStart,
endIndex = text.selectionEnd; endIndex = text.selectionEnd;
var selectedText = text.value.substring(startIndex, endIndex); var selectedText = text.value.substring(startIndex, endIndex);
var format = '**' var format = '**'
if (selectedText.includes('**')) { if (selectedText.includes('**')) {
text.value = selectedText.replace(/\*/g, ''); text.value = selectedText.replace(/\*/g, '');
} }
else if (selectedText.length == 0) { else if (selectedText.length == 0) {
text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex);
} }
else { else {
text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex);
} }
} }
makeItalics = function (form) { makeItalics = function (form) {
var text = document.getElementById(form); var text = document.getElementById(form);
var startIndex = text.selectionStart, var startIndex = text.selectionStart,
endIndex = text.selectionEnd; endIndex = text.selectionEnd;
var selectedText = text.value.substring(startIndex, endIndex); var selectedText = text.value.substring(startIndex, endIndex);
var format = '*' var format = '*'
if (selectedText.includes('*')) { if (selectedText.includes('*')) {
text.value = selectedText.replace(/\*/g, ''); text.value = selectedText.replace(/\*/g, '');
} }
else if (selectedText.length == 0) { else if (selectedText.length == 0) {
text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex);
} }
else { else {
text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex);
} }
} }
makeQuote = function (form) { makeQuote = function (form) {
var text = document.getElementById(form); var text = document.getElementById(form);
var startIndex = text.selectionStart, var startIndex = text.selectionStart,
endIndex = text.selectionEnd; endIndex = text.selectionEnd;
var selectedText = text.value.substring(startIndex, endIndex); var selectedText = text.value.substring(startIndex, endIndex);
var format = '>' var format = '>'
if (selectedText.includes('>')) { if (selectedText.includes('>')) {
text.value = text.value.substring(0, startIndex) + selectedText.replace(/\>/g, '') + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText.replace(/\>/g, '') + text.value.substring(endIndex);
} }
else if (selectedText.length == 0) { else if (selectedText.length == 0) {
text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex);
} }
else { else {
text.value = text.value.substring(0, startIndex) + format + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + format + selectedText + text.value.substring(endIndex);
} }
} }
function autoExpand (field) { function autoExpand (field) {
xpos=window.scrollX; xpos=window.scrollX;
ypos=window.scrollY; ypos=window.scrollY;
field.style.height = 'inherit'; field.style.height = 'inherit';
var computed = window.getComputedStyle(field); var computed = window.getComputedStyle(field);
var height = parseInt(computed.getPropertyValue('border-top-width'), 10) var height = parseInt(computed.getPropertyValue('border-top-width'), 10)
+ parseInt(computed.getPropertyValue('padding-top'), 10) + parseInt(computed.getPropertyValue('padding-top'), 10)
+ field.scrollHeight + field.scrollHeight
+ parseInt(computed.getPropertyValue('padding-bottom'), 10) + parseInt(computed.getPropertyValue('padding-bottom'), 10)
+ parseInt(computed.getPropertyValue('border-bottom-width'), 10) + parseInt(computed.getPropertyValue('border-bottom-width'), 10)
+ 32; + 32;
field.style.height = height + 'px'; field.style.height = height + 'px';
window.scrollTo(xpos,ypos); window.scrollTo(xpos,ypos);
}; };
document.addEventListener('input', function (event) { document.addEventListener('input', function (event) {
if (event.target.tagName.toLowerCase() !== 'textarea') return; if (event.target.tagName.toLowerCase() !== 'textarea') return;
autoExpand(event.target); autoExpand(event.target);
}, false); }, false);
function post_toast2(url, button1, button2) { function post_toast2(url, button1, button2) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", url, true); xhr.open("POST", url, true);
var form = new FormData() var 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]);
} }
} }
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload = function() { xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300) {
try { try {
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"]; document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
} catch(e) { } catch(e) {
document.getElementById('toast-post-success-text').innerText = "Action successful!"; document.getElementById('toast-post-success-text').innerText = "Action successful!";
} }
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.show(); myToast.show();
return true return true
} else if (xhr.status >= 300 && xhr.status < 400) { } else if (xhr.status >= 300 && xhr.status < 400) {
window.location.href = JSON.parse(xhr.response)["redirect"] window.location.href = JSON.parse(xhr.response)["redirect"]
} else { } else {
try { try {
data=JSON.parse(xhr.response); data=JSON.parse(xhr.response);
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById('toast-post-error-text').innerText = data["error"]; document.getElementById('toast-post-error-text').innerText = data["error"];
return false return false
} catch(e) { } catch(e) {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById('toast-post-error-text').innerText = "Error. Please try again later."; document.getElementById('toast-post-error-text').innerText = "Error. Please try again later.";
return false return false
} }
} }
}; };
xhr.send(form); xhr.send(form);
document.getElementById(button1).classList.toggle("d-none"); document.getElementById(button1).classList.toggle("d-none");
document.getElementById(button2).classList.toggle("d-none"); document.getElementById(button2).classList.toggle("d-none");
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,59 +1,59 @@
document.addEventListener("DOMContentLoaded", function(){ document.addEventListener("DOMContentLoaded", function(){
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function(element){ tooltipTriggerList.map(function(element){
return new bootstrap.Tooltip(element); return new bootstrap.Tooltip(element);
}); });
}); });
function post_toast(url, reload, data) { function post_toast(url, reload, data) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", url, true); xhr.open("POST", url, true);
var form = new FormData() var 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]);
} }
} }
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload = function() { xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300) {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.show(); myToast.show();
try { try {
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"]; document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
} catch(e) { } catch(e) {
document.getElementById('toast-post-success-text').innerText = "Action successful!"; document.getElementById('toast-post-success-text').innerText = "Action successful!";
} }
if (reload == 1) {window.location.reload(true)} if (reload == 1) {window.location.reload(true)}
return true return true
} else if (xhr.status >= 300 && xhr.status < 400) { } else if (xhr.status >= 300 && xhr.status < 400) {
window.location.href = JSON.parse(xhr.response)["redirect"] window.location.href = JSON.parse(xhr.response)["redirect"]
} else { } else {
try { try {
data=JSON.parse(xhr.response); data=JSON.parse(xhr.response);
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById('toast-post-error-text').innerText = data["error"]; document.getElementById('toast-post-error-text').innerText = data["error"];
return false return false
} catch(e) { } catch(e) {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
document.getElementById('toast-post-error-text').innerText = "Error. Please try again later."; document.getElementById('toast-post-error-text').innerText = "Error. Please try again later.";
return false return false
} }
} }
}; };
xhr.send(form); xhr.send(form);
} }

View file

@ -1,46 +1,46 @@
window.onload = function () { window.onload = function () {
var prevScrollpos = window.pageYOffset; var prevScrollpos = window.pageYOffset;
window.onscroll = function () { window.onscroll = function () {
var currentScrollPos = window.pageYOffset; var currentScrollPos = window.pageYOffset;
var topBar = document.getElementById("fixed-bar-mobile"); var topBar = document.getElementById("fixed-bar-mobile");
var bottomBar = document.getElementById("mobile-bottom-navigation-bar"); var bottomBar = document.getElementById("mobile-bottom-navigation-bar");
var dropdown = document.getElementById("mobileSortDropdown"); var dropdown = document.getElementById("mobileSortDropdown");
var navbar = document.getElementById("navbar"); var navbar = document.getElementById("navbar");
if (bottomBar != null) { if (bottomBar != null) {
if (prevScrollpos > currentScrollPos && (window.innerHeight + currentScrollPos) < (document.body.offsetHeight - 65)) { if (prevScrollpos > currentScrollPos && (window.innerHeight + currentScrollPos) < (document.body.offsetHeight - 65)) {
bottomBar.style.bottom = "0px"; bottomBar.style.bottom = "0px";
} }
else if (currentScrollPos <= 125 && (window.innerHeight + currentScrollPos) < (document.body.offsetHeight - 65)) { else if (currentScrollPos <= 125 && (window.innerHeight + currentScrollPos) < (document.body.offsetHeight - 65)) {
bottomBar.style.bottom = "0px"; bottomBar.style.bottom = "0px";
} }
else if (prevScrollpos > currentScrollPos && (window.innerHeight + currentScrollPos) >= (document.body.offsetHeight - 65)) { else if (prevScrollpos > currentScrollPos && (window.innerHeight + currentScrollPos) >= (document.body.offsetHeight - 65)) {
bottomBar.style.bottom = "-50px"; bottomBar.style.bottom = "-50px";
} }
else { else {
bottomBar.style.bottom = "-50px"; bottomBar.style.bottom = "-50px";
} }
} }
if (topBar != null && dropdown != null) { if (topBar != null && dropdown != null) {
if (prevScrollpos > currentScrollPos) { if (prevScrollpos > currentScrollPos) {
topBar.style.top = "48px"; topBar.style.top = "48px";
navbar.classList.remove("shadow"); navbar.classList.remove("shadow");
} }
else if (currentScrollPos <= 125) { else if (currentScrollPos <= 125) {
topBar.style.top = "48px"; topBar.style.top = "48px";
navbar.classList.remove("shadow"); navbar.classList.remove("shadow");
} }
else { else {
topBar.style.top = "-48px"; topBar.style.top = "-48px";
dropdown.classList.remove('show'); dropdown.classList.remove('show');
navbar.classList.add("shadow"); navbar.classList.add("shadow");
} }
} }
prevScrollpos = currentScrollPos; prevScrollpos = currentScrollPos;
} }
} }

View file

@ -1,27 +1,27 @@
report_postModal = function(id) { report_postModal = function(id) {
submitbutton=document.getElementById("reportPostButton"); submitbutton=document.getElementById("reportPostButton");
submitbutton.onclick = function() { submitbutton.onclick = function() {
this.innerHTML='<span class="spinner-border spinner-border-sm mr-2" role="status" aria-hidden="true"></span>Reporting post'; this.innerHTML='<span class="spinner-border spinner-border-sm mr-2" role="status" aria-hidden="true"></span>Reporting post';
this.disabled = true; this.disabled = true;
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", '/flag/post/'+id, true); xhr.open("POST", '/flag/post/'+id, true);
var form = new FormData() var form = new FormData()
form.append("formkey", formkey()); form.append("formkey", formkey());
form.append("reason", document.getElementById("reason").value); form.append("reason", document.getElementById("reason").value);
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload=function() { xhr.onload=function() {
document.getElementById("reportPostFormBefore").classList.add('d-none'); document.getElementById("reportPostFormBefore").classList.add('d-none');
document.getElementById("reportPostFormAfter").classList.remove('d-none'); document.getElementById("reportPostFormAfter").classList.remove('d-none');
}; };
xhr.onerror=function(){alert(errortext)}; xhr.onerror=function(){alert(errortext)};
xhr.send(form); xhr.send(form);
} }
}; };

View file

@ -5,70 +5,70 @@ function post(url) {
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.send(form); xhr.send(form);
window.location.reload(true) window.location.reload(true)
}; };
function updatebgselection(){ function updatebgselection(){
var bgselector = document.getElementById("backgroundSelector"); var bgselector = document.getElementById("backgroundSelector");
var selection = bgselector.options[bgselector.selectedIndex].text; var selection = bgselector.options[bgselector.selectedIndex].text;
const backgrounds = [ const backgrounds = [
{ {
folder: "fantasy", folder: "fantasy",
backgrounds: backgrounds:
[ [
"1.webp", "1.webp",
"2.webp", "2.webp",
"3.webp", "3.webp",
"4.webp", "4.webp",
"5.webp", "5.webp",
"6.webp", "6.webp",
] ]
}, },
{ {
folder: "solarpunk", folder: "solarpunk",
backgrounds: backgrounds:
[ [
"1.webp", "1.webp",
"2.webp", "2.webp",
"3.webp", "3.webp",
"4.webp", "4.webp",
"5.webp", "5.webp",
"6.webp", "6.webp",
"7.webp", "7.webp",
"8.webp", "8.webp",
"9.webp", "9.webp",
"10.webp", "10.webp",
"11.webp", "11.webp",
"12.webp", "12.webp",
"13.webp", "13.webp",
"14.webp", "14.webp",
"15.webp", "15.webp",
"16.webp", "16.webp",
"17.webp", "17.webp",
"18.webp", "18.webp",
"19.webp", "19.webp",
] ]
}, },
{ {
folder: "pixelart", folder: "pixelart",
backgrounds: backgrounds:
[ [
"1.webp", "1.webp",
"2.webp", "2.webp",
"3.webp", "3.webp",
"4.webp", "4.webp",
"5.webp", "5.webp",
] ]
} }
] ]
let bgContainer = document.getElementById(`bgcontainer`); let bgContainer = document.getElementById(`bgcontainer`);
let str = ''; let str = '';
let bgsToDisplay = backgrounds[bgselector.selectedIndex].backgrounds; let bgsToDisplay = backgrounds[bgselector.selectedIndex].backgrounds;
let bgsDir = backgrounds[bgselector.selectedIndex].folder; let bgsDir = backgrounds[bgselector.selectedIndex].folder;
for (i=0; i < bgsToDisplay.length; i++) { for (i=0; i < bgsToDisplay.length; i++) {
let onclickPost = bgsDir + "/" + bgsToDisplay[i]; let onclickPost = bgsDir + "/" + bgsToDisplay[i];
str += `<button class="btn btn-secondary m-1 p-0" style="width:15rem; overflow: hidden;"><img loading="lazy" style="padding:0.25rem; width: 15rem" src="/assets/images/backgrounds/${bgsDir}/${bgsToDisplay[i]}" alt="${bgsToDisplay[i]}-background" onclick="post('/settings/profile?background=${onclickPost}')"/></button>`; str += `<button class="btn btn-secondary m-1 p-0" style="width:15rem; overflow: hidden;"><img loading="lazy" style="padding:0.25rem; width: 15rem" src="/assets/images/backgrounds/${bgsDir}/${bgsToDisplay[i]}" alt="${bgsToDisplay[i]}-background" onclick="post('/settings/profile?background=${onclickPost}')"/></button>`;
} }
bgContainer.innerHTML = str; bgContainer.innerHTML = str;
} }
updatebgselection(); updatebgselection();

View file

@ -1,235 +1,235 @@
makeBold = function (form) { makeBold = function (form) {
var text = document.getElementById(form); var text = document.getElementById(form);
var startIndex = text.selectionStart, var startIndex = text.selectionStart,
endIndex = text.selectionEnd; endIndex = text.selectionEnd;
var selectedText = text.value.substring(startIndex, endIndex); var selectedText = text.value.substring(startIndex, endIndex);
var format = '**' var format = '**'
if (selectedText.includes('**')) { if (selectedText.includes('**')) {
text.value = selectedText.replace(/\*/g, ''); text.value = selectedText.replace(/\*/g, '');
} }
else if (selectedText.length == 0) { else if (selectedText.length == 0) {
text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex);
} }
else { else {
text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex);
} }
} }
makeItalics = function (form) { makeItalics = function (form) {
var text = document.getElementById(form); var text = document.getElementById(form);
var startIndex = text.selectionStart, var startIndex = text.selectionStart,
endIndex = text.selectionEnd; endIndex = text.selectionEnd;
var selectedText = text.value.substring(startIndex, endIndex); var selectedText = text.value.substring(startIndex, endIndex);
var format = '*' var format = '*'
if (selectedText.includes('*')) { if (selectedText.includes('*')) {
text.value = selectedText.replace(/\*/g, ''); text.value = selectedText.replace(/\*/g, '');
} }
else if (selectedText.length == 0) { else if (selectedText.length == 0) {
text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex);
} }
else { else {
text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + format + selectedText + format + text.value.substring(endIndex);
} }
} }
makeQuote = function (form) { makeQuote = function (form) {
var text = document.getElementById(form); var text = document.getElementById(form);
var startIndex = text.selectionStart, var startIndex = text.selectionStart,
endIndex = text.selectionEnd; endIndex = text.selectionEnd;
var selectedText = text.value.substring(startIndex, endIndex); var selectedText = text.value.substring(startIndex, endIndex);
var format = '>' var format = '>'
if (selectedText.includes('>')) { if (selectedText.includes('>')) {
text.value = text.value.substring(0, startIndex) + selectedText.replace(/\>/g, '') + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText.replace(/\>/g, '') + text.value.substring(endIndex);
} }
else if (selectedText.length == 0) { else if (selectedText.length == 0) {
text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + selectedText + text.value.substring(endIndex);
} }
else { else {
text.value = text.value.substring(0, startIndex) + format + selectedText + text.value.substring(endIndex); text.value = text.value.substring(0, startIndex) + format + selectedText + text.value.substring(endIndex);
} }
} }
function charLimit(form, text) { function charLimit(form, text) {
var input = document.getElementById(form); var input = document.getElementById(form);
var text = document.getElementById(text); var text = document.getElementById(text);
var length = input.value.length; var length = input.value.length;
var maxLength = input.getAttribute("maxlength"); var maxLength = input.getAttribute("maxlength");
if (length >= maxLength) { if (length >= maxLength) {
text.style.color = "#E53E3E"; text.style.color = "#E53E3E";
} }
else if (length >= maxLength * .72){ else if (length >= maxLength * .72){
text.style.color = "#FFC107"; text.style.color = "#FFC107";
} }
else { else {
text.style.color = "#A0AEC0"; text.style.color = "#A0AEC0";
} }
text.innerText = maxLength - length; text.innerText = maxLength - length;
} }
hide_image=function(){ hide_image=function(){
x=document.getElementById('image-upload-block'); x=document.getElementById('image-upload-block');
url=document.getElementById('post-URL').value; url=document.getElementById('post-URL').value;
if (url.length>=1){ if (url.length>=1){
x.classList.add('d-none'); x.classList.add('d-none');
} }
else { else {
x.classList.remove('d-none'); x.classList.remove('d-none');
} }
} }
function autoSuggestTitle() { function autoSuggestTitle() {
var urlField = document.getElementById("post-URL"); var urlField = document.getElementById("post-URL");
var titleField = document.getElementById("post-title"); var titleField = document.getElementById("post-title");
var isValidURL = urlField.checkValidity(); var isValidURL = urlField.checkValidity();
if (isValidURL && urlField.value.length > 0 && titleField.value === "") { if (isValidURL && urlField.value.length > 0 && titleField.value === "") {
var x = new XMLHttpRequest(); var x = new XMLHttpRequest();
x.withCredentials=true; x.withCredentials=true;
x.onreadystatechange = function() { x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200) { if (x.readyState == 4 && x.status == 200) {
title=JSON.parse(x.responseText)["title"]; title=JSON.parse(x.responseText)["title"];
titleField.value=title; titleField.value=title;
checkForRequired() checkForRequired()
} }
} }
x.open('get','/submit/title?url=' + urlField.value); x.open('get','/submit/title?url=' + urlField.value);
x.send(null); x.send(null);
}; };
}; };
if (window.location.pathname=='/submit') { if (window.location.pathname=='/submit') {
window.onload = autoSuggestTitle(); window.onload = autoSuggestTitle();
} }
document.addEventListener('paste', function (event) { document.addEventListener('paste', function (event) {
var nothingFocused = document.activeElement === document.body; var nothingFocused = document.activeElement === document.body;
if (nothingFocused) { if (nothingFocused) {
var clipText = event.clipboardData.getData('Text'); var clipText = event.clipboardData.getData('Text');
var url = new RegExp('^(?:[a-z]+:)?//', 'i'); var url = new RegExp('^(?:[a-z]+:)?//', 'i');
if (url.test(clipText) && window.location.pathname !== '/submit') { if (url.test(clipText) && window.location.pathname !== '/submit') {
window.location.href = '/submit?url=' + clipText; window.location.href = '/submit?url=' + clipText;
} }
else if (url.test(clipText) && window.location.pathname == '/submit') { else if (url.test(clipText) && window.location.pathname == '/submit') {
document.getElementById("post-URL").value = clipText; document.getElementById("post-URL").value = clipText;
autoSuggestTitle() autoSuggestTitle()
} }
} }
}); });
function checkForRequired() { function checkForRequired() {
var title = document.getElementById("post-title"); var title = document.getElementById("post-title");
var url = document.getElementById("post-URL"); var url = document.getElementById("post-URL");
var text = document.getElementById("post-text"); var text = document.getElementById("post-text");
var button = document.getElementById("create_button"); var button = document.getElementById("create_button");
var image = document.getElementById("file-upload"); var image = document.getElementById("file-upload");
if (url.value.length > 0 || image.value.length > 0) { if (url.value.length > 0 || image.value.length > 0) {
text.required = false; text.required = false;
url.required=false; url.required=false;
} else if (text.value.length > 0 || image.value.length > 0) { } else if (text.value.length > 0 || image.value.length > 0) {
url.required = false; url.required = false;
} else { } else {
text.required = true; text.required = true;
url.required = true; url.required = true;
} }
var isValidTitle = title.checkValidity(); var isValidTitle = title.checkValidity();
var isValidURL = url.checkValidity(); var isValidURL = url.checkValidity();
var isValidText = text.checkValidity(); var isValidText = text.checkValidity();
if (isValidTitle && (isValidURL || image.value.length>0)) { if (isValidTitle && (isValidURL || image.value.length>0)) {
button.disabled = false; button.disabled = false;
} else if (isValidTitle && isValidText) { } else if (isValidTitle && isValidText) {
button.disabled = false; button.disabled = false;
} else { } else {
button.disabled = true; button.disabled = true;
} }
} }
function markdown() { function markdown() {
var input = document.getElementById('post-text').value; var input = document.getElementById('post-text').value;
var emojis = Array.from(input.matchAll(/:(.{1,30}?):/gi)) var emojis = Array.from(input.matchAll(/:(.{1,30}?):/gi))
if(emojis != null){ if(emojis != null){
for(i = 0; i < emojis.length; i++){ for(i = 0; i < emojis.length; i++){
var emoji = emojis[i][0] var emoji = emojis[i][0]
var remoji = emoji.replace(/:/g,''); var remoji = emoji.replace(/:/g,'');
if (remoji.startsWith("!")) if (remoji.startsWith("!"))
{ {
input = input.replace(emoji, "<img height=30 src='/assets/images/emojis/" + remoji.substring(1) + ".webp' class='mirrored'>") input = input.replace(emoji, "<img height=30 src='/assets/images/emojis/" + remoji.substring(1) + ".webp' class='mirrored'>")
} else { } else {
input = input.replace(emoji, "<img height=30 src='/assets/images/emojis/" + remoji + ".webp'>") input = input.replace(emoji, "<img height=30 src='/assets/images/emojis/" + remoji + ".webp'>")
} }
} }
} }
document.getElementById('preview').innerHTML = marked(input) document.getElementById('preview').innerHTML = marked(input)
} }
document.onpaste = function(event) { document.onpaste = function(event) {
f=document.getElementById('file-upload'); f=document.getElementById('file-upload');
files = event.clipboardData.files files = event.clipboardData.files
filename = files[0].name.toLowerCase() filename = files[0].name.toLowerCase()
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".webp") || filename.endsWith(".gif")) if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".webp") || filename.endsWith(".gif"))
{ {
f.files = files; f.files = files;
document.getElementById('filename-show').textContent = filename; document.getElementById('filename-show').textContent = filename;
document.getElementById('urlblock').classList.add('d-none'); document.getElementById('urlblock').classList.add('d-none');
var fileReader = new FileReader(); var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]); fileReader.readAsDataURL(f.files[0]);
fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);}); fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);});
document.getElementById('file-upload').setAttribute('required', 'false'); document.getElementById('file-upload').setAttribute('required', 'false');
checkForRequired(); checkForRequired();
} }
} }
document.getElementById('file-upload').addEventListener('change', function(){ document.getElementById('file-upload').addEventListener('change', function(){
f=document.getElementById('file-upload'); f=document.getElementById('file-upload');
document.getElementById('urlblock').classList.add('d-none'); document.getElementById('urlblock').classList.add('d-none');
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name; document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name;
filename = f.files[0].name.toLowerCase() filename = f.files[0].name.toLowerCase()
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".webp") || filename.endsWith(".webp")) if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".webp") || filename.endsWith(".webp"))
{ {
var fileReader = new FileReader(); var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]); fileReader.readAsDataURL(f.files[0]);
fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);}); fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);});
checkForRequired(); checkForRequired();
} }
}) })

File diff suppressed because one or more lines are too long

View file

@ -1,93 +1,93 @@
function post_toast_callback(url, data, callback) { function post_toast_callback(url, data, callback) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", url, true); xhr.open("POST", url, true);
var form = new FormData() var 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]);
} }
} }
form.append("formkey", formkey()); form.append("formkey", formkey());
xhr.withCredentials=true; xhr.withCredentials=true;
xhr.onload = function() { xhr.onload = function() {
let result = callback(xhr); let result = callback(xhr);
if (xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300) {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.show(); myToast.show();
try { try {
if(typeof result == "string") { if(typeof result == "string") {
document.getElementById('toast-post-success-text').innerText = result; document.getElementById('toast-post-success-text').innerText = result;
} else { } else {
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"]; document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
} }
} catch(e) { } catch(e) {
document.getElementById('toast-post-success-text').innerText = "Action successful!"; document.getElementById('toast-post-success-text').innerText = "Action successful!";
} }
return true; return true;
} else { } else {
var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success'));
myToast.hide(); myToast.hide();
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error')); var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show(); myToast.show();
try { try {
if(typeof result == "string") { if(typeof result == "string") {
document.getElementById('toast-post-error-text').innerText = result; document.getElementById('toast-post-error-text').innerText = result;
} else { } else {
document.getElementById('toast-post-error-text').innerText = JSON.parse(xhr.response)["error"]; document.getElementById('toast-post-error-text').innerText = JSON.parse(xhr.response)["error"];
} }
return false return false
} catch(e) { } catch(e) {
document.getElementById('toast-post-error-text').innerText = "Error. Please try again later."; document.getElementById('toast-post-error-text').innerText = "Error. Please try again later.";
} }
return false; return false;
} }
}; };
xhr.send(form); xhr.send(form);
} }
const TRANSFER_TAX = 0.01; const TRANSFER_TAX = 0.01;
window.addEventListener( 'load', function() { window.addEventListener( 'load', function() {
var userid = document.getElementById("userid").value; var userid = document.getElementById("userid").value;
if (userid != "nosong") if (userid != "nosong")
{ {
var audio = new Audio(`/songs/${userid}`); var audio = new Audio(`/songs/${userid}`);
audio.loop=true; audio.loop=true;
audio.play(); audio.play();
document.getElementById('userpage').addEventListener('click', () => { document.getElementById('userpage').addEventListener('click', () => {
if (audio.paused) audio.play(); if (audio.paused) audio.play();
}, {once : true}); }, {once : true});
} }
}, false ); }, false );
function updateTax(mobile=false) { function updateTax(mobile=false) {
let suf = mobile ? "-mobile" : ""; let suf = mobile ? "-mobile" : "";
let amount = parseInt(document.getElementById("coins-transfer-amount" + suf).value); let amount = parseInt(document.getElementById("coins-transfer-amount" + suf).value);
if(isNaN(amount) || amount < 0) { if(isNaN(amount) || amount < 0) {
amount = 0; amount = 0;
} }
document.getElementById("coins-transfer-taxed" + suf).innerText = amount - Math.ceil(amount*TRANSFER_TAX); document.getElementById("coins-transfer-taxed" + suf).innerText = amount - Math.ceil(amount*TRANSFER_TAX);
} }
function toggleElement(group, id) { function toggleElement(group, id) {
for(let el of document.getElementsByClassName(group)) { for(let el of document.getElementsByClassName(group)) {
if(el.id != id) { if(el.id != id) {
el.classList.add('d-none'); el.classList.add('d-none');
} }
} }
document.getElementById(id).classList.toggle('d-none'); document.getElementById(id).classList.toggle('d-none');
} }

View file

@ -33,7 +33,7 @@
{% if v %} {% if v %}
{% include "award_modal.html" %} {% include "award_modal.html" %}
<script src="/assets/js/comments_v.js?v=14"></script> <script src="/assets/js/comments_v.js?v=24"></script>
{% endif %} {% endif %}
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>

View file

@ -53,7 +53,7 @@
</script> </script>
{% if v %} {% if v %}
<script src="/assets/js/comments_v.js?v=14"></script> <script src="/assets/js/comments_v.js?v=24"></script>
{% include "award_modal.html" %} {% include "award_modal.html" %}
{% include "emoji_modal.html" %} {% include "emoji_modal.html" %}
{% include "gif_modal.html" %} {% include "gif_modal.html" %}