It was adding a listener for DOMContentLoaded event in code that runs when that event has just fired, so the listener never ran. Also clean up and simplify some relevant code. Similar to https://github.com/shurcooL/issuesapp/commit/c25bd476f001893e3608cd5aa6b016760236ad2d.
This way, pressing escape works even if you have a link selected (which is often the case after clicking on an anchor). We avoid processing unwanted keydown events because they'll be default prevented. Add "keydown" event listener to body rather than document, because it's sufficient and for consistency.