147 lines
No EOL
5.6 KiB
JavaScript
147 lines
No EOL
5.6 KiB
JavaScript
function promiseXHR(a,b,g){var n="XMLHttpRequest",h="setRequestHeader",k="constructor",t="hasOwnProperty",u="POST",v="content-type",w="x-requested-with",x=Object,y=function(d){return encodeURIComponent(d).replace(/%20/g,"+")},c,e,f,l,z,m;
|
|
if(b)switch(b[k]){case self.FormData:l=1;break;case x:for(p in m="_="+(new Date).getTime(),b)if(b[t](p))for(b[p]&&b[p][k]==Array||(b[p]=[b[p]]),c=0;c<b[p].length;c++)m+="&"+y(p)+"="+y(b[p][c]);case Number:g=g||b,b=m}switch(a[k]){case x:e=a.method,f=a.headers,a=a.url;case String:c=a||location.href.split("#")[0];(e=e||(b?u:"GET"))in{GET:1,HEAD:1}&&b&&(c+=(0>c.indexOf("?")?"?":"&")+b);a=new self[n];
|
|
a.open(e,c);for(p in f)f[t](p)&&(a[h](c=p.toLowerCase(),f[p]),c==v&&(l=1),c==w&&(z=1));z||a[h](w,n);l||e==u&&a[h](v,"application/x-www-form-urlencoded")}return new Promise(function(A,B){a.onreadystatechange=function(){4==a.readyState&&A(a)};g|0&&setTimeout(function(){B("timeout");a.abort()},g);a.send(b)})}self.Promise||document.write("<script src=//cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js></script>")
|
|
//
|
|
|
|
// TIME=HHMMDDMMYY
|
|
|
|
const topNav = document.getElementById("topnav")
|
|
function selTab(evt, id) {
|
|
var tabcontent, tablinks
|
|
tablinks = document.getElementsByClassName("tablinks")
|
|
tabcontent = document.getElementsByClassName("tabcontent")
|
|
|
|
for (let tab of tabcontent) {
|
|
tab.style.display = "none"
|
|
var link = tab.dataset.src
|
|
if (link) {
|
|
tab.getElementsByTagName("iframe")[0].setAttribute("src", "")
|
|
}
|
|
}
|
|
for(let link of tablinks)
|
|
link.className = "tablinks"
|
|
var act = document.getElementById(id)
|
|
act.style.display = "flex"
|
|
evt.currentTarget.className += " active"
|
|
|
|
var link = act.dataset.src
|
|
if(link) {
|
|
act.getElementsByTagName("iframe")[0].setAttribute("src", link)
|
|
}
|
|
topNav.className = "topnav"
|
|
}
|
|
function toggleResponsive() {
|
|
topNav.className = topNav.className === "topnav" ? "topnav responsive" : "topnav"
|
|
//topNav.className = ["topnav","responsive"].slice(0,1+(x.className === "topnav")).join(" ")
|
|
}
|
|
|
|
let contactsData = []
|
|
function delContact(i) {
|
|
contactsData.splice(i, 1);
|
|
storeContacts()
|
|
window.location.reload()
|
|
}
|
|
function addContact(doReloadAfter) {
|
|
contactsData.push({
|
|
r: parseInt(document.querySelector('#newcon_r').value),
|
|
f: parseInt(document.querySelector('#newcon_f').value),
|
|
tl: parseInt(document.querySelector('#newcon_tl').value),
|
|
n: document.querySelector('#newcon_n').value,
|
|
t: document.querySelector('#newcon_t').value,
|
|
})
|
|
storeContacts()
|
|
if (doReloadAfter) window.location.reload()
|
|
}
|
|
function resetContacts() {
|
|
if (confirm("do you want to delete all contacts?")) {
|
|
promiseXHR("/contacts.json", JSON.stringify([]))
|
|
.then(() => alert("reset contacts"))
|
|
}
|
|
}
|
|
function storeContacts() {
|
|
promiseXHR("/contacts.json", JSON.stringify(contactsData))
|
|
.then(() => alert("stored contacts"))
|
|
}
|
|
let firstFetch = true
|
|
function fetchCfgVals() {
|
|
if (!firstFetch) return
|
|
firstFetch = false
|
|
promiseXHR("/config.json").then(j=>{
|
|
const res = JSON.parse(j.responseText)
|
|
console.log(res)
|
|
for (let key in res) {
|
|
let e = document.getElementById(key) || document.getElementsByName(key)[0]
|
|
if (!!e) {
|
|
if (e.type == 'checkbox') {
|
|
e.checked = res[key];
|
|
} else {
|
|
e.value = res[key]
|
|
}
|
|
}
|
|
}
|
|
})
|
|
promiseXHR("/contacts.json").then(j=>{
|
|
const contactlist = document.getElementById("contactlist")
|
|
contactsData = JSON.parse(j.responseText)
|
|
console.log("received contacts from esp", contactsData)
|
|
for (let contactI in contactsData) {
|
|
const contact = contactsData[contactI]
|
|
const li = document.createElement("li")
|
|
li.innerHTML = `<form action="/page" class="styled-form no-top-margin">
|
|
<h3>${ contact.n }</h3>
|
|
<input type="hidden" name="ric" value="${ contact.r }" />
|
|
<input type="hidden" name="fun" value="${ contact.f }" />
|
|
<label for="text">Message</label>
|
|
<input type="text" name="text" value="${ contact.t }" />
|
|
<pre>RIC=${ contact.r } F=${ contact.f } TL=${ contact.tl }</pre>
|
|
<input class="btn" type="submit" name="add" value="queue" />
|
|
<input class="btn" type="submit" name="addtx" value="direct transmit" />
|
|
</form>
|
|
<div class="styled-form">
|
|
<button onClick="delContact(${ contactI })">del contact</button>
|
|
</div>
|
|
`
|
|
contactlist.appendChild(li)
|
|
}
|
|
})
|
|
}
|
|
|
|
document.getElementById("defaultTab").click()
|
|
for (let i of document.getElementsByTagName("input")) i.placeholder = i.name
|
|
|
|
function calculateTimeToTxTxt(type) {
|
|
document.querySelector("input[name='text']").value = calculateTime(type)
|
|
}
|
|
function calculateTime(type) {
|
|
const now = new Date();
|
|
|
|
// Extract date components
|
|
const hh = String(now.getHours()).padStart(2, '0');
|
|
const mm = String(now.getMinutes()).padStart(2, '0');
|
|
const DD = String(now.getDate()).padStart(2, '0');
|
|
const MM = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-based
|
|
const YY = String(now.getFullYear()).slice(-2); // Get last two digits of the year
|
|
|
|
// Construct the formatted string
|
|
const formattedTime = `${hh}${mm}${DD}${MM}${YY}`;
|
|
|
|
switch (type) {
|
|
case 'tpl':
|
|
return `#ZEIT=${formattedTime}#ZEIT=${formattedTime}`;
|
|
case 'swissphone':
|
|
return `;TIME=${formattedTime};TIME=${formattedTime}`;
|
|
default:
|
|
return 'Invalid type';
|
|
}
|
|
}
|
|
function populateTimezones() {
|
|
const timezones = Intl.supportedValuesOf('timeZone');
|
|
const select = document.getElementById("time_zone");
|
|
timezones.forEach(zone => {
|
|
const option = document.createElement("option");
|
|
option.value = zone;
|
|
option.textContent = zone;
|
|
select.appendChild(option);
|
|
});
|
|
}
|
|
populateTimezones(); |