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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384// 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// "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').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()}`) } }
document.getElementById('dismiss-claim-prompt').addEventListener('click', function() { document.getElementById('claim-prompt').hidden = true localStorage.removeItem(claimTokenKey) localStorage.setItem(dismissedClaimTokenKey, claimToken) })
// 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 }})