/*************************************************************** * * * SMAM: Send Me A Mail * * * * Made with ♥ by Brendan Abolivier * * Source code available under GPLv3 license here: * * https://github.com/babolivier/smam/ * * * ***************************************************************/ var prefix = 'form' var items = { name: 'name', addr: 'addr', subj: 'subj', text: 'text', }; var DOMFields = {}; var server = getServer(); var token = ""; var labels = true; var lang = []; var customFields = {}; var xhr = { customFields: new XMLHttpRequest(), lang: new XMLHttpRequest(), token: new XMLHttpRequest(), send: new XMLHttpRequest() } // XHR callbacks xhr.customFields.onreadystatechange = function() { if(xhr.customFields.readyState == XMLHttpRequest.DONE) { customFields = JSON.parse(xhr.customFields.responseText); for(let field in customFields) { customFields[field].name = field; } } }; xhr.token.onreadystatechange = function() { if(xhr.token.readyState == XMLHttpRequest.DONE) { token = xhr.token.responseText; } }; xhr.lang.onreadystatechange = function() { if(xhr.lang.readyState == XMLHttpRequest.DONE) { let response = JSON.parse(xhr.lang.responseText); lang = response.translations; labels = response.labels; } }; xhr.send.onreadystatechange = function() { if(xhr.send.readyState == XMLHttpRequest.DONE) { let status = document.getElementById('form_status'); status.setAttribute('class', ''); if(xhr.send.status === 200) { cleanForm(); status.setAttribute('class', 'success'); status.innerHTML = lang.send_status_success; } else { status.setAttribute('class', 'failure'); status.innerHTML = lang.send_status_failure; } } }; // Returns the server's base URI based on the user's script tag // return: the SMAM server's base URI function getServer() { var scripts = document.getElementsByTagName('script'); // Parsing all the