Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980// Format of possible localStorage values is://// Standard Claim Token -- a run uploaded while not logged in.// "claim_tokens/<run_id>": "<claim_token>"// e.g. "claim_tokens/gcb": "wYJm4S9uAAra6TMyzLkvhC5y"//// Dismissed Claim Token -- a Standard Claim Token whose prompt was dismised in the UI. This dismiss UI is no longer// present (commit after 03ce4e15d11248a8876012e73791d81607741810), but for future- and past-proofing we continue to// maintain their local storage state.// "dismissed_claim_tokens/<run_id>": "<claim_token>"// e.g. "dismissed_claim_tokens/gcb": "wYJm4S9uAAra6TMyzLkvhC5y"
const activateClaimLink = function(claimToken) { if(window.gon.user !== null && document.getElementById('claim-nav-link') !== null) { document.getElementById('claim-nav-link').href = `/${window.gon.run.id}?claim_token=${claimToken}` }
document.getElementById('claim-nav-link-container').hidden = false}
const activateClaimPrompt = function(claimToken) { if(window.gon.user !== null) { document.getElementById('claim-prompt-button').href = `/${window.gon.run.id}?claim_token=${claimToken}` }
document.getElementById('claim-prompt').hidden = false}
document.addEventListener('turbolinks:load', function() { if ( window.gon === undefined || window.gon.run === undefined || location.pathname.substr(location.pathname.lastIndexOf('/')) === '/edit' ) { return }
if (location.pathname === '/') { return }
const claimTokenKey = `claim_tokens/${window.gon.run.id}` const dismissedClaimTokenKey = `dismissed_claim_tokens/${window.gon.run.id}`
// If there's a claim token in the URL, slurp it up into local storage and remove it from the URL. const queryParams = new URLSearchParams(window.location.search) if(queryParams.has('claim_token')) { localStorage.setItem(claimTokenKey, queryParams.get('claim_token')) queryParams.delete('claim_token')
// Clean up the URL if(queryParams.toString() === '') { window.history.replaceState({}, document.title, window.location.pathname) } else { window.history.replaceState({}, document.title, `${window.location.pathname}?${queryParams.toString()}`) } }
// When a run is claimed, the backend prevents it from ever being claimed again, even if the run is later disowned. So // let's get rid of our useless claim token. if(window.gon.run.user !== null) { localStorage.removeItem(claimTokenKey) localStorage.removeItem(dismissedClaimTokenKey) return }
const claimToken = localStorage.getItem(claimTokenKey) const dismissedClaimToken = localStorage.getItem(dismissedClaimTokenKey)
if(claimToken !== null) { activateClaimLink(claimToken) activateClaimPrompt(claimToken) return }
if(dismissedClaimToken !== null) { activateClaimLink(dismissedClaimToken) return }})