How to link to a specific scene in a Hype document

If you've made a multi-scene Hype document which is hosted online as a web page, you can link directly to a named scene in that document using this handy script:

function check_for_deeplinks(hypeDocument, element, event) {
	/*
	Allows "deep" linking from an external page into a specific scene in a Tumult Hype document.
	To use, put this on the first frame of the first scene in the Hype document.
	Then, set the link url to `my-hype-document.html#my-scene-name`, to go to the scene named 
	"my-scene-name".
	*/

	// Look for a hash in the url
	var hash = window.location.hash.substring(1);
	
	// Once the hash is found, remove it from the url so you can return to the first scene again
	// in future without redirecting again.
	history.pushState("", document.title, window.location.pathname);
	
	// Go through each scene to find the one whose name matches the hash
	for(var i = 0; i < hypeDocument.sceneNames().length; i++) {
		if(hypeDocument.sceneNames()[i] == hash) {
			// Go to the scene once you've found it
			hypeDocument.showSceneNamed(hash);
			break;
		}
	}
}

[gist]