Translate https://gist.github.com/bhelx/778542 to JS
quick updates