JS function mass-rewrite