How to get current page's resourceId or contextId?

A user recently posted the solution to a similar problem, try going through their code and see if you can find something that points you in the right direction: