naTmeg / ScriptedAmigaEmulator

Amiga Emulator in javascript and HTML5
331 stars 63 forks source link

Use URL hash for easy sharing. #1

Closed mrdoob closed 11 years ago

mrdoob commented 11 years ago

Albeit it's likely that will bring you hosting/bandwidth issues, I think it would be good for the project if whenever you clicked on Play the id of the rom would be added to the url as hash, like this:

http://scriptedamigaemulator.net/#9_Fingers

Then, whenever the page loads you could automatically load the rom if the hash isn't empty.

This would allow anyone to show 9 Fingers to a friend without having to tell them what to select on the form.

I tried to implement it myself, but seems like it would require a bit of refactoring. Here's some basic code for you anyway:

// at init time

if ( window.location.hash.length > 0 ) {

    var id = window.location.hash.substr( 1 );
    loadRom( id );

}

// at play time

function loadRom( id ) {

    window.locatin.hash = id
    ...

}
naTmeg commented 11 years ago

Thanks, that is an interesting idea. Should be added in the next release.

mrdoob commented 11 years ago

Uhm. I suggest making URL friendly hashes for each.

This link doesn't auto-link:

http://scriptedamigaemulator.net/#State of the Art

However, this one does:

http://scriptedamigaemulator.net/#State_of_the_Art

Something like this should already do the trick here:

hash = hash.replace(/ /, "_") // url encode
hash = hash.replace(/_/, " ") // url decode
naTmeg commented 11 years ago

Hmm, at least it worked for me when i tried yesterday. It can only work if the page is load the first time, because it's called via "document.onload". Anyway, the spaces in the name are fixed now. Thanks again :)

mrdoob commented 11 years ago

Sweet!