"use strict"; //As basic as it gets... //This function retrieves //and returns data from //specified URL. async function getData(url) { let d = await fetch(url); let t = await d.text(); return t; } //Set the cross-site origin by passing it in as an argument. //Use 'Strict' for the highest security. It disallows cross-origin //data to be written by other websites. 'None' allows any site to //use any, and all cross-origin data. //'SameSite=Strict' //'SameSite=Lax' //'SameSite=None' async function setCookieGetData(url, SameSiteCookieValue) { let cookieVal = SameSiteCookieValue; let d = null; let t = null; if (typeof cookieVal === "string") { if (cookieVal !== "" && cookieVal !== null && cookieVal !== undefined) { let d = await fetch(url, { headers: { Cookie: 'SameSite=' + cookieVal } }).then().catch(); let t = await d.text(); } } return t; } //Gets a URL with a custom cookie which is determined by //the name and value arguments async function set_cookie_get_url(url, CookieName, CookieValue) { let cName = CookieName; let cVal = CookieValue; let d = null; let t = null; if (typeof cVal === "string") { if (cVal !== "" && cVal !== null && cVal !== undefined) { if (typeof cName === "string") { if (cName !== "" && cName !== null && cName !== undefined) { let d = await fetch(url, { headers: { Cookie: (cName + '=' + cVal) } }).then().catch(); let t = await d.text(); } } } } return t; } async function postForm(url, formData) { let resp = await fetch(url, { method: 'post', body: formData }).then(function (response) { return response.text().text; }).then(function (response) { console.log("data posted: " + response.text().text); }); return resp; } function xmlhttp_get(url) { var xmlhttp = null; var txt = null; var memory_address = null; memory_address = make_memory_address(); xmlhttp = xmlhttp_constructor(); if (xmlhttp !== null) { get_xmlhttp_data(xmlhttp, url, memory_address); txt = get_temp_item(memory_address); return txt; } } function get_and_save_xmlhttp(memAddr, url) { var adr = null; var xmlhttp = null; var txt = null; adr = memAddr; xmlhttp = xmlhttp_constructor(); if (xmlhttp !== null) { get_xmlhttp_data(xmlhttp, url, adr); //Put text/html into a container with the memory address for reference txt = get_temp_item(adr); //get the code by referencing the memory address return txt; } } function xmlhttp_constructor() { var xmlhttp = null; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } else { xmlhttp = new XMLHttpRequest(); } xmlhttp.addEventListener("abort", function () { destroy_xmlhttp(xmlhttp); //alert("abort"); }); xmlhttp.addEventListener("error", function () { destroy_xmlhttp(xmlhttp); //alert("error"); }); xmlhttp.addEventListener("timeout", function () { destroy_xmlhttp(xmlhttp); //alert("timeout"); }); return xmlhttp; } function destroy_xmlhttp(xmlhttp) { xmlhttp = null; } function get_xmlhttp_data(xmlhttp_obj, url, memory_address) { var xmlhttp_state_txt = null; var xmlhttp = null; var xmlhttp_txt = null; var div_elem = null; var blank_image = null; var blank_img = null; var redirect_url = null; var memAddr = null; memAddr = memory_address; xmlhttp = xmlhttp_obj; xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { xmlhttp_state_txt = "Loading complete and without error."; //4: request finished and response is ready, 200 code means process occurred OK xmlhttp_txt = xmlhttp.responseText; save_response_text(memAddr, xmlhttp_txt); xmlhttp = null; //alert(xmlhttp_txt); return xmlhttp_txt; } else if (xmlhttp.readyState == 4 && xmlhttp.status == 301) { redirect_url = xmlhttp.getResponseHeader("Location"); xmlhttp.open("GET", encodeURI(redirect_url), true); } else if (xmlhttp.readyState == 4 && xmlhttp.status == 302) { redirect_url = xmlhttp.getResponseHeader("Location"); xmlhttp.open("GET", encodeURI(redirect_url), true); } else if (xmlhttp.readyState == 4 && xmlhttp.status != 200 && xmlhttp.status != 301 && xmlhttp.status != 302) { xmlhttp_state_txt = ("Loading complete, but is not OK. Status is: " + xmlhttp.statusText); //4: request finished and response is ready, but status is not OK xmlhttp = null; return; } else if (xmlhttp.readyState == 3) { xmlhttp_state_txt = "Processing Request."; //3: processing request return; } else if (xmlhttp.readyState == 2) { xmlhttp_state_txt = "Request Recieved."; //2: request received return; } else if (xmlhttp.readyState == 1) { xmlhttp_state_txt = "Server Connection Established."; //1: server connection established //alert(window.location.hostname); xmlhttp.setRequestHeader("Accept", "text/*,text/html,text/html,text/javascript,text/plain"); xmlhttp.setRequestHeader("Access-Control-Allow-Origin", window.location.hostname); xmlhttp.send(null); } else if (xmlhttp.readyState == 0) { xmlhttp_state_txt = "Request Not Initialized."; //0: request not initialized } }; xmlhttp.open("GET", url, true); } function save_response_text(memory_address, txt) { remember(memory_address, txt); return memory_address; } //2023-09-24: //The client system gathers data about the operation //of the Chromosphere website and stores it inside //a global array. At set intervals of time (perhaps 5000 ms) //the data is automatically sent to the server. //Then the global array is set to empty, and it starts the process //all over again. function post_data_to_server(post_data) { var formData = null; var u = null; var b = null; b = return_base_path(); u = b + "/chromosphere/data_io/?data_id=" + get_time_milliseconds().toString() + "&token=" + make_unique_id(32); //the token isn't a real token, just a random string of numbers will do fine until I set up tokens. formData = post_data; postForm(u, formData); }