2022-07-16 21:00:02 +00:00
|
|
|
function pinned_timestamp(id) {
|
|
|
|
const el = document.getElementById(id)
|
2022-09-04 23:15:37 +00:00
|
|
|
const pintooltip = el.getAttribute("data-bs-original-title")
|
2022-11-22 22:36:33 +00:00
|
|
|
if (!pintooltip.includes('until'))
|
|
|
|
{
|
|
|
|
const time = formatDate(new Date(parseInt(el.dataset.timestamp)*1000))
|
|
|
|
el.setAttribute("data-bs-original-title", `${pintooltip} until ${time}`)
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function post(url) {
|
2022-10-14 12:01:11 +00:00
|
|
|
const xhr = createXhrWithFormKey(url);
|
|
|
|
xhr[0].send(xhr[1]);
|
2022-07-16 21:00:02 +00:00
|
|
|
};
|
|
|
|
|
2023-08-03 06:50:22 +00:00
|
|
|
function option_vote_0(oid, parentid, kind) {
|
2022-11-11 19:02:57 +00:00
|
|
|
for(let el of document.getElementsByClassName('presult-'+parentid)) {
|
|
|
|
el.classList.remove('d-none');
|
|
|
|
}
|
2023-08-12 11:12:50 +00:00
|
|
|
const full_oid = `option-${kind}-${oid}`
|
2022-09-05 23:33:58 +00:00
|
|
|
const type = document.getElementById(full_oid).checked;
|
|
|
|
const scoretext = document.getElementById('score-' + full_oid);
|
|
|
|
const score = Number(scoretext.textContent);
|
2022-07-16 21:00:02 +00:00
|
|
|
if (type == true) scoretext.textContent = score + 1;
|
|
|
|
else scoretext.textContent = score - 1;
|
2022-09-05 23:33:58 +00:00
|
|
|
post(`/vote/${kind}/option/${oid}`);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 06:50:22 +00:00
|
|
|
function option_vote_1(oid, parentid, kind) {
|
2022-11-11 19:02:57 +00:00
|
|
|
for(let el of document.getElementsByClassName('presult-'+parentid)) {
|
|
|
|
el.classList.remove('d-none');
|
|
|
|
}
|
2023-08-12 11:12:50 +00:00
|
|
|
const full_oid = `option-${kind}-${oid}`
|
|
|
|
let curr = document.getElementById(`current-option-${kind}-${parentid}`)
|
2022-07-16 21:00:02 +00:00
|
|
|
if (curr && curr.value)
|
|
|
|
{
|
2022-09-05 23:33:58 +00:00
|
|
|
const scoretext = document.getElementById('score-' + curr.value);
|
2023-11-15 07:51:19 +00:00
|
|
|
if (scoretext) {
|
|
|
|
const score = Number(scoretext.textContent);
|
|
|
|
scoretext.textContent = score - 1;
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 23:33:58 +00:00
|
|
|
const scoretext = document.getElementById('score-' + full_oid);
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2022-09-05 23:33:58 +00:00
|
|
|
const score = Number(scoretext.textContent);
|
2022-07-16 21:00:02 +00:00
|
|
|
scoretext.textContent = score + 1;
|
2022-09-05 23:33:58 +00:00
|
|
|
post(`/vote/${kind}/option/${oid}`);
|
|
|
|
curr.value = full_oid
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 06:50:22 +00:00
|
|
|
function option_vote_2(t, oid, kind) {
|
2023-03-12 17:36:35 +00:00
|
|
|
postToast(t, `/vote/${kind}/option/${oid}`,
|
2022-11-21 01:00:10 +00:00
|
|
|
{
|
|
|
|
},
|
|
|
|
() => {
|
2023-03-12 17:36:35 +00:00
|
|
|
t.disabled = true;
|
2023-08-03 06:55:39 +00:00
|
|
|
const parent = t.parentElement.parentElement
|
|
|
|
for(let el of parent.getElementsByClassName('bet')) {
|
2022-11-21 01:00:10 +00:00
|
|
|
el.disabled = true;
|
|
|
|
}
|
2023-08-03 06:55:39 +00:00
|
|
|
for(let el of parent.getElementsByClassName('cost')) {
|
2022-11-21 01:00:10 +00:00
|
|
|
el.classList.add('d-none')
|
|
|
|
}
|
2022-12-04 15:40:32 +00:00
|
|
|
const scoretext = document.getElementById('option-' + oid);
|
|
|
|
const score = Number(scoretext.textContent);
|
2022-11-21 01:00:10 +00:00
|
|
|
scoretext.textContent = score + 1;
|
|
|
|
}
|
|
|
|
);
|
2022-11-07 10:49:49 +00:00
|
|
|
}
|
2023-06-27 14:14:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//POPOVER
|
|
|
|
|
|
|
|
const popClickBadgeTemplateDOM = document.createElement("IMG");
|
|
|
|
popClickBadgeTemplateDOM.classList.add("pop-badge");
|
|
|
|
popClickBadgeTemplateDOM.loading = "lazy";
|
|
|
|
|
|
|
|
const popover = document.getElementById("popover");
|
|
|
|
|
|
|
|
let pop_instance
|
|
|
|
let is_popover_visible = false
|
|
|
|
|
2023-06-29 22:40:36 +00:00
|
|
|
document.addEventListener("click", function(e) {
|
2023-06-27 14:14:33 +00:00
|
|
|
|
2023-06-29 22:40:36 +00:00
|
|
|
if (is_popover_visible && document.getSelection().type != 'Range' && !e.target.classList.contains('pop-badge')) {
|
2023-06-27 14:14:33 +00:00
|
|
|
pop_instance.hide()
|
|
|
|
}
|
|
|
|
|
2023-07-03 00:26:20 +00:00
|
|
|
active = document.activeElement;
|
2023-06-27 14:14:33 +00:00
|
|
|
|
|
|
|
if (active.getAttribute("data-bs-toggle") == "popover") {
|
|
|
|
const author = JSON.parse(active.dataset.popInfo);
|
2023-07-03 00:26:20 +00:00
|
|
|
|
2023-06-27 14:14:33 +00:00
|
|
|
if (popover.getElementsByClassName('pop-badges')) {
|
|
|
|
const badgesDOM = popover.getElementsByClassName('pop-badges')[0];
|
|
|
|
badgesDOM.innerHTML = "";
|
|
|
|
for (const badge of author["badges"]) {
|
|
|
|
const badgeDOM = popClickBadgeTemplateDOM.cloneNode();
|
2023-06-29 22:40:36 +00:00
|
|
|
badgeDOM.src = badge[0];
|
|
|
|
badgeDOM.title = badge[1];
|
|
|
|
if (badge[2])
|
|
|
|
badgeDOM.alt = badge[2]
|
2023-06-27 14:14:33 +00:00
|
|
|
badgesDOM.append(badgeDOM);
|
|
|
|
}
|
|
|
|
}
|
2023-07-03 00:26:20 +00:00
|
|
|
|
2023-06-27 14:14:33 +00:00
|
|
|
popover.getElementsByClassName('pop-banner')[0].src = author["bannerurl"]
|
|
|
|
popover.getElementsByClassName('pop-picture')[0].src = author["profile_url"]
|
|
|
|
if (author["hat"]) {
|
|
|
|
popover.getElementsByClassName('pop-hat')[0].src = author['hat'] + "?h=7"
|
|
|
|
}
|
2023-07-22 11:25:37 +00:00
|
|
|
else {
|
|
|
|
popover.getElementsByClassName('pop-hat')[0].removeAttribute('src');
|
|
|
|
}
|
2023-06-27 14:14:33 +00:00
|
|
|
popover.getElementsByClassName('pop-username')[0].innerHTML = author["username"]
|
|
|
|
if (popover.getElementsByClassName('pop-bio').length > 0) {
|
|
|
|
popover.getElementsByClassName('pop-bio')[0].innerHTML = author["bio_html"]
|
|
|
|
}
|
|
|
|
popover.getElementsByClassName('pop-postcount')[0].innerHTML = author["post_count"]
|
|
|
|
popover.getElementsByClassName('pop-commentcount')[0].innerHTML = author["comment_count"]
|
|
|
|
popover.getElementsByClassName('pop-coins')[0].innerHTML = author["coins"]
|
|
|
|
popover.getElementsByClassName('pop-marseybux')[0].innerHTML = author["marseybux"]
|
|
|
|
popover.getElementsByClassName('pop-view_more')[0].href = author["url"]
|
|
|
|
popover.getElementsByClassName('pop-created-date')[0].innerHTML = author["created_date"]
|
|
|
|
popover.getElementsByClassName('pop-id')[0].innerHTML = author["id"]
|
|
|
|
if (author["original_usernames"]) {
|
|
|
|
popover.getElementsByClassName('pop-original-usernames')[0].innerHTML = author["original_usernames"]
|
|
|
|
}
|
2023-06-27 21:13:04 +00:00
|
|
|
else {
|
|
|
|
popover.getElementsByClassName('pop-original-usernames')[0].innerHTML = ''
|
|
|
|
}
|
2023-06-27 14:14:33 +00:00
|
|
|
|
|
|
|
pop_instance = bootstrap.Popover.getOrCreateInstance(active, {
|
|
|
|
content: popover.innerHTML,
|
|
|
|
html: true,
|
2024-02-19 00:31:35 +00:00
|
|
|
sanitize: false, // already done on the back end, fixes complex emotes
|
2023-06-27 14:14:33 +00:00
|
|
|
});
|
|
|
|
pop_instance.show()
|
|
|
|
is_popover_visible = true
|
2023-06-29 22:40:36 +00:00
|
|
|
|
|
|
|
const generated_popovers = document.getElementsByClassName("popover")
|
|
|
|
generated_popover = generated_popovers[generated_popovers.length-1]
|
|
|
|
|
|
|
|
const badge_els = generated_popover.getElementsByClassName('pop-badge');
|
|
|
|
for (badge_el of badge_els) {
|
|
|
|
badge_el.setAttribute("data-bs-toggle", "tooltip");
|
|
|
|
badge_el.setAttribute("data-bs-placement", "bottom");
|
|
|
|
if (badge_el.alt) {
|
|
|
|
const date = formatDate(new Date(badge_el.alt*1000));
|
|
|
|
badge_el.title = badge_el.title + ' ' + date.toString();
|
2023-06-29 22:46:17 +00:00
|
|
|
badge_el.removeAttribute('alt');
|
2023-06-29 22:40:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bs_trigger(generated_popover)
|
2023-06-27 14:14:33 +00:00
|
|
|
}
|
|
|
|
});
|