Files
SpeedScope/hash-params.ts
T
Alan Pierce 7c1118a425 Add profileURL and title hash parameters (#19)
On init, we check the hash fragment for these parameters and load the URL. We
always show a loading state in that case rather than the landing screen.

When determining the title, an explicitly-specified title takes precedence,
otherwise we use the filename.

I also added an error state, currently only used for my new code, but possibly
there could be a more robust or widespread error handling approach in the
future.
2018-04-14 20:38:04 -07:00

29 lines
733 B
TypeScript

export interface HashParams {
profileURL?: string
title?: string
}
export function getHashParams(): HashParams {
try {
const hashContents = window.location.hash
if (!hashContents.startsWith('#')) {
return {}
}
const components = hashContents.substr(1).split('&')
const result: HashParams = {}
for (const component of components) {
const [key, value] = component.split('=')
if (key === 'profileURL') {
result.profileURL = decodeURIComponent(value)
} else if (key === 'title') {
result.title = decodeURIComponent(value)
}
}
return result
} catch (e) {
console.error(`Error when loading hash fragment.`)
console.error(e)
return {}
}
}