I wrote up a quick TamperMonkey script for use on https://gist.github.com. It was bothering me that I could not expand / collapse files on a gist I was working on. This script adds a button to control expanding and collapsing each file in a gist independently. Check out the code here: https://gist.github.com/Jaace/7b70d2bb19af63e10b144ed7d867eae0
You’ll want to install TamperMonkey or GreaseMonkey (though untested with GreaseMonkey and may need tweaking) to use this.