Here's something from this codebase, with names and variables altered but for the most part left alone. Note the hardcoded `ajax_max` variable.
https://gist.github.com/anonymous/2d06bd45222999647d99df54fb...