57 lines
1.6 KiB
Plaintext
57 lines
1.6 KiB
Plaintext
<% layout('./layout') %>
|
|
|
|
<div id="logs" class="logs">
|
|
<h1 id="title"></h1>
|
|
<div class="captcha" id="captcha"></div>
|
|
<h3 id="bottom">
|
|
<noscript>This feature doesen't function properly unless JavaScript is enabled.</noscript>
|
|
</h3>
|
|
</div>
|
|
|
|
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
|
<script>
|
|
const url = "<%= it.url %>"
|
|
const websocket = "<%= it.websocket %>"
|
|
const sitekey = "<%= it.sitekey %>"
|
|
const ws = new WebSocket(`${websocket}/save?url=${encodeURIComponent(url)}`)
|
|
const h1 = document.getElementById("title")
|
|
const h3 = document.getElementById("bottom")
|
|
const captcha = document.getElementById("captcha")
|
|
|
|
ws.onmessage = function (msg) {
|
|
const text = msg.data.split(' - ').slice(1).join(' - ')
|
|
|
|
if (msg.data == 'ERROR - Missing URL' || msg.data == 'ERROR - Whoops! What is that? That is not a Youtube url.') {
|
|
h1.innerHTML = text
|
|
return
|
|
} else if (msg.data.startsWith('CAPTCHA -')) {
|
|
captcha.style.display = 'block'
|
|
turnstile.render('#captcha', {
|
|
sitekey: sitekey,
|
|
callback: function(token) {
|
|
captcha.remove()
|
|
ws.send(token)
|
|
},
|
|
})
|
|
} else if (msg.data.startsWith('DONE -')) {
|
|
window.location.href = text
|
|
}
|
|
|
|
h3.innerHTML = `${h1.innerHTML}<br>${h3.innerHTML}`
|
|
h1.innerHTML = text
|
|
}
|
|
|
|
ws.onclose = function (event) {
|
|
h3.innerHTML = `Websocket connection was closed: ${event.reason} (${event.code})<br>${h3.innerHTML}`
|
|
}
|
|
|
|
setInterval(() => {
|
|
ws.send('alive')
|
|
}, 2000)
|
|
</script>
|
|
|
|
<style>
|
|
.logs {
|
|
text-align: center;
|
|
}
|
|
</style> |