Create decoder.js

This is based on the original code by J. Martins. I'm ripping this apart to get it to work.