Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I use MutationObserver to watch the document root and reapply event handlers in my stuff. It's flawless as far as I can tell. MutationObserver is the correct answer I think.
@A.L I'm sorry, but I'm not sure that understand what you mean. Are you saying that only spaces can be used to define a code block on StackExchange pages? If so, I think you're mistaken. A tab will work just as well as 4 spaces to define a code block in StackExchange network's markdown syntax.
@A.L I appreciate your feedback. If my script's replacement of spaces with tabs is irritating to you, then you might prefer balpha's script. His uses spaces for indenting. Modifying my script to indent with spaces would be prohibitively complicated, as so much of the logic depends on spaces being converted to tabs. But as you say, it's invisible, and I prefer it this way. It's faster for me to arrow key through 2 tabs than through 8 spaces.
@A.L Ah, thanks for pointing out that bug. [Enter] was mis-handling the 4-space indentation. I fixed it. You can now indent with 4 spaces and the script will continue auto indenting with tabs. Try it out and let me know if it's still a problem. Merci beaucoup!