Redo edit.js

I wrote all this a while ago, but I still can't test it on my PC, so test it before you merge.