bunteshaus.de/themes/buha/static/js/generator.js

257 lines
6.6 KiB
JavaScript
Raw Normal View History

2022-03-27 19:58:39 +02:00
function check_checkboxes(name) {
const checkboxes = document.querySelectorAll(`input[name="${name}"]:checked`);
let values = [];
checkboxes.forEach((checkbox) => {
2022-06-08 06:09:50 +02:00
values.push("\"" + checkbox.value + "\"");
2022-03-27 19:58:39 +02:00
});
if (values) {
return values;
} else {
return null;
}
}
2022-06-08 06:09:50 +02:00
function Clear(name)
{
clearRadioGroup(name);
}
function clearRadioGroup(name)
{
var ele = document.getElementsByName(name);
for(var i=0;i<ele.length;i++)
ele[i].checked = false;
}
2022-06-07 13:36:28 +02:00
function typeInTextarea(newText, el = document.getElementById('content')) {
const [start, end] = [el.selectionStart, el.selectionEnd];
el.setRangeText(newText, start, end);
}
2022-05-10 04:16:08 +02:00
function button(x) {
2022-06-07 13:36:28 +02:00
const id = document.getElementById('content');
if (x == "url") {
let url = prompt("Please enter URL", "https://wikipedia.org");
2022-06-12 13:50:06 +02:00
if (url != null) {
let desc = prompt("Description", "The free Encyclopedia");
if (desc != null) {var out = "[" + desc + "](" + url + ") ";}
}
2022-06-07 13:36:28 +02:00
}
if (x == "headline") {
let headline = prompt("Headline", "Act One");
2022-06-12 13:50:06 +02:00
if (headline != null) {var out = "## " + headline + "\n\n";}
2022-06-07 13:36:28 +02:00
}
if (x == "pic") {
let desc = prompt("Description", "Wikipedia logo");
2022-06-12 13:50:06 +02:00
if (desc != null) {
let pic = prompt("Please enter URL or Number", "https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png");
if (pic != null) {var out = "![" + desc + "](" + pic + ") ";}
}
2022-06-07 13:36:28 +02:00
}
if (x == "bold") {
let bold = prompt("Bold", "");
2022-06-12 13:50:06 +02:00
if (bold != null) {var out = "\*\*" + bold + "\*\* ";}
2022-06-07 13:36:28 +02:00
}
if (x == "paragraph") {
var out = "\n\n";
}
if (x == "newline") {
var out = " \n";
}
if (x == "more") {
var out = "\n<!--more-->\n\n";
}
if (out != null) {
typeInTextarea(out);
const end = id.value.length;
id.setSelectionRange(end, end);
id.focus();
}
2022-05-10 04:16:08 +02:00
}
2022-03-27 19:58:39 +02:00
function testor(input) {
let v1 = [];
input.forEach((input) => {
v1.push("\"" + input.trim() + "\"");
});
if (v1) {
return v1;
} else {
return null;
}
}
function showInput(e) {
2022-04-11 22:38:32 +02:00
document.getElementById("result").innerHTML = '';
2022-03-27 19:58:39 +02:00
e.preventDefault();
2022-04-11 22:38:32 +02:00
document.getElementById("result").style.display = "flex";
2022-03-27 19:58:39 +02:00
var output_info = document.getElementById("myform");
2022-04-11 22:38:32 +02:00
var display = document.getElementById("result");
2022-03-27 19:58:39 +02:00
2022-04-10 02:24:33 +02:00
2022-03-27 19:58:39 +02:00
var d = new Date();
2022-04-10 02:24:33 +02:00
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";
2022-03-27 19:58:39 +02:00
var form = document.querySelector('form[id="myform"]');
2022-04-06 17:51:02 +02:00
var title = form.elements['title'].value;
2022-06-08 06:09:50 +02:00
var summary = form.elements['summary'].value;
2022-03-27 19:58:39 +02:00
var content = form.elements['content'].value;
2022-04-06 17:51:02 +02:00
var when = form.elements['when'].value;
2022-04-10 02:27:54 +02:00
var covid = form.elements['covid'].value;
2022-04-06 17:51:02 +02:00
var price = form.elements['price'].value;
2022-04-28 17:39:10 +02:00
var contact_mail = form.elements['contact_mail'].value;
var insta = form.elements['insta'].value;
2022-04-04 00:42:08 +02:00
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(',')); }
2022-03-27 19:58:39 +02:00
var tags = check_checkboxes('tags');
2022-04-04 00:42:08 +02:00
if (form.elements['newtags']) { var newtags = testor(form.elements['newtags'].value.split(',')); }
2022-03-27 19:58:39 +02:00
var featured = check_checkboxes('featured');
2022-04-04 01:13:42 +02:00
var about = check_checkboxes('about');
2022-04-28 17:55:16 +02:00
var recurrent = check_checkboxes('recurrent');
2022-03-27 19:58:39 +02:00
2022-04-10 14:06:48 +02:00
var foundations = check_checkboxes('foundations');
if (form.elements['newfoundations']) { var newfoundations = testor(form.elements['newfoundations'].value.split(',')); }
2022-04-10 02:24:33 +02:00
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";
}
2022-03-27 19:58:39 +02:00
2022-04-04 00:42:08 +02:00
if (newtags != '""') {
var ntags = newtags;
2022-03-27 19:58:39 +02:00
}
if (tags != '') {
var ntags = tags;
}
2022-04-04 00:42:08 +02:00
if (tags != '' && newtags != '""') {
var ntags = tags + "," + newtags;
2022-03-27 19:58:39 +02:00
}
2022-06-08 06:09:50 +02:00
2022-04-04 00:42:08 +02:00
if (newcategories != '""') {
2022-06-08 06:09:50 +02:00
var ncategories = newcategories;
2022-04-04 00:42:08 +02:00
}
2022-06-08 06:09:50 +02:00
if (categories != '' ) {
var ncategories = categories;
2022-04-04 00:42:08 +02:00
}
if (categories != '' && newcategories != '""') {
2022-06-08 06:09:50 +02:00
var ncategories = categories + "," + newcategories;
2022-04-04 00:42:08 +02:00
}
2022-04-06 17:51:02 +02:00
if (newevents != '""') {
var nevents = newevents;
}
if (events != '') {
var nevents = events;
}
if (events != '' && newevents != '""') {
var nevents = events + "," + newevents;
}
2022-04-10 14:06:48 +02:00
if (newfoundations != '""') {
var nfoundations = newfoundations;
}
if (foundations != '') {
var nfoundations = foundations;
}
if (foundations != '' && newfoundations != '""') {
var nfoundations = foundations + "," + newfoundations;
}
2022-04-04 00:42:08 +02:00
2022-03-27 19:58:39 +02:00
if (!title) {
display.innerHTML += "Title is missing..<br>"
}
2022-04-28 17:39:10 +02:00
2022-03-27 19:58:39 +02:00
2022-04-28 17:39:10 +02:00
if (title) {
2022-03-27 19:58:39 +02:00
display.innerHTML += "---<br>";
display.innerHTML += "title: \"" + title + "\"<br>";
2022-04-10 14:54:59 +02:00
if (lastmod) {
display.innerHTML += "lastmod: " + lastmod + "<br>";
} else {
display.innerHTML += "date: " + datestring + "<br>";
}
2022-06-08 06:09:50 +02:00
if (summary) {
display.innerHTML += "summary: \"" + summary + "\"<br>";
}
2022-03-27 20:14:36 +02:00
if (featured != '') {
display.innerHTML += "featured: true<br>";
}
2022-03-27 19:58:39 +02:00
2022-04-04 01:13:42 +02:00
if (about != '') {
display.innerHTML += "about: true<br>";
}
2022-04-28 17:55:16 +02:00
if (recurrent != '') {
display.innerHTML += "recurrent: true<br>";
}
2022-04-03 21:08:42 +02:00
if (when) {
display.innerHTML += "when: \"" + when + "\"<br>";
}
2022-04-04 00:42:08 +02:00
if (ncategories) {
display.innerHTML += "categories: \[" + ncategories + "]<br>";
2022-03-27 20:14:36 +02:00
}
2022-03-27 19:58:39 +02:00
2022-04-06 19:32:09 +02:00
if (nevents) {
2022-04-06 17:51:02 +02:00
display.innerHTML += "events: \[" + nevents + "]<br>";
2022-03-27 20:14:36 +02:00
}
2022-04-03 21:08:42 +02:00
2022-04-10 14:06:48 +02:00
if (nfoundations) {
display.innerHTML += "foundations: \[" + nfoundations + "]<br>";
}
2022-03-27 20:14:36 +02:00
if (ntags) {
display.innerHTML += "tags: \[" + ntags + "]<br>";
}
2022-04-10 02:27:54 +02:00
if (covid) {
display.innerHTML += "covid: \"" + covid + "\"<br>";
}
2022-04-03 21:08:42 +02:00
if (price) {
display.innerHTML += "price: \"" + price + "\"<br>";
}
2022-04-10 14:54:59 +02:00
2022-04-28 17:39:10 +02:00
if (contact_mail) {
display.innerHTML += "contact_mail: \"" + contact_mail + "\"<br>";
}
if (insta) {
display.innerHTML += "insta: \"" + insta + "\"<br>";
2022-04-03 21:08:42 +02:00
}
2022-03-27 20:14:36 +02:00
display.innerHTML += "---<br>";
if (content) {
2022-03-27 20:40:45 +02:00
display.innerHTML += content;
2022-03-27 20:14:36 +02:00
}
2022-03-27 19:58:39 +02:00
}
2022-05-10 04:16:08 +02:00
const textarea = document.getElementById('result');
2022-06-07 13:36:28 +02:00
var end = textarea.length;
2022-05-10 04:16:08 +02:00
textarea.focus();
2022-03-27 19:58:39 +02:00
}