Updated with an even better solution. The following tbkeys shortcut definition will toggle header visibility:
"h": "{ let tabmail = window.top.document.getElementById('tabmail'); let doc = tabmail?.currentAboutMessage?.document || document.getElementById('messageBrowser')?.contentDocument; doc.getElementById('msgHeaderView').collapsed = !doc.getElementById('msgHeaderView').collapsed; }"
This was my previous (inferior) solution, but could still be useful if you actually want a hotkey to swap out a stylesheet: quite a hack, but it works. I set up two css files, hide.css and display.css, hiding and showing the header respectively. Then the following tbkeys shortcut definition toggles between them:
"h": "{ var ss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService); var io = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService); var ds = Cc['@mozilla.org/file/directory_service;1'].getService(Ci.nsIProperties); var show = 0; var chromepath = ds.get('UChrm', Ci.nsIFile); chromepath.append('userChrome.css'); var hidepath = ds.get('UChrm', Ci.nsIFile); hidepath.append('hide.css'); var displaypath = ds.get('UChrm', Ci.nsIFile); displaypath.append('display.css'); var chromefile = io.newFileURI(chromepath); var hidefile = io.newFileURI(hidepath); var displayfile = io.newFileURI(displaypath); if(ss.sheetRegistered(chromefile, ss.USER_SHEET)){ ss.unregisterSheet(chromefile, ss.USER_SHEET); show = 1; } if(ss.sheetRegistered(hidefile, ss.USER_SHEET)){ ss.unregisterSheet(hidefile, ss.USER_SHEET); show = 1; } if(ss.sheetRegistered(displayfile, ss.USER_SHEET)){ ss.unregisterSheet(displayfile, ss.USER_SHEET); show = 0; } if(show) { ss.loadAndRegisterSheet(displayfile, ss.USER_SHEET); } else { ss.loadAndRegisterSheet(hidefile, ss.USER_SHEET); } }"
Contents of hide.css as well as userchrome.css (starting view is hidden):
#msgHeaderView { visibility: collapse; }
Contents of display.css:
#msgHeaderView { visibility: display; }