Help with 'visibility animation keys for collections' script modification

Hello,
I found this very useful script:
https://b3d.interplanety.org/en/changing-objects-visibility-in-the-viewport-and-while-rendering/
This script Works fine but when you have 10+ collections to manage visibility it can become a mess.
Thats because it toggles the visibility and let it as is when you stop timeline. So if you hit play again the collections visibility are as when timeline stopped last time and not as it should begin.
Would it be easy to mod it so collections visibility state are more specific?

Hope I made clear what I mean,
With regards!