Js script for catching events