Derpi-Notify v1.2.9
The extension sends a request to the About page (which is the most lightweight page on the site) every N seconds (which can be adjusted in the options) and looks for the notification and message counters on the page.
The total amount is then displayed on the icon, and when clicked it opens a menu that looks similar to the site's top bar with the notifications and messages icons, both of which can be clicked to go to their respective pages. You should choose the domain you're normally signed in on using the options, otherwise the extension can't keep count of your notifications and messages.
If you browse the site on the domain of your choosing the extension will keep the count synced with the page contents without having to wait for the next timed update.
By default, the extension sends a notification and plays a sound when the total increases, but both the notification and its sound can be disabled if you only want the counter. The notification also disappears after a few seconds initially, but this can be changed to a longer duration or disabled entirely (by setting the timeout to 0), so only a click on the close button or one of the buttons will clear it.
This extension is open source, you can find the code at https://github.com/SeinopSys/Derpi-Notify