2022-07-16 21:00:02 +00:00
|
|
|
const reason_comment = document.getElementById("reason_comment")
|
|
|
|
const reportCommentButton = document.getElementById("reportCommentButton");
|
|
|
|
|
|
|
|
reason_comment.addEventListener('keydown', (e) => {
|
|
|
|
if(!((e.ctrlKey || e.metaKey) && e.key === "Enter")) return;
|
|
|
|
|
|
|
|
const targetDOM = document.activeElement;
|
|
|
|
if(!(targetDOM instanceof HTMLInputElement)) return;
|
|
|
|
|
|
|
|
reportCommentButton.click()
|
|
|
|
bootstrap.Modal.getOrCreateInstance(document.getElementById('reportCommentModal')).hide()
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function report_commentModal(id, author) {
|
|
|
|
|
|
|
|
document.getElementById("comment-author").textContent = author;
|
|
|
|
|
|
|
|
reportCommentButton.innerHTML='Report comment';
|
|
|
|
reportCommentButton.disabled = false;
|
|
|
|
reportCommentButton.classList.remove('disabled');
|
|
|
|
|
|
|
|
reason_comment.value = ""
|
|
|
|
setTimeout(() => {
|
|
|
|
reason_comment.focus()
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
reportCommentButton.onclick = function() {
|
|
|
|
this.innerHTML='Reporting comment';
|
|
|
|
|
2022-11-18 21:32:48 +00:00
|
|
|
postToast(this, `/report/comment/${id}`,
|
|
|
|
{
|
|
|
|
"reason": reason_comment.value
|
|
|
|
},
|
|
|
|
() => {}
|
|
|
|
);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns the selection text based on the range with the HTML
|
|
|
|
function getSelectionTextHtml() {
|
|
|
|
let html = "";
|
|
|
|
let sel = getSelection();
|
|
|
|
if (sel.rangeCount) {
|
|
|
|
let container = document.createElement("div");
|
|
|
|
container.appendChild(sel.getRangeAt(0).cloneContents());
|
|
|
|
html += container.innerHTML;
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2022-12-09 03:35:28 +00:00
|
|
|
function toggleReplyBox(id) {
|
2022-07-16 21:00:02 +00:00
|
|
|
const element = document.getElementById(id);
|
|
|
|
const textarea = element.getElementsByTagName('textarea')[0]
|
2022-07-23 08:53:43 +00:00
|
|
|
element.classList.toggle('d-none')
|
|
|
|
|
|
|
|
if (!element.classList.contains('d-none'))
|
2022-07-16 21:00:02 +00:00
|
|
|
{
|
2022-07-23 08:53:43 +00:00
|
|
|
let text = getSelection().toString().trim()
|
|
|
|
if (text)
|
|
|
|
{
|
2022-11-09 17:31:53 +00:00
|
|
|
text = '> ' + text
|
|
|
|
text = text.replace(/\n/g,"\n> ").replace(/\*/g,"\\*")
|
|
|
|
text = text.replace(/\n> \n/g,"\n \n")
|
2022-11-12 08:16:45 +00:00
|
|
|
text = text.split('> Reply')[0]
|
2022-11-09 17:31:53 +00:00
|
|
|
if (!text.endsWith('\n')) text += '\n'
|
|
|
|
textarea.value = text
|
2022-07-23 08:53:43 +00:00
|
|
|
}
|
|
|
|
textarea.focus()
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2022-11-09 17:23:21 +00:00
|
|
|
|
|
|
|
autoExpand(textarea);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleEdit(id){
|
|
|
|
comment=document.getElementById("comment-text-"+id);
|
|
|
|
form=document.getElementById("comment-edit-"+id);
|
|
|
|
box=document.getElementById('comment-edit-body-'+id);
|
|
|
|
actions = document.getElementById('comment-' + id +'-actions');
|
|
|
|
|
|
|
|
comment.classList.toggle("d-none");
|
|
|
|
form.classList.toggle("d-none");
|
|
|
|
actions.classList.toggle("d-none");
|
|
|
|
autoExpand(box);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-11-18 21:27:53 +00:00
|
|
|
function delete_commentModal(t, id) {
|
2022-09-04 23:15:37 +00:00
|
|
|
document.getElementById("deleteCommentButton").onclick = function() {
|
2022-11-18 21:27:53 +00:00
|
|
|
postToast(t, `/delete/comment/${id}`,
|
|
|
|
{
|
|
|
|
},
|
|
|
|
() => {
|
2022-12-30 12:52:59 +00:00
|
|
|
if (location.pathname == '/admin/reported/comments')
|
2022-10-23 16:24:17 +00:00
|
|
|
{
|
|
|
|
document.getElementById("post-info-"+id).remove()
|
|
|
|
document.getElementById("comment-"+id).remove()
|
|
|
|
}
|
|
|
|
else
|
2023-01-01 11:36:20 +00:00
|
|
|
{
|
2022-10-23 16:24:17 +00:00
|
|
|
document.getElementsByClassName(`comment-${id}-only`)[0].classList.add('deleted');
|
|
|
|
document.getElementById(`delete-${id}`).classList.add('d-none');
|
|
|
|
document.getElementById(`undelete-${id}`).classList.remove('d-none');
|
|
|
|
document.getElementById(`delete2-${id}`).classList.add('d-none');
|
|
|
|
document.getElementById(`undelete2-${id}`).classList.remove('d-none');
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2022-11-18 21:27:53 +00:00
|
|
|
);
|
2022-07-16 21:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function post_reply(id){
|
|
|
|
const btn = document.getElementById(`save-reply-to-${id}`)
|
|
|
|
btn.disabled = true;
|
|
|
|
btn.classList.add('disabled');
|
|
|
|
|
2022-07-23 08:57:53 +00:00
|
|
|
const form = new FormData();
|
2022-07-16 21:00:02 +00:00
|
|
|
form.append('parent_id', id);
|
|
|
|
form.append('body', document.getElementById('reply-form-body-'+id).value);
|
|
|
|
try {
|
2023-01-23 11:04:07 +00:00
|
|
|
for (const e of document.getElementById(`file-upload-reply-c_${id}`).files)
|
2022-07-16 21:00:02 +00:00
|
|
|
form.append('file', e);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-10-14 12:01:11 +00:00
|
|
|
const xhr = createXhrWithFormKey("/reply", "POST", form);
|
|
|
|
xhr[0].onload=function(){
|
2022-07-16 21:00:02 +00:00
|
|
|
let data
|
2022-10-14 12:01:11 +00:00
|
|
|
try {data = JSON.parse(xhr[0].response)}
|
2022-07-16 21:00:02 +00:00
|
|
|
catch(e) {console.log(e)}
|
|
|
|
if (data && data["comment"]) {
|
2022-09-20 19:06:26 +00:00
|
|
|
const comments = document.getElementById('replies-of-c_' + id);
|
2022-12-30 13:17:04 +00:00
|
|
|
const comment = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '').replace(/data-nonce=".*?"/g, `data-nonce="${nonce}"`);
|
2022-12-07 20:27:22 +00:00
|
|
|
|
|
|
|
comments.insertAdjacentHTML('beforeend', comment);
|
2022-09-20 19:06:26 +00:00
|
|
|
|
2023-01-01 07:55:25 +00:00
|
|
|
register_new_elements(comments);
|
2022-09-20 19:06:26 +00:00
|
|
|
bs_trigger(comments);
|
|
|
|
|
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
|
|
|
|
|
|
|
document.getElementById('reply-form-body-'+id).value = ''
|
|
|
|
document.getElementById('message-reply-'+id).innerHTML = ''
|
2022-12-14 04:16:43 +00:00
|
|
|
toggleReplyBox('reply-message-c_'+id)
|
2023-01-23 11:04:07 +00:00
|
|
|
const fileupload = document.getElementById(`file-upload-reply-c_${id}`)
|
2022-12-09 06:50:28 +00:00
|
|
|
if (fileupload) {
|
|
|
|
fileupload.value = null;
|
2023-01-23 11:04:07 +00:00
|
|
|
document.getElementById(`filename-show-reply-c_${id}`).innerHTML = '<i class="fas fa-file"></i>';
|
2022-12-09 06:50:28 +00:00
|
|
|
}
|
2022-10-14 10:15:06 +00:00
|
|
|
} else {
|
|
|
|
showToast(false, getMessageFromJsonData(false, data));
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
|
|
|
}, 2000);
|
|
|
|
}
|
2022-10-14 12:01:11 +00:00
|
|
|
xhr[0].send(xhr[1]);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function comment_edit(id){
|
|
|
|
const btn = document.getElementById(`edit-btn-${id}`)
|
|
|
|
btn.disabled = true
|
|
|
|
btn.classList.add('disabled');
|
|
|
|
|
2022-07-23 08:57:53 +00:00
|
|
|
const form = new FormData();
|
2022-07-16 21:00:02 +00:00
|
|
|
form.append('body', document.getElementById('comment-edit-body-'+id).value);
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (const e of document.getElementById('file-edit-reply-'+id).files)
|
|
|
|
form.append('file', e);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2022-10-14 15:43:58 +00:00
|
|
|
const xhr = createXhrWithFormKey("/edit_comment/"+id, "POST", form);
|
2022-10-14 12:01:11 +00:00
|
|
|
xhr[0].onload=function(){
|
2022-07-16 21:00:02 +00:00
|
|
|
let data
|
2022-10-14 12:01:11 +00:00
|
|
|
try {data = JSON.parse(xhr[0].response)}
|
2022-07-16 21:00:02 +00:00
|
|
|
catch(e) {console.log(e)}
|
|
|
|
if (data && data["comment"]) {
|
|
|
|
commentForm=document.getElementById('comment-text-'+id);
|
2022-12-30 13:17:04 +00:00
|
|
|
commentForm.innerHTML = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '').replace(/data-nonce=".*?"/g, `data-nonce="${nonce}"`)
|
2022-07-16 21:00:02 +00:00
|
|
|
document.getElementById('cancel-edit-'+id).click()
|
2023-01-01 07:55:25 +00:00
|
|
|
|
|
|
|
register_new_elements(commentForm);
|
2022-07-16 21:00:02 +00:00
|
|
|
bs_trigger(commentForm);
|
2023-01-01 07:55:25 +00:00
|
|
|
|
2022-08-06 14:04:34 +00:00
|
|
|
document.getElementById('filename-edit-reply-' + id).innerHTML = '<i class="fas fa-file"></i>';
|
2022-12-03 05:27:47 +00:00
|
|
|
document.getElementById('comment-edit-body-' + id).value = data["body"];
|
2022-12-07 16:51:51 +00:00
|
|
|
document.getElementById('file-edit-reply-'+id).value = null;
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-10-14 10:15:06 +00:00
|
|
|
showToast(false, getMessageFromJsonData(false, data));
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
2022-08-06 14:04:34 +00:00
|
|
|
}, 1000);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2022-10-14 12:01:11 +00:00
|
|
|
xhr[0].send(xhr[1]);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-21 11:48:27 +00:00
|
|
|
function post_comment(fullname, hide){
|
2022-07-16 21:00:02 +00:00
|
|
|
const btn = document.getElementById('save-reply-to-'+fullname)
|
2022-12-24 23:21:52 +00:00
|
|
|
const textArea = document.getElementById('reply-form-body-'+fullname)
|
2022-07-16 21:00:02 +00:00
|
|
|
btn.disabled = true
|
|
|
|
btn.classList.add('disabled');
|
|
|
|
|
2022-07-23 08:57:53 +00:00
|
|
|
const form = new FormData();
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
form.append('formkey', formkey());
|
|
|
|
form.append('parent_fullname', fullname);
|
2022-12-24 23:21:52 +00:00
|
|
|
form.append('body', textArea.value);
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
for (const e of document.getElementById('file-upload-reply-'+fullname).files)
|
|
|
|
form.append('file', e);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
const xhr = new XMLHttpRequest();
|
2022-12-30 07:35:32 +00:00
|
|
|
url = '/comment';
|
|
|
|
xhr.open("POST", url);
|
2022-07-16 21:00:02 +00:00
|
|
|
xhr.setRequestHeader('xhr', 'xhr');
|
|
|
|
xhr.onload=function(){
|
|
|
|
let data
|
|
|
|
try {data = JSON.parse(xhr.response)}
|
|
|
|
catch(e) {console.log(e)}
|
|
|
|
if (data && data["comment"]) {
|
2022-07-23 09:08:02 +00:00
|
|
|
if (hide) document.getElementById(hide).classList.add('d-none');
|
2022-07-23 08:53:17 +00:00
|
|
|
|
|
|
|
let name = 'comment-form-space-' + fullname;
|
|
|
|
commentForm = document.getElementById(name);
|
|
|
|
|
2022-07-23 09:08:02 +00:00
|
|
|
let comments = document.getElementById('replies-of-' + fullname);
|
2022-12-30 13:17:04 +00:00
|
|
|
let comment = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '').replace(/data-nonce=".*?"/g, `data-nonce="${nonce}"`);
|
2022-07-23 08:53:17 +00:00
|
|
|
|
2022-12-07 20:27:22 +00:00
|
|
|
comments.insertAdjacentHTML('afterbegin', comment);
|
2022-07-23 08:53:17 +00:00
|
|
|
|
2023-01-01 07:55:25 +00:00
|
|
|
register_new_elements(comments);
|
2022-09-08 17:12:46 +00:00
|
|
|
bs_trigger(comments);
|
2022-07-23 08:53:17 +00:00
|
|
|
|
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
|
|
|
|
|
|
|
document.getElementById('reply-form-body-'+fullname).value = ''
|
2022-07-23 09:19:47 +00:00
|
|
|
document.getElementById('form-preview-'+fullname).innerHTML = ''
|
2022-11-18 20:53:54 +00:00
|
|
|
document.getElementById('charcount-'+fullname).innerHTML = ''
|
2022-08-05 20:00:16 +00:00
|
|
|
document.getElementById('filename-show-reply-' + fullname).innerHTML = '<i class="fas fa-file"></i>';
|
2022-12-07 16:51:51 +00:00
|
|
|
document.getElementById('file-upload-reply-'+fullname).value = null;
|
2022-12-24 23:21:52 +00:00
|
|
|
autoExpand(textArea);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-10-14 10:15:06 +00:00
|
|
|
showToast(false, getMessageFromJsonData(false, data));
|
2022-07-23 08:53:17 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
|
|
|
}, 2000);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.send(form)
|
|
|
|
}
|
|
|
|
|
|
|
|
document.onpaste = function(event) {
|
2022-12-04 15:40:32 +00:00
|
|
|
const focused = document.activeElement;
|
2022-11-13 14:16:42 +00:00
|
|
|
const files = structuredClone(event.clipboardData.files);
|
2022-10-11 17:13:50 +00:00
|
|
|
|
|
|
|
if (files.length > 4)
|
|
|
|
{
|
|
|
|
alert("You can't upload more than 4 files at one time!")
|
|
|
|
return
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2022-10-11 17:13:50 +00:00
|
|
|
|
|
|
|
if (!files.length) return
|
|
|
|
|
|
|
|
if (focused.id.includes('reply-form-body-')) {
|
2022-12-04 15:40:32 +00:00
|
|
|
const fullname = focused.dataset.fullname;
|
2022-10-11 17:13:50 +00:00
|
|
|
f=document.getElementById('file-upload-reply-' + fullname);
|
|
|
|
try {
|
2022-07-16 21:00:02 +00:00
|
|
|
let filename = ''
|
|
|
|
for (const file of files)
|
|
|
|
filename += file.name + ', '
|
2022-11-07 22:21:03 +00:00
|
|
|
filename = filename.toLowerCase().slice(0, -2)
|
2022-07-16 21:00:02 +00:00
|
|
|
f.files = files;
|
2022-10-11 17:13:50 +00:00
|
|
|
document.getElementById('filename-show-reply-' + fullname).textContent = filename;
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2022-10-11 17:13:50 +00:00
|
|
|
catch(e) {}
|
|
|
|
}
|
|
|
|
else if (focused.id.includes('comment-edit-body-')) {
|
2022-12-04 15:40:32 +00:00
|
|
|
const id = focused.dataset.id;
|
2022-10-11 17:13:50 +00:00
|
|
|
f=document.getElementById('file-edit-reply-' + id);
|
|
|
|
let filename = ''
|
|
|
|
for (const file of files)
|
|
|
|
filename += file.name + ', '
|
2022-11-07 22:21:03 +00:00
|
|
|
filename = filename.toLowerCase().slice(0, -2)
|
2022-10-11 17:13:50 +00:00
|
|
|
f.files = files;
|
|
|
|
document.getElementById('filename-edit-reply-' + id).textContent = filename;
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
else if (focused.id.includes('post-edit-box-')) {
|
2022-12-04 15:40:32 +00:00
|
|
|
const id = focused.dataset.id;
|
2022-10-11 17:13:50 +00:00
|
|
|
f=document.getElementById('file-upload-edit-' + id);
|
|
|
|
let filename = ''
|
|
|
|
for (const file of files)
|
|
|
|
filename += file.name + ', '
|
2022-11-07 22:21:03 +00:00
|
|
|
filename = filename.toLowerCase().slice(0, -2)
|
2022-10-11 17:13:50 +00:00
|
|
|
f.files = files;
|
|
|
|
document.getElementById('filename-show-edit-' + id).textContent = filename;
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2023-01-23 12:00:04 +00:00
|
|
|
else if (focused.id == "input-message") {
|
|
|
|
f=document.getElementById('file-upload');
|
|
|
|
let filename = ''
|
|
|
|
for (const file of files)
|
|
|
|
filename += file.name + ', '
|
|
|
|
filename = filename.toLowerCase().slice(0, -2)
|
|
|
|
f.files = files;
|
|
|
|
document.getElementById('filename').textContent = filename;
|
|
|
|
}
|
2023-01-24 10:19:20 +00:00
|
|
|
else if (focused.id == "input-message-mobile") {
|
|
|
|
f=document.getElementById('file-upload-mobile');
|
|
|
|
let filename = ''
|
|
|
|
for (const file of files)
|
|
|
|
filename += file.name + ', '
|
|
|
|
filename = filename.toLowerCase().slice(0, -2)
|
|
|
|
f.files = files;
|
|
|
|
document.getElementById('filename-mobile').textContent = filename;
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function handle_action(type, cid, thing) {
|
|
|
|
const btns = document.getElementsByClassName(`action-${cid}`)
|
|
|
|
for (const btn of btns)
|
|
|
|
{
|
|
|
|
btn.disabled = true;
|
|
|
|
btn.classList.add('disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
const form = new FormData();
|
|
|
|
form.append('formkey', formkey());
|
|
|
|
form.append('comment_id', cid);
|
|
|
|
form.append('thing', thing);
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("post", `/${type}/${cid}`);
|
|
|
|
xhr.setRequestHeader('xhr', 'xhr');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xhr.onload=function(){
|
|
|
|
let data
|
|
|
|
try {data = JSON.parse(xhr.response)}
|
|
|
|
catch(e) {console.log(e)}
|
|
|
|
if (data && data["response"]) {
|
|
|
|
const element = document.getElementById(`${type}-${cid}`);
|
|
|
|
element.innerHTML = data["response"]
|
2022-10-14 10:15:06 +00:00
|
|
|
} else {
|
|
|
|
showToast(false, getMessageFromJsonData(false, data));
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
for (const btn of btns)
|
2022-09-04 23:15:37 +00:00
|
|
|
{
|
2022-07-16 21:00:02 +00:00
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
xhr.send(form)
|
|
|
|
}
|