You just want to run a script if the page is in edit mode or just execute if it is not?
Use this little function (requires jQuery) to check whether the page is in edit mode or not:
function checkIfEditMode(){ return ($("#MSOLayout_InDesignMode").val() || $("#_wikiPageMode").val()) ? true : false }
This script will work Web Part pages, SharePoint Publishing pages and Wiki pages.