mirror of
https://github.com/Wolvan/poll.horse.git
synced 2024-11-28 23:27:58 +01:00
cb0ec9dfa1
A new button has been added (which gets automatically removed by JS) that lets a user add a new option. Also, an XSS exploit has been fixed.
46 lines
No EOL
1.7 KiB
JavaScript
46 lines
No EOL
1.7 KiB
JavaScript
"use strict";
|
|
(() => {
|
|
const inputList = [];
|
|
const pollOptionsAnchor = document.querySelector(".poll-options");
|
|
const extendMessageDiv = document.querySelector("#extend-message");
|
|
const inputCounter = document.querySelector("#options-counter");
|
|
const addOptionButton = document.querySelector("#add-options-button");
|
|
|
|
function createPollOptionInput() {
|
|
if (inputList.length >= parseInt(MAX_POLL_OPTIONS)) return;
|
|
const optionEl = document.createElement("div");
|
|
optionEl.classList.add("poll-option");
|
|
const input = document.createElement("input");
|
|
input.type = "text";
|
|
input.maxLength = MAX_CHARACTER_LENGTH;
|
|
input.name = "poll-option";
|
|
input.placeholder = "Enter your option here";
|
|
optionEl.appendChild(input);
|
|
|
|
input.addEventListener("keyup", () => {
|
|
if (inputList.every(el => el.value) && pollOptionsAnchor) {
|
|
pollOptionsAnchor.appendChild(createPollOptionInput());
|
|
}
|
|
});
|
|
inputList.push(input);
|
|
inputCounter.textContent = inputList.length;
|
|
|
|
return optionEl;
|
|
}
|
|
|
|
pollOptionsAnchor.querySelectorAll(".poll-option input").forEach(el => {
|
|
el.addEventListener("keyup", () => {
|
|
if (inputList.every(el => el.value) && pollOptionsAnchor) {
|
|
pollOptionsAnchor.appendChild(createPollOptionInput());
|
|
}
|
|
});
|
|
inputList.push(el);
|
|
});
|
|
|
|
inputCounter.textContent = inputList.length;
|
|
|
|
if (extendMessageDiv) extendMessageDiv.style.display = "block";
|
|
if (addOptionButton) addOptionButton.remove();
|
|
|
|
return createPollOptionInput;
|
|
})(); |