Another port of my wonderful private paste. This time in js.