'use strict'; (() => { const current = new URL(window.location.href); const state = current.searchParams.get('state') || ''; const provider = state.match(/^(x|instagram|linkedin)\.[A-Za-z0-9_-]{40,100}$/)?.[1]; const code = current.searchParams.get('code'); const error = current.searchParams.get('error'); // Remove the authorization code from browser history before opening the application. window.history.replaceState(null, '', window.location.pathname); if (!provider || ((!code || code.length > 8000) && !error) || (error && error.length > 200)) { document.getElementById('message').textContent = 'This sign-in return is missing or invalid. Open Inkspring and start connecting the account again.'; return; } const target = new URL(`inkspring://oauth/${provider}`); target.searchParams.set('state', state); if (error) target.searchParams.set('error', error); else target.searchParams.set('code', code); const link = document.getElementById('return'); link.href = target.href; link.hidden = false; document.getElementById('message').textContent = error ? 'Sign-in was canceled. Return to Inkspring to continue.' : 'Your browser can now return the sign-in result to Inkspring. Select the button and allow your browser to open the installed app.'; })();