Changed the method of checking visibility to using jQuery. Must add
@require to load jQuery to the script preamble in TM.