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) => {
|
2023-08-06 03:33:34 +00:00
|
|
|
if (!((e.ctrlKey || e.metaKey) && e.key === "Enter")) return;
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
const targetDOM = document.activeElement;
|
2023-08-06 03:33:34 +00:00
|
|
|
if (!(targetDOM instanceof HTMLInputElement)) return;
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
reportCommentButton.click()
|
2023-10-02 06:04:05 +00:00
|
|
|
bootstrap.Modal.getOrCreateInstance(document.getElementById('reportCommentModal')).hide()
|
2022-07-16 21:00:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function report_commentModal(id, author) {
|
|
|
|
document.getElementById("comment-author").textContent = author;
|
|
|
|
|
|
|
|
reportCommentButton.innerHTML='Report comment';
|
|
|
|
reportCommentButton.disabled = false;
|
|
|
|
reportCommentButton.classList.remove('disabled');
|
2023-05-01 18:30:28 +00:00
|
|
|
reportCommentButton.dataset.id = id
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
reason_comment.value = ""
|
|
|
|
setTimeout(() => {
|
|
|
|
reason_comment.focus()
|
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
2023-05-01 18:30:28 +00:00
|
|
|
reportCommentButton.onclick = function() {
|
|
|
|
this.innerHTML='Reporting comment';
|
|
|
|
this.disabled = true;
|
|
|
|
this.classList.add('disabled');
|
|
|
|
|
|
|
|
postToast(this, '/report/comment/' + reportCommentButton.dataset.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;
|
|
|
|
}
|
|
|
|
|
2023-08-02 07:43:38 +00:00
|
|
|
function toggleReplyBox(t, id) {
|
2022-07-16 21:00:02 +00:00
|
|
|
const element = document.getElementById(id);
|
2023-02-27 15:02:35 +00:00
|
|
|
const ta = element.getElementsByTagName('textarea')[0]
|
2023-03-21 18:13:53 +00:00
|
|
|
element.classList.remove('d-none')
|
2022-07-23 08:53:43 +00:00
|
|
|
|
2023-03-21 18:13:53 +00:00
|
|
|
let text = getSelection().toString().trim()
|
|
|
|
if (text)
|
2022-07-16 21:00:02 +00:00
|
|
|
{
|
2023-03-21 18:13:53 +00:00
|
|
|
text = '> ' + text
|
|
|
|
text = text.replace(/\n/g,"\n> ")
|
|
|
|
text = text.replace(/\n> \n/g,"\n \n")
|
|
|
|
text = text.split('> Reply')[0]
|
|
|
|
text = text.replace(/\*/g,"\\*")
|
|
|
|
|
|
|
|
if (ta.value && !ta.value.endsWith('\n')) ta.value += '\n'
|
|
|
|
ta.value += text
|
|
|
|
if (!ta.value.endsWith('\n')) ta.value += '\n'
|
2023-08-29 06:06:02 +00:00
|
|
|
markdown(ta);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2023-03-21 18:13:53 +00:00
|
|
|
ta.focus()
|
2022-11-09 17:23:21 +00:00
|
|
|
|
2023-02-27 15:02:35 +00:00
|
|
|
autoExpand(ta);
|
2023-08-02 07:43:38 +00:00
|
|
|
|
|
|
|
let newHTML = ''
|
|
|
|
if (t.innerHTML.includes('<i class="fas fa-'))
|
|
|
|
newHTML += '<i class="fas fa-quotes"></i>'
|
2023-08-14 14:29:06 +00:00
|
|
|
if (t.textContent)
|
2023-08-02 07:43:38 +00:00
|
|
|
newHTML += 'Quote selection'
|
|
|
|
t.innerHTML = newHTML
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleEdit(id){
|
2023-10-02 04:58:25 +00:00
|
|
|
const comment = document.getElementById("comment-text-"+id);
|
|
|
|
const form = document.getElementById("comment-edit-"+id);
|
|
|
|
const box = document.getElementById('comment-edit-body-'+id);
|
|
|
|
const actions = document.getElementById('comment-' + id +'-actions');
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
comment.classList.toggle("d-none");
|
|
|
|
form.classList.toggle("d-none");
|
|
|
|
actions.classList.toggle("d-none");
|
2023-10-02 04:58:25 +00:00
|
|
|
|
|
|
|
if (comment.classList.contains('d-none')) {
|
|
|
|
autoExpand(box);
|
|
|
|
markdown(box);
|
|
|
|
charLimit(box.id, 'charcount-edit-' + id)
|
|
|
|
}
|
2023-07-01 00:13:57 +00:00
|
|
|
|
|
|
|
close_inline_speed_emoji_modal();
|
2022-07-16 21:00:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-09-01 08:15:33 +00:00
|
|
|
const deleteCommentButton = document.getElementById("deleteCommentButton");
|
|
|
|
|
|
|
|
function delete_commentModal(id) {
|
|
|
|
deleteCommentButton.dataset.id = id
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteCommentButton.onclick = () => {
|
|
|
|
const id = deleteCommentButton.dataset.id
|
|
|
|
postToast(deleteCommentButton, `/delete/comment/${id}`,
|
|
|
|
{},
|
|
|
|
() => {
|
|
|
|
if (location.pathname == '/admin/reported/comments')
|
2022-11-18 21:27:53 +00:00
|
|
|
{
|
2023-09-01 08:15:33 +00:00
|
|
|
document.getElementById("post-info-"+id).remove()
|
|
|
|
document.getElementById("comment-"+id).remove()
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2023-09-01 08:15:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2023-07-07 23:00:37 +00:00
|
|
|
function post_reply(id) {
|
|
|
|
close_inline_speed_emoji_modal();
|
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
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);
|
2023-02-27 15:02:35 +00:00
|
|
|
|
|
|
|
const ta = document.getElementById('reply-form-body-'+id)
|
|
|
|
form.append('body', ta.value);
|
2022-07-16 21:00:02 +00:00
|
|
|
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
|
|
|
|
2023-08-12 10:35:59 +00:00
|
|
|
const xhr = createXhrWithFormKey("/reply", form);
|
2023-02-27 17:25:38 +00:00
|
|
|
|
|
|
|
const upload_prog = document.getElementById(`upload-prog-c_${id}`);
|
|
|
|
xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
|
|
|
|
|
2023-03-10 03:21:02 +00:00
|
|
|
xhr[0].onload=function(){
|
2023-02-27 17:25:38 +00:00
|
|
|
upload_prog.classList.add("d-none")
|
|
|
|
|
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)}
|
2023-03-12 09:54:14 +00:00
|
|
|
catch(e) {console.error(e)}
|
2022-07-16 21:00:02 +00:00
|
|
|
if (data && data["comment"]) {
|
2022-09-20 19:06:26 +00:00
|
|
|
const comments = document.getElementById('replies-of-c_' + id);
|
2023-10-02 04:39:54 +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}"`).replace(/ loading="lazy"/g, '');
|
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');
|
|
|
|
|
2023-02-27 15:02:35 +00:00
|
|
|
ta.value = ''
|
2022-09-20 19:06:26 +00:00
|
|
|
document.getElementById('message-reply-'+id).innerHTML = ''
|
2023-08-03 07:33:57 +00:00
|
|
|
document.getElementById('reply-to-c_'+id).classList.add('d-none')
|
2023-02-27 15:02:35 +00:00
|
|
|
|
|
|
|
const input = ta.parentElement.querySelector('input[type="file"]')
|
|
|
|
input.previousElementSibling.innerHTML = '';
|
|
|
|
input.value = null;
|
2023-08-08 10:52:07 +00:00
|
|
|
oldfiles[ta.id] = new DataTransfer();
|
2023-08-03 07:13:10 +00:00
|
|
|
|
2023-08-03 08:08:12 +00:00
|
|
|
remove_dialog();
|
2023-08-03 07:33:57 +00:00
|
|
|
restore_reply_buttons(`c_${id}`)
|
2022-10-14 10:15:06 +00:00
|
|
|
} else {
|
|
|
|
showToast(false, getMessageFromJsonData(false, data));
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2023-03-09 19:41:08 +00:00
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function comment_edit(id){
|
|
|
|
const btn = document.getElementById(`edit-btn-${id}`)
|
|
|
|
btn.disabled = true
|
|
|
|
btn.classList.add('disabled');
|
|
|
|
|
2023-02-27 15:02:35 +00:00
|
|
|
const ta = document.getElementById('comment-edit-body-'+id)
|
|
|
|
|
2022-07-23 08:57:53 +00:00
|
|
|
const form = new FormData();
|
2023-02-27 15:02:35 +00:00
|
|
|
form.append('body', ta.value);
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
for (const e of document.getElementById('file-edit-reply-'+id).files)
|
|
|
|
form.append('file', e);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2023-08-12 10:35:59 +00:00
|
|
|
const xhr = createXhrWithFormKey("/edit_comment/"+id, form);
|
2023-02-27 17:25:38 +00:00
|
|
|
|
|
|
|
const upload_prog = document.getElementById(`upload-prog-edit-c_${id}`);
|
|
|
|
xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
|
|
|
|
|
2023-03-10 03:21:02 +00:00
|
|
|
xhr[0].onload=function(){
|
2023-02-27 17:25:38 +00:00
|
|
|
upload_prog.classList.add("d-none")
|
|
|
|
|
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)}
|
2023-03-12 09:54:14 +00:00
|
|
|
catch(e) {console.error(e)}
|
2022-07-16 21:00:02 +00:00
|
|
|
if (data && data["comment"]) {
|
|
|
|
commentForm=document.getElementById('comment-text-'+id);
|
2023-10-02 04:39:54 +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}"`).replace(/ loading="lazy"/g, '');
|
|
|
|
|
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-12-03 05:27:47 +00:00
|
|
|
document.getElementById('comment-edit-body-' + id).value = data["body"];
|
2023-02-27 15:02:35 +00:00
|
|
|
|
2023-08-14 06:55:32 +00:00
|
|
|
if (data["ping_cost"]) {
|
|
|
|
const ping_cost = document.getElementById('comment-ping-cost-' + id)
|
2023-08-14 14:29:06 +00:00
|
|
|
ping_cost.textContent = data["ping_cost"]
|
2023-08-14 06:55:32 +00:00
|
|
|
ping_cost.parentElement.classList.remove('d-none')
|
|
|
|
}
|
2023-08-13 16:03:29 +00:00
|
|
|
|
2023-08-14 07:04:48 +00:00
|
|
|
if (data["edited_string"]) {
|
|
|
|
const edited_string = document.getElementById('comment-edited_string-' + id)
|
2023-08-14 14:29:06 +00:00
|
|
|
edited_string.textContent = data["edited_string"]
|
2023-08-14 07:04:48 +00:00
|
|
|
edited_string.parentElement.classList.remove('d-none')
|
|
|
|
}
|
|
|
|
|
2023-02-27 15:02:35 +00:00
|
|
|
const input = ta.parentElement.querySelector('input[type="file"]')
|
|
|
|
input.previousElementSibling.innerHTML = '';
|
|
|
|
input.value = null;
|
2023-08-08 10:52:07 +00:00
|
|
|
oldfiles[ta.id] = new DataTransfer();
|
2023-08-03 07:13:10 +00:00
|
|
|
|
|
|
|
remove_dialog();
|
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
|
|
|
}
|
2023-03-09 19:41:08 +00:00
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
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){
|
2023-07-07 23:00:37 +00:00
|
|
|
close_inline_speed_emoji_modal();
|
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
const btn = document.getElementById('save-reply-to-'+fullname)
|
2023-02-27 15:02:35 +00:00
|
|
|
const ta = 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);
|
2023-02-27 15:02:35 +00:00
|
|
|
form.append('body', ta.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);
|
2023-02-27 17:25:38 +00:00
|
|
|
|
|
|
|
const upload_prog = document.getElementById(`upload-prog-${fullname}`);
|
|
|
|
xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
|
2023-05-05 21:45:25 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
xhr.setRequestHeader('xhr', 'xhr');
|
2023-03-10 03:21:02 +00:00
|
|
|
xhr.onload=function(){
|
2023-02-27 17:25:38 +00:00
|
|
|
upload_prog.classList.add("d-none")
|
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
let data
|
|
|
|
try {data = JSON.parse(xhr.response)}
|
2023-03-12 09:54:14 +00:00
|
|
|
catch(e) {console.error(e)}
|
2022-07-16 21:00:02 +00:00
|
|
|
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);
|
2023-10-02 04:39:54 +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}"`).replace(/ loading="lazy"/g, '');
|
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');
|
|
|
|
|
2023-02-27 15:02:35 +00:00
|
|
|
ta.value = ''
|
|
|
|
autoExpand(ta);
|
|
|
|
|
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 = ''
|
2023-02-27 15:02:35 +00:00
|
|
|
|
|
|
|
const input = ta.parentElement.querySelector('input[type="file"]')
|
|
|
|
input.previousElementSibling.innerHTML = '';
|
|
|
|
input.value = null;
|
2023-08-08 10:52:07 +00:00
|
|
|
oldfiles[ta.id] = new DataTransfer();
|
2023-07-25 18:41:24 +00:00
|
|
|
|
|
|
|
const ghost_town_box = document.getElementById('ghost-town-box')
|
|
|
|
if (ghost_town_box) ghost_town_box.remove()
|
2023-08-03 07:13:10 +00:00
|
|
|
|
2023-08-03 08:08:12 +00:00
|
|
|
remove_dialog();
|
|
|
|
if (fullname.startsWith('c_'))
|
|
|
|
restore_reply_buttons(fullname)
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-10-14 10:15:06 +00:00
|
|
|
showToast(false, getMessageFromJsonData(false, data));
|
2023-03-09 23:49:42 +00:00
|
|
|
btn.disabled = false;
|
|
|
|
btn.classList.remove('disabled');
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.send(form)
|
|
|
|
}
|
|
|
|
|
2023-08-03 07:33:57 +00:00
|
|
|
|
|
|
|
function restore_reply_buttons(fullname) {
|
|
|
|
const reply_buttons = [document.getElementById(`toggle-reply-${fullname}`)]
|
|
|
|
const mobile_reply_button = document.getElementById(`toggle-reply-${fullname}-mobile`)
|
|
|
|
if (mobile_reply_button) reply_buttons.push(mobile_reply_button)
|
|
|
|
for (const t of reply_buttons) {
|
|
|
|
let newHTML = ''
|
|
|
|
if (t.innerHTML.includes('<i class="fas fa-'))
|
|
|
|
newHTML += '<i class="fas fa-reply"></i>'
|
2023-08-14 14:29:06 +00:00
|
|
|
if (t.textContent)
|
2023-08-03 07:33:57 +00:00
|
|
|
newHTML += 'Reply'
|
|
|
|
t.innerHTML = newHTML
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancel(fullname) {
|
|
|
|
document.getElementById(`reply-to-${fullname}`).classList.add('d-none')
|
2023-08-03 08:08:12 +00:00
|
|
|
remove_dialog();
|
2023-08-03 07:33:57 +00:00
|
|
|
restore_reply_buttons(fullname)
|
|
|
|
}
|