// /app/turnstile/: the page the Mac and iPhone apps load in a small web view to get a Cloudflare // Turnstile token before they call POST /api/jobs, /api/candidates or /api/moderators. The token // is handed to the app through the "turnstile" script message handler: // { type: "token", token } | { type: "expired" } | { type: "error", message } | { type: "not_needed" } (function () { var box = document.getElementById('challenge'); function send(message) { try { window.webkit.messageHandlers.turnstile.postMessage(message); } catch (e) { /* opened in a browser */ } box.dataset.state = message.type; } fetch('/api/meta', { headers: { accept: 'application/json' } }) .then(function (r) { return r.json(); }) .then(function (m) { if (!m.turnstile_site_key) return send({ type: 'not_needed' }); window.onAppTurnstile = function () { window.turnstile.render(box, { sitekey: m.turnstile_site_key, appearance: 'interaction-only', callback: function (token) { send({ type: 'token', token: token }); }, 'expired-callback': function () { send({ type: 'expired' }); }, 'error-callback': function (code) { send({ type: 'error', message: String(code || 'challenge error') }); } }); }; var s = document.createElement('script'); s.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onAppTurnstile'; s.async = true; document.head.appendChild(s); }) .catch(function () { send({ type: 'error', message: 'could not reach the server' }); }); })();