Some of this logic is going to be used on multiple pages - share for sure, clear maybe, and an as-yet nonexistent add favorite function.  It might be a good idea to split out functions for manipulating favorites into a separate module.