function check_checkboxes(name) { const checkboxes = document.querySelectorAll(`input[name="${name}"]:checked`); let values = []; checkboxes.forEach((checkbox) => { values.push("\"" + checkbox.value + "\""); }); if (values) { return values; } else { return null; } } function button(x) { const textarea = document.getElementById('content'); if (x == "url") { let url = prompt("Please enter URL", "https://wikipedia.org"); let desc = prompt("Description", "The free Encyclopedia"); var out = "[" + desc + "](" + url + ")"; } else if (x == "headline") { let headline = prompt("Headline", "Act One"); var out = "##" + headline + "\n\n"; } if (x == "pic") { let desc = prompt("Description", "Wikipedia logo"); let pic = prompt("Please enter URL or Number", "https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png"); var out = "![" + desc + "](" + pic + ")"; } if (x == "bold") { let bold = prompt("Bold", ""); var out = "**" + bold + "**"; } if (x == "paragraph") { var out = "\n\n"; } if (x == "newline") { var out = " "; } if (x == "more") { var out = "\n\n\n\n"; } if (out != null) { textarea.innerHTML += out; var end = textarea.value.length; } textarea.setSelectionRange(end, end); textarea.focus(); } function testor(input) { let v1 = []; input.forEach((input) => { v1.push("\"" + input.trim() + "\""); }); if (v1) { return v1; } else { return null; } } function showInput(e) { document.getElementById("result").innerHTML = ''; e.preventDefault(); document.getElementById("result").style.display = "flex"; var output_info = document.getElementById("myform"); var display = document.getElementById("result"); var d = new Date(); var datestring = d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2) + "T" + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":00+02:00"; var form = document.querySelector('form[id="myform"]'); var title = form.elements['title'].value; var content = form.elements['content'].value; var when = form.elements['when'].value; var covid = form.elements['covid'].value; var price = form.elements['price'].value; var contact_mail = form.elements['contact_mail'].value; var insta = form.elements['insta'].value; var events = check_checkboxes('events'); if (form.elements['newevents']) { var newevents = testor(form.elements['newevents'].value.split(',')); } var categories = check_checkboxes('categories'); if (form.elements['newcategories']) { var newcategories = testor(form.elements['newcategories'].value.split(',')); } var tags = check_checkboxes('tags'); if (form.elements['newtags']) { var newtags = testor(form.elements['newtags'].value.split(',')); } var featured = check_checkboxes('featured'); var about = check_checkboxes('about'); var recurrent = check_checkboxes('recurrent'); var foundations = check_checkboxes('foundations'); if (form.elements['newfoundations']) { var newfoundations = testor(form.elements['newfoundations'].value.split(',')); } var lastmod = form.elements['lastmod'].value; if (lastmod) { var dl = new Date(lastmod); var lastmod = dl.getFullYear() + "-" + ("0"+(dl.getMonth()+1)).slice(-2) + "-" + ("0" + dl.getDate()).slice(-2) + "T" + "14:" + "00:00+02:00"; } if (newtags != '""') { var ntags = newtags; } if (tags != '') { var ntags = tags; } if (tags != '' && newtags != '""') { var ntags = tags + "," + newtags; } if (newcategories != '""') { var ncategories = newcategories; } if (categories != '') { var ncategories = categories; } if (categories != '' && newcategories != '""') { var ncategories = categories + "," + newcategories; } if (newevents != '""') { var nevents = newevents; } if (events != '') { var nevents = events; } if (events != '' && newevents != '""') { var nevents = events + "," + newevents; } if (newfoundations != '""') { var nfoundations = newfoundations; } if (foundations != '') { var nfoundations = foundations; } if (foundations != '' && newfoundations != '""') { var nfoundations = foundations + "," + newfoundations; } if (!title) { display.innerHTML += "Title is missing..
" } if (title) { display.innerHTML += "---
"; display.innerHTML += "title: \"" + title + "\"
"; if (lastmod) { display.innerHTML += "lastmod: " + lastmod + "
"; } else { display.innerHTML += "date: " + datestring + "
"; } if (featured != '') { display.innerHTML += "featured: true
"; } if (about != '') { display.innerHTML += "about: true
"; } if (recurrent != '') { display.innerHTML += "recurrent: true
"; } if (when) { display.innerHTML += "when: \"" + when + "\"
"; } if (ncategories) { display.innerHTML += "categories: \[" + ncategories + "]
"; } if (nevents) { display.innerHTML += "events: \[" + nevents + "]
"; } if (nfoundations) { display.innerHTML += "foundations: \[" + nfoundations + "]
"; } if (ntags) { display.innerHTML += "tags: \[" + ntags + "]
"; } if (covid) { display.innerHTML += "covid: \"" + covid + "\"
"; } if (price) { display.innerHTML += "price: \"" + price + "\"
"; } if (contact_mail) { display.innerHTML += "contact_mail: \"" + contact_mail + "\"
"; } if (insta) { display.innerHTML += "insta: \"" + insta + "\"
"; } display.innerHTML += "---
"; if (content) { display.innerHTML += content; } } const textarea = document.getElementById('result'); var end = textarea.value.length; textarea.focus(); }