2022-08-24 14:30:30 +00:00
|
|
|
function vote(type, id, dir) {
|
2022-07-16 21:00:02 +00:00
|
|
|
const upvotes = document.getElementsByClassName(type + '-' + id + '-up');
|
|
|
|
const downvotes = document.getElementsByClassName(type + '-' + id + '-down');
|
|
|
|
const scoretexts = document.getElementsByClassName(type + '-score-' + id);
|
|
|
|
|
|
|
|
for (let i=0; i<upvotes.length; i++) {
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
const upvote = upvotes[i]
|
|
|
|
const downvote = downvotes[i]
|
|
|
|
const scoretext = scoretexts[i]
|
|
|
|
const score = Number(scoretext.textContent);
|
|
|
|
|
|
|
|
if (dir == "1") {
|
|
|
|
if (upvote.classList.contains('active')) {
|
|
|
|
upvote.classList.remove('active')
|
|
|
|
upvote.classList.remove('active-anim')
|
|
|
|
scoretext.textContent = score - 1
|
|
|
|
votedirection = "0"
|
|
|
|
} else if (downvote.classList.contains('active')) {
|
|
|
|
upvote.classList.add('active')
|
|
|
|
upvote.classList.add('active-anim')
|
|
|
|
downvote.classList.remove('active')
|
|
|
|
downvote.classList.remove('active-anim')
|
|
|
|
scoretext.textContent = score + 2
|
|
|
|
votedirection = "1"
|
|
|
|
} else {
|
|
|
|
upvote.classList.add('active')
|
|
|
|
upvote.classList.add('active-anim')
|
|
|
|
scoretext.textContent = score + 1
|
|
|
|
votedirection = "1"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (upvote.classList.contains('active')) {
|
|
|
|
scoretext.classList.add('score-up')
|
|
|
|
scoretext.classList.add('score-up-anim')
|
|
|
|
scoretext.classList.remove('score-down')
|
|
|
|
scoretext.classList.remove('score')
|
|
|
|
} else if (downvote.classList.contains('active')) {
|
|
|
|
scoretext.classList.add('score-down')
|
|
|
|
scoretext.classList.remove('score-up')
|
|
|
|
scoretext.classList.remove('score-up-anim');
|
|
|
|
scoretext.classList.remove('score')
|
|
|
|
} else {
|
|
|
|
scoretext.classList.add('score')
|
|
|
|
scoretext.classList.remove('score-up')
|
|
|
|
scoretext.classList.remove('score-up-anim');
|
|
|
|
scoretext.classList.remove('score-down')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (downvote.classList.contains('active')) {
|
|
|
|
downvote.classList.remove('active')
|
|
|
|
downvote.classList.remove('active-anim')
|
|
|
|
scoretext.textContent = score + 1
|
|
|
|
votedirection = "0"
|
|
|
|
} else if (upvote.classList.contains('active')) {
|
|
|
|
downvote.classList.add('active')
|
|
|
|
downvote.classList.add('active-anim')
|
|
|
|
upvote.classList.remove('active')
|
|
|
|
upvote.classList.remove('active-anim')
|
|
|
|
scoretext.textContent = score - 2
|
|
|
|
votedirection = "-1"
|
|
|
|
} else {
|
|
|
|
downvote.classList.add('active')
|
|
|
|
downvote.classList.add('active-anim')
|
|
|
|
scoretext.textContent = score - 1
|
|
|
|
votedirection = "-1"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (upvote.classList.contains('active')) {
|
|
|
|
scoretext.classList.add('score-up')
|
|
|
|
scoretext.classList.add('score-up-anim')
|
|
|
|
scoretext.classList.remove('score-down')
|
|
|
|
scoretext.classList.remove('score')
|
|
|
|
} else if (downvote.classList.contains('active')) {
|
|
|
|
scoretext.classList.add('score-down')
|
|
|
|
scoretext.classList.remove('score-up-anim')
|
|
|
|
scoretext.classList.remove('score-up')
|
|
|
|
scoretext.classList.remove('score')
|
|
|
|
} else {
|
|
|
|
scoretext.classList.add('score')
|
|
|
|
scoretext.classList.remove('score-up')
|
|
|
|
scoretext.classList.remove('score-down')
|
|
|
|
scoretext.classList.remove('score-up-anim')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-10-14 11:31:02 +00:00
|
|
|
const xhr = createXhrWithFormKey("/vote/" + type.replace('-mobile','') + "/" + id + "/" + votedirection);
|
2022-10-14 12:01:11 +00:00
|
|
|
xhr[0].send(xhr[1]);
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 17:49:30 +00:00
|
|
|
let global_price;
|
2024-01-12 08:12:35 +00:00
|
|
|
let global_currency;
|
2023-02-27 17:49:30 +00:00
|
|
|
|
2023-10-08 22:42:05 +00:00
|
|
|
const note_section = document.getElementById('note_section')
|
|
|
|
const gif_button = note_section.querySelector('[title="Add GIF"]')
|
2023-10-10 20:34:35 +00:00
|
|
|
const giveaward_button = document.getElementById('giveaward')
|
2023-10-08 22:42:05 +00:00
|
|
|
|
2022-12-30 15:16:49 +00:00
|
|
|
function pick(kind, price, coins, marseybux) {
|
2023-02-27 17:49:30 +00:00
|
|
|
global_price = price;
|
|
|
|
|
2023-01-01 02:34:12 +00:00
|
|
|
price = parseInt(price)
|
2023-01-01 02:35:08 +00:00
|
|
|
coins = parseInt(coins)
|
|
|
|
marseybux = parseInt(marseybux)
|
2023-01-01 02:32:37 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
document.getElementById('kind').value=kind;
|
2022-10-16 22:14:50 +00:00
|
|
|
if (document.getElementsByClassName('picked').length > 0) {
|
|
|
|
document.getElementsByClassName('picked')[0].classList.toggle('picked');
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
document.getElementById(kind).classList.toggle('picked')
|
2023-03-19 17:13:45 +00:00
|
|
|
|
2023-06-23 11:07:47 +00:00
|
|
|
if (kind == "chud") {
|
2023-03-19 17:13:45 +00:00
|
|
|
document.getElementById('phrase_section').classList.remove("d-none")
|
2023-10-08 22:42:05 +00:00
|
|
|
note_section.classList.add("d-none")
|
2023-03-19 17:13:45 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById('phrase_section').classList.add("d-none")
|
2023-10-08 22:42:05 +00:00
|
|
|
note_section.classList.remove("d-none")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kind == "emoji") {
|
2023-12-01 15:44:53 +00:00
|
|
|
if (giveaward_button.dataset.url.startsWith('/award/post/'))
|
2023-10-10 20:34:35 +00:00
|
|
|
document.getElementById('emoji_behavior_section').classList.remove("d-none")
|
2023-10-08 22:42:05 +00:00
|
|
|
document.getElementById('note').setAttribute("style", "min-height:35px;max-height:35px;height:35px;min-width:min(300px,80vw)")
|
|
|
|
gif_button.classList.add('d-none')
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById('emoji_behavior_section').classList.add("d-none")
|
|
|
|
document.getElementById('note').removeAttribute("style")
|
|
|
|
gif_button.classList.remove('d-none')
|
2023-03-19 17:13:45 +00:00
|
|
|
}
|
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
if (kind == "flairlock") {
|
|
|
|
document.getElementById('notelabel').innerHTML = "New flair:";
|
2023-06-08 04:07:08 +00:00
|
|
|
document.getElementById('note').placeholder = "Insert new flair here, or leave empty to add 1 day to the duration of the current flair.";
|
2022-07-16 21:00:02 +00:00
|
|
|
document.getElementById('note').maxLength = 100;
|
|
|
|
}
|
2023-05-13 04:53:14 +00:00
|
|
|
else if (kind == "namelock") {
|
|
|
|
document.getElementById('notelabel').innerHTML = "New username:";
|
2023-06-08 04:07:08 +00:00
|
|
|
document.getElementById('note').placeholder = "Insert new username here, or leave empty to add 1 day to the duration of the current username.";
|
2023-05-13 04:53:14 +00:00
|
|
|
document.getElementById('note').maxLength = 25;
|
|
|
|
}
|
2023-10-04 13:05:43 +00:00
|
|
|
else if (kind == "emoji") {
|
|
|
|
document.getElementById('notelabel').innerHTML = "Emoji name:";
|
|
|
|
document.getElementById('note').placeholder = "Insert one site emoji here.";
|
|
|
|
document.getElementById('note').maxLength = 33;
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
else {
|
|
|
|
document.getElementById('notelabel').innerHTML = "Note (optional):";
|
|
|
|
document.getElementById('note').placeholder = "Note to include in award notification";
|
|
|
|
document.getElementById('note').maxLength = 200;
|
|
|
|
}
|
2023-03-21 18:49:27 +00:00
|
|
|
|
2023-10-10 16:53:46 +00:00
|
|
|
const ownednum = Number(document.getElementById(`${kind}-owned`).textContent);
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2024-01-12 08:12:35 +00:00
|
|
|
if (kind == 'grass')
|
|
|
|
global_currency = 'coins'
|
|
|
|
else if (kind == 'benefactor')
|
|
|
|
global_currency = 'marseybux'
|
|
|
|
else
|
|
|
|
global_currency = 'coins/marseybux'
|
|
|
|
|
2023-10-26 17:59:20 +00:00
|
|
|
if (ownednum > 0) {
|
2023-10-10 16:53:46 +00:00
|
|
|
document.getElementById('award_price').textContent = `${ownednum} owned`;
|
2023-10-10 20:34:35 +00:00
|
|
|
giveaward_button.classList.remove('d-none');
|
2023-10-10 16:53:46 +00:00
|
|
|
document.getElementById('buyandgiveaward').classList.add('d-none');
|
|
|
|
}
|
|
|
|
else {
|
2024-01-12 08:12:35 +00:00
|
|
|
document.getElementById('award_price').textContent = `Price: ${price} ${global_currency}`;
|
2023-10-10 20:34:35 +00:00
|
|
|
giveaward_button.classList.add('d-none');
|
2023-10-10 16:53:46 +00:00
|
|
|
document.getElementById('buyandgiveaward').classList.remove('d-none');
|
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
2022-10-07 03:25:34 +00:00
|
|
|
|
|
|
|
function giveaward(t) {
|
2022-10-19 17:54:18 +00:00
|
|
|
const kind = document.getElementById('kind').value;
|
2023-03-19 17:13:45 +00:00
|
|
|
|
2023-06-23 11:07:47 +00:00
|
|
|
const note_id = (kind == "chud" ? "chud_phrase" : "note")
|
2023-03-19 17:13:45 +00:00
|
|
|
|
2023-12-01 15:44:53 +00:00
|
|
|
postToast(t, t.dataset.url,
|
2023-03-21 15:27:46 +00:00
|
|
|
{
|
|
|
|
"kind": kind,
|
2023-10-08 22:42:05 +00:00
|
|
|
"note": document.getElementById(note_id).value,
|
2024-04-12 11:08:03 +00:00
|
|
|
"emoji_behavior": document.getElementById("emoji_behavior").value,
|
|
|
|
"award_quantity": document.getElementById("award_quantity").value,
|
2023-03-21 15:27:46 +00:00
|
|
|
},
|
2022-11-03 19:07:08 +00:00
|
|
|
() => {
|
|
|
|
let owned = document.getElementById(`${kind}-owned`)
|
2023-10-26 16:13:24 +00:00
|
|
|
let ownednum = Number(owned.textContent) - 1;
|
|
|
|
owned.textContent = ownednum
|
|
|
|
|
|
|
|
let ownedblock = document.getElementById(`${kind}-owned-block`)
|
2023-10-26 17:59:20 +00:00
|
|
|
if (ownednum > 0) {
|
2023-10-27 09:50:56 +00:00
|
|
|
ownedblock.textContent = `${ownednum} owned`;
|
2023-10-26 16:13:24 +00:00
|
|
|
document.getElementById('award_price').textContent = `${ownednum} owned`;
|
|
|
|
}
|
|
|
|
else {
|
2023-10-31 20:59:45 +00:00
|
|
|
ownedblock.textContent = `Price: ${global_price}`
|
2024-01-12 08:12:35 +00:00
|
|
|
document.getElementById('award_price').textContent = `Price: ${global_price} ${global_currency}`;
|
2023-10-10 16:53:46 +00:00
|
|
|
}
|
2023-01-01 11:36:20 +00:00
|
|
|
}
|
2022-10-07 03:25:34 +00:00
|
|
|
);
|
|
|
|
}
|
2022-12-30 12:14:18 +00:00
|
|
|
|
2023-02-25 19:40:15 +00:00
|
|
|
const awardtabs = document.getElementsByClassName('award-tab');
|
|
|
|
const awardsections = document.getElementsByClassName('award-section');
|
|
|
|
|
|
|
|
function switchAwardTab() {
|
|
|
|
for (const element of awardtabs)
|
|
|
|
element.classList.toggle('active')
|
|
|
|
for (const element of awardsections)
|
|
|
|
element.classList.toggle('d-none')
|
|
|
|
}
|