Update: I’m currently working this into a gem. Feel free to watch/use/contribute on github: http://github.com/aaronvb/fb_js_connect
This can definitely work without Ruby on Rails, but you may need to change a few things.
To use this in Ruby on Rails, save this file into your RAILS_ROOT/lib folder. If you alter or use this code please contribute back!