>If there would be something like \AtEndPage, the \afterpage package
>would be much smaller, its code easier to understand and much easier
>to maintain.

\begin{plug}[shameless]
look at macros/latex/contrib/supported/ms/everyshi.* for a hook just before
\shipout. Should be easy to extend.
\end{plug}

Best regards
Martin

--