82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
const input = document.querySelector('footer > .i > input')
|
|
const hints = document.querySelector('.hints')
|
|
var inputed_room = ''
|
|
|
|
const initEruda = () => {
|
|
if (window.__zatupsErudaInitialized || window.__zatupsErudaLoading) return
|
|
|
|
const start = () => {
|
|
if (!window.eruda) {
|
|
hints.innerHTML = '<span>Консоль не загрузилась</span>'
|
|
return
|
|
}
|
|
try {
|
|
window.eruda.init()
|
|
window.__zatupsErudaInitialized = true
|
|
} catch (error) {
|
|
hints.innerHTML = '<span>Консоль не загрузилась</span>'
|
|
}
|
|
}
|
|
|
|
if (window.eruda) return start()
|
|
|
|
window.__zatupsErudaLoading = true
|
|
const script = document.createElement('script')
|
|
script.src = '../common/eruda.min.js?v13'
|
|
script.onload = () => {
|
|
window.__zatupsErudaLoading = false
|
|
start()
|
|
}
|
|
script.onerror = () => {
|
|
window.__zatupsErudaLoading = false
|
|
hints.innerHTML = '<span>Консоль не загрузилась</span>'
|
|
}
|
|
document.head.appendChild(script)
|
|
}
|
|
|
|
input.addEventListener('focus', (e) => {
|
|
const fixed = `height: ${map.clientHeight}px !important;`
|
|
document.querySelector('#map').style = fixed
|
|
document.querySelector('#map > #wr').style = fixed
|
|
})
|
|
|
|
input.addEventListener('input', (e) => {
|
|
console.log(e.target.value)
|
|
inputed_room = e.target.value.trim().toLowerCase()
|
|
if (inputed_room === 'eruda') {
|
|
try {hints.classList.remove('a')} catch {}
|
|
hints.innerHTML = ''
|
|
initEruda()
|
|
return
|
|
}
|
|
if (inputed_room.length > 0) {
|
|
try {hints.classList.add('a')} catch {}
|
|
const out = fdata.results(inputed_room)
|
|
if (out.length == 0) {
|
|
Telegram.WebApp.HapticFeedback.notificationOccurred('error')
|
|
return hints.innerHTML = `<span>Результатов нет</span>`
|
|
}
|
|
hints.innerHTML = out.map(e => `<span onclick="find('${e.r}', ${e.f})">${e.r}</span>`).join('')
|
|
console.log(inputed_room)
|
|
|
|
} else {
|
|
try {hints.classList.remove('a')} catch {}
|
|
hints.innerHTML = ''
|
|
}
|
|
})
|
|
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
|
|
const find = async (room_name, floor) => {
|
|
console.log(room_name, floor)
|
|
input.value = ''
|
|
input.placeholder = room_name
|
|
hints.innerHTML = ''
|
|
try {hints.classList.remove('a')} catch {}
|
|
if (!room_name.includes('Туал')) {
|
|
fswitch(floor)
|
|
await sleep(450)
|
|
}
|
|
Telegram.WebApp.HapticFeedback.notificationOccurred('success')
|
|
highlight(room_name)
|
|
}
|