Conditionalize the use of window.addEventListener