Update library.js

Minify variables declarations. Fix `.replace()` method's selection history.