2023-05-06 21:53:43 +01:00
|
|
|
init()
|
2023-02-09 20:29:07 +00:00
|
|
|
|
|
|
|
async function init() {
|
2023-05-06 21:53:43 +01:00
|
|
|
hideLoading()
|
2023-02-09 20:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function submit() {
|
2023-05-06 21:53:43 +01:00
|
|
|
setLoadingDesc('Collecting\nData')
|
|
|
|
showLoading()
|
|
|
|
var browserData = await getBrowserData()
|
|
|
|
setLoadingDesc('Reading\nForm')
|
|
|
|
var formData = await getFormData()
|
|
|
|
preflight({browserData: browserData, formData: formData})
|
2023-02-09 20:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getFormData() {
|
2023-05-06 21:53:43 +01:00
|
|
|
let data = {}
|
|
|
|
data.subject = document.getElementById('subject').value
|
|
|
|
data.message = document.getElementById('message').value
|
|
|
|
return data
|
2023-02-09 20:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getBrowserData() {
|
2023-05-06 21:53:43 +01:00
|
|
|
let data = {}
|
|
|
|
data.userAgent = navigator.userAgent
|
|
|
|
data.userAgentData = JSON.stringify(navigator.userAgentData)
|
|
|
|
data.localStorage = JSON.stringify(await storageAvailable('localStorage'))
|
|
|
|
data.sessionStorage = JSON.stringify(await storageAvailable('sessionStorage'))
|
|
|
|
data.viewport = `${window.innerWidth} x ${window.innerHeight}`
|
|
|
|
return data
|
2023-02-09 20:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function preflight(data) {
|
2023-05-06 21:53:43 +01:00
|
|
|
document.getElementById('pre_subject').textContent = data.formData.subject
|
|
|
|
pre_msg = `UserAgent: ${data.browserData.userAgent}
|
2023-02-09 20:29:07 +00:00
|
|
|
\nUserAgentData: ${data.browserData.userAgentData}
|
|
|
|
\nlocalStorage Avail: ${data.browserData.localStorage}
|
|
|
|
\nsessionStorage Avail: ${data.browserData.sessionStorage}
|
|
|
|
\nViewport size: ${data.browserData.viewport}
|
|
|
|
\nUser message:\n\n${data.formData.message}`
|
2023-05-06 21:53:43 +01:00
|
|
|
document.getElementById('pre_message').innerText = pre_msg
|
|
|
|
hideLoading()
|
|
|
|
document.getElementById('preflight').style = 'display: block'
|
|
|
|
sessionStorage.setItem('preflight_subject', data.formData.subject)
|
|
|
|
sessionStorage.setItem('preflight_msg', pre_msg)
|
2023-02-09 20:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function cancel() {
|
2023-05-06 21:53:43 +01:00
|
|
|
document.getElementById('preflight').style = 'display: none'
|
2023-02-09 20:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function send() {
|
2023-05-06 21:53:43 +01:00
|
|
|
setLoadingDesc('Sending\nData')
|
|
|
|
document.getElementById('preflight').style = 'display: none'
|
|
|
|
showLoading()
|
|
|
|
var subject = sessionStorage.getItem('preflight_subject')
|
|
|
|
var msg = sessionStorage.getItem('preflight_msg')
|
|
|
|
if (typeof subject != 'string') {
|
|
|
|
subject = document.getElementById('preflight_subject').innerText
|
|
|
|
}
|
|
|
|
if (typeof msg != 'string') {
|
|
|
|
msg = document.getElementById('preflight_msg')
|
|
|
|
}
|
|
|
|
var payload = JSON.stringify({subject: subject, msg: msg})
|
|
|
|
console.log(payload)
|
|
|
|
let opt = {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Accept': 'application/json'
|
|
|
|
},
|
|
|
|
redirect: 'follow',
|
|
|
|
body: payload
|
|
|
|
}
|
|
|
|
var res = await fetch(`${window.location.origin}/api/v1/issue`, opt)
|
|
|
|
if (res.status == 200) {
|
|
|
|
setLoadingDesc('Success')
|
|
|
|
vibe('ok')
|
|
|
|
await delay(2500)
|
|
|
|
window.location.replace('/')
|
|
|
|
} else {
|
|
|
|
setLoadingDesc('Error')
|
|
|
|
vibe('err')
|
|
|
|
await delay(2500)
|
|
|
|
hideLoading()
|
|
|
|
document.getElementById('preflight').style = 'display: none;'
|
|
|
|
}
|
2023-02-09 20:29:07 +00:00
|
|
|
}
|