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
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {HTMLImageElement} */
|
|
|
|
const popClickBadgeTemplateDOM = document.createElement("IMG");
|
2022-11-12 10:44:13 +00:00
|
|
|
popClickBadgeTemplateDOM.classList.add("pop-badge");
|
2022-07-16 21:00:02 +00:00
|
|
|
popClickBadgeTemplateDOM.loading = "lazy";
|
|
|
|
popClickBadgeTemplateDOM.alt = "badge";
|
|
|
|
|
|
|
|
/**
|
2022-09-04 23:15:37 +00:00
|
|
|
* @param {MouseEvent} e
|
|
|
|
*/
|
2022-07-16 21:00:02 +00:00
|
|
|
function popclick(e) {
|
|
|
|
// We let through those methods
|
|
|
|
if(e.ctrlKey || e.metaKey || e.shiftKey || e.altKey)
|
2022-11-07 10:49:49 +00:00
|
|
|
return;
|
2022-07-16 21:00:02 +00:00
|
|
|
e.preventDefault();
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
if(e.currentTarget.dataset.popInfo === undefined)
|
|
|
|
throw new SyntaxError("ill formed HTML! data-pop-info not present!!!");
|
|
|
|
|
|
|
|
const author = JSON.parse(e.currentTarget.dataset.popInfo);
|
|
|
|
if(!(author instanceof Object))
|
|
|
|
throw new SyntaxError("data-pop-info was not valid!");
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
// This is terrible lol. in header.js:bs_trigger() we should add
|
|
|
|
// to the ANCHOR element an event handler for "show.bs.tooltip" to build this
|
|
|
|
// when the DOM is ready.
|
|
|
|
// PROBLEM: IT DOES NOT WORK :MARSEYCRAZYTROLL: idk why it should work according to
|
|
|
|
// boostrap docs!
|
|
|
|
setTimeout(() => {
|
|
|
|
let popover = document.getElementsByClassName("popover")
|
|
|
|
popover = popover[popover.length-1]
|
|
|
|
|
2022-11-11 14:25:28 +00:00
|
|
|
if (popover.getElementsByClassName('pop-badges').length > 0) {
|
|
|
|
const badgesDOM = popover.getElementsByClassName('pop-badges')[0];
|
|
|
|
badgesDOM.innerHTML = "";
|
|
|
|
for (const badge of author["badges"]) {
|
|
|
|
const badgeDOM = popClickBadgeTemplateDOM.cloneNode();
|
|
|
|
badgeDOM.src = badge + "?b=4";
|
|
|
|
|
|
|
|
badgesDOM.append(badgeDOM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
popover.getElementsByClassName('pop-banner')[0].src = author["bannerurl"]
|
|
|
|
popover.getElementsByClassName('pop-picture')[0].src = author["profile_url"]
|
2022-09-20 21:22:58 +00:00
|
|
|
if (author["hat"]) popover.getElementsByClassName('pop-hat')[0].src = author['hat'] + "?h=7"
|
2022-07-16 21:00:02 +00:00
|
|
|
popover.getElementsByClassName('pop-username')[0].innerHTML = author["username"]
|
2022-07-20 01:16:59 +00:00
|
|
|
if (popover.getElementsByClassName('pop-bio').length > 0) {
|
|
|
|
popover.getElementsByClassName('pop-bio')[0].innerHTML = author["bio_html"]
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
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-viewmore')[0].href = author["url"]
|
2022-11-11 15:22:10 +00:00
|
|
|
popover.getElementsByClassName('pop-created-date')[0].innerHTML = author["created_date"]
|
2022-07-16 21:00:02 +00:00
|
|
|
}, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("click", function(){
|
|
|
|
active = document.activeElement.getAttributeNode("class");
|
|
|
|
if (active && active.nodeValue == "user-name text-decoration-none"){
|
|
|
|
pops = document.getElementsByClassName('popover')
|
|
|
|
if (pops.length > 1) pops[0].remove()
|
|
|
|
}
|
|
|
|
else document.querySelectorAll('.popover').forEach(e => e.remove());
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2022-09-05 23:33:58 +00:00
|
|
|
function poll_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');
|
|
|
|
}
|
2022-09-05 23:33:58 +00:00
|
|
|
const full_oid = kind + '-' + oid
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-09-05 23:33:58 +00:00
|
|
|
function poll_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');
|
|
|
|
}
|
2022-09-05 23:33:58 +00:00
|
|
|
const full_oid = kind + '-' + oid
|
|
|
|
let curr = document.getElementById(`current-${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);
|
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-11-21 01:00:10 +00:00
|
|
|
function bet_vote(t, oid) {
|
|
|
|
postToast(t, `/vote/post/option/${oid}`,
|
|
|
|
{
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
for(let el of document.getElementsByClassName('bet')) {
|
|
|
|
el.disabled = true;
|
|
|
|
}
|
|
|
|
for(let el of document.getElementsByClassName('cost')) {
|
|
|
|
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-21 01:11:17 +00:00
|
|
|
|
|
|
|
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200;
|
2022-11-21 01:00:10 +00:00
|
|
|
}
|
|
|
|
);
|
2022-11-07 10:49:49 +00:00
|
|
|
}
|