From 1781169bbca86c0a3e0923b47e0ab6d85d00b494 Mon Sep 17 00:00:00 2001 From: Dimitri Gilbert Date: Wed, 27 Sep 2023 14:34:56 +0200 Subject: [PATCH] clickotron can now call webserver, but it does not work, yet ;) --- index.html | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index df1a983..ad05518 100644 --- a/index.html +++ b/index.html @@ -317,6 +317,7 @@

parseArger form

pa-type="flag" />

+        

       
       

Subcommand forms

@@ -381,11 +382,28 @@

bulk-parse form

out = document.getElementById('parseArger_result').innerHTML + out; document.getElementById('bin_bulk_parse_result').innerHTML = out; + document.getElementById('parseArger_result').innerHTML = out; } document.getElementById('bin_bulk_parse').addEventListener('submit', function (e) { e.preventDefault(); e.target.checkValidity(); bin_bulk_parse_parse(e.target); + if ((window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") + && (window.location.protocol === "http:" || window.location.protocol === "https:") + && (window.location.port !== "80" && window.location.port !== "443")) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://localhost:' + window.location.port + '/form', true); + xhr.setRequestHeader('Content-Type', 'text/plain'); + xhr.onreadystatechange = function() { + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { + document.getElementById('parseArger_server_response').innerHTML = this.responseText; + } + }; + xhr.onerror = function() { + document.getElementById('parseArger_server_response').innerHTML = 'Error: ' + this.responseText; + }; + xhr.send(document.getElementById('parseArger_result').innerHTML.replace(/parseArger /g, '')); + } });
@@ -551,11 +569,25 @@

completely form

out = document.getElementById('parseArger_result').innerHTML + out; document.getElementById('bin_completely_result').innerHTML = out; + document.getElementById('parseArger_result').innerHTML = out; } document.getElementById('bin_completely').addEventListener('submit', function (e) { e.preventDefault(); e.target.checkValidity(); bin_completely_parse(e.target); + if ((window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") + && (window.location.protocol === "http:" || window.location.protocol === "https:") + && (window.location.port !== "80" && window.location.port !== "443")) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://localhost:' + window.location.port + '/form', true); + xhr.setRequestHeader('Content-Type', 'text/plain'); + xhr.onreadystatechange = function() { + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { + document.getElementById('parseArger_server_response').innerHTML = this.responseText; + } + }; + xhr.send(document.getElementById('parseArger_result').innerHTML.replace(/parseArger /g, '')); + } }); @@ -647,11 +679,25 @@

document form

out = document.getElementById('parseArger_result').innerHTML + out; document.getElementById('bin_document_result').innerHTML = out; + document.getElementById('parseArger_result').innerHTML = out; } document.getElementById('bin_document').addEventListener('submit', function (e) { e.preventDefault(); e.target.checkValidity(); bin_document_parse(e.target); + if ((window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") + && (window.location.protocol === "http:" || window.location.protocol === "https:") + && (window.location.port !== "80" && window.location.port !== "443")) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://localhost:' + window.location.port + '/form', true); + xhr.setRequestHeader('Content-Type', 'text/plain'); + xhr.onreadystatechange = function() { + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { + document.getElementById('parseArger_server_response').innerHTML = this.responseText; + } + }; + xhr.send(document.getElementById('parseArger_result').innerHTML.replace(/parseArger /g, '')); + } }); @@ -809,11 +855,25 @@

generate form

out = document.getElementById('parseArger_result').innerHTML + out; document.getElementById('bin_generate_result').innerHTML = out; + document.getElementById('parseArger_result').innerHTML = out; } document.getElementById('bin_generate').addEventListener('submit', function (e) { e.preventDefault(); e.target.checkValidity(); bin_generate_parse(e.target); + if ((window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") + && (window.location.protocol === "http:" || window.location.protocol === "https:") + && (window.location.port !== "80" && window.location.port !== "443")) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://localhost:' + window.location.port + '/form', true); + xhr.setRequestHeader('Content-Type', 'text/plain'); + xhr.onreadystatechange = function() { + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { + document.getElementById('parseArger_server_response').innerHTML = this.responseText; + } + }; + xhr.send(document.getElementById('parseArger_result').innerHTML.replace(/parseArger /g, '')); + } }); @@ -947,11 +1007,25 @@

html-form form

out = document.getElementById('parseArger_result').innerHTML + out; document.getElementById('bin_html_form_result').innerHTML = out; + document.getElementById('parseArger_result').innerHTML = out; } document.getElementById('bin_html_form').addEventListener('submit', function (e) { e.preventDefault(); e.target.checkValidity(); bin_html_form_parse(e.target); + if ((window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") + && (window.location.protocol === "http:" || window.location.protocol === "https:") + && (window.location.port !== "80" && window.location.port !== "443")) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://localhost:' + window.location.port + '/form', true); + xhr.setRequestHeader('Content-Type', 'text/plain'); + xhr.onreadystatechange = function() { + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { + document.getElementById('parseArger_server_response').innerHTML = this.responseText; + } + }; + xhr.send(document.getElementById('parseArger_result').innerHTML.replace(/parseArger /g, '')); + } }); @@ -1035,11 +1109,25 @@

parse form

out = document.getElementById('parseArger_result').innerHTML + out; document.getElementById('bin_parse_result').innerHTML = out; + document.getElementById('parseArger_result').innerHTML = out; } document.getElementById('bin_parse').addEventListener('submit', function (e) { e.preventDefault(); e.target.checkValidity(); bin_parse_parse(e.target); + if ((window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") + && (window.location.protocol === "http:" || window.location.protocol === "https:") + && (window.location.port !== "80" && window.location.port !== "443")) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://localhost:' + window.location.port + '/form', true); + xhr.setRequestHeader('Content-Type', 'text/plain'); + xhr.onreadystatechange = function() { + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { + document.getElementById('parseArger_server_response').innerHTML = this.responseText; + } + }; + xhr.send(document.getElementById('parseArger_result').innerHTML.replace(/parseArger /g, '')); + } }); @@ -1062,7 +1150,11 @@

parse form

const ielt = document.getElementById(inp); switch (ielt.getAttribute('pa-type')) { case 'pos': - out += ' "' + parseArger_frm.get(inp) + '"'; + if (/[\s!@#$%^&*()_+=[\]{};':"\\|,.<>/?]/.test(parseArger_frm.get(inp))) { + out += ' "' + parseArger_frm.get(inp) + '"'; + } else { + out += ' ' + parseArger_frm.get(inp); + } break; case 'opt': if (parseArger_frm.get(inp) !== '') {