Sharepoint 2013 Files Ribbon Missing or Disappears

The Sharepoint menu ribbon that normally displays will disappear the instant you add a webpart into the page. The reason why this happens appears to be Sharepoint no-longer understanding that there is no default list to target the ribbon with. A new dropped-in webpart may cause the ribbon to render other context sensitive actions. The most commonly found solution is to have a javascript function that performs a dummy click on the list you want the ribbon to target to. then put this function in an infinite loop with a timer. I was rather unsatisfied with that solution and eventually found some other people had figured out a slightly better way. My most ideal solution would be to force the ribbon to permanently set the target to a known webpart but I could not find enough information about how Sharepoint’s Javascript works. So here is what I have settled with:

function InitializeStaticRibbon() {
var initInfo = {
editable: true,isEditMode: false,allowWebPartAdder: false
};
SP.Ribbon.WebPartComponent.registerWithPageManager(initInfo);
var wpcomp = SP.Ribbon.WebPartComponent.get_instance();
if(wpcomp){
var zc = document.getElementById("MSOZoneCell_WebPartWPQ2");
wpcomp.selectWebPart(zc, true);
SP.Ribbon.WebPartComponent.get_instance().deselectWebPartAndZone = function() { };
}
}

ExecuteOrDelayUntilScriptLoaded(InitializeStaticRibbon, "sp.ribbon.js");

Placing the above code with s

Info on getting current context:
Issues with getting the SP.ClientContext in SharePoint 2013

Info on preventing ribbon from disappearing on click-aways:
http://w3facility.org/question/list-tools-tab-is-no-longer-available-after-adding-webpart-to-the-page/

Getting the webpart component:
Display ribbon when multiple ListViewWebPart on the page
https://social.msdn.microsoft.com/Forums/office/en-US/c4c988e2-805c-49a4-a5bf-5097dedcef58/how-to-select-a-web-part-to-show-the-ribbon-sections?forum=sharepointdevelopment