Convert to a 'prototype' based on fpmurphy's code + Thomas Vogt's feedback, so that we can properly disconnect the events when the extension is disabled.