Add checkbox for the comments section

This commit is contained in:
Kuba Orlik 2023-02-03 14:48:06 +01:00
parent d2e709891e
commit 180872e308
1 changed files with 37 additions and 0 deletions

View File

@ -83,6 +83,7 @@ into the {body} of the default.hbs template --}}
</section>
</div>
</header>
@ -134,6 +135,42 @@ into the {body} of the default.hbs template --}}
src="https://www.internet-czas-dzialac.pl/isso/js/embed.min.js" async></script>
<section id="isso-thread"></section>
<script>
(async function(){
function addCheckbox(){const original_submit = document.querySelector(".post-action input[type='submit']");
original_submit.style.setProperty("display", "none")
const faux_submit = document.createElement("input")
faux_submit.value = "Wyślij"
const comment_checkbox_id = "comment-checkbox"
const checkbox = document.createElement("input")
checkbox.type = "checkbox"
checkbox.id = comment_checkbox_id
checkbox.required = true
const label = document.createElement("label")
label.for = comment_checkbox_id;
label.appendChild(checkbox)
const label_text = document.createElement("span")
label_text.innerHTML = `akceptuję postanowienia <a href="#">regulaminu komentarzy</a>`
label.appendChild(label_text)
document.querySelector("#isso-thread .auth-section").appendChild(label)
faux_submit.addEventListener("click", ()=>{
if(!checkbox.checked){
checkbox.reportValidity()
}else {
original_submit.click()
}
})
original_submit.parentElement.appendChild(faux_submit)
}
for(let i=0; i<=20; i++){
if(document.querySelector(".post-action input[type='submit']")){
continue
}
await new Promise((resolve)=>setTimeout(resolve, 200));
}
addCheckbox();
})()
</script>
</div>
</main>