// Scholar for Firefox Ingester Browser Functions // Based on code taken from Greasemonkey and PiggyBank // This code is licensed according to the GPL ////////////////////////////////////////////////////////////////////////////// // // Scholar_Ingester_Interface // ////////////////////////////////////////////////////////////////////////////// // Class to interface with the browser when ingesting data Scholar_Ingester_Interface = function() {} Scholar_Ingester_Interface._scrapeProgress = new Array(); ////////////////////////////////////////////////////////////////////////////// // // Public Scholar_Ingester_Interface methods // ////////////////////////////////////////////////////////////////////////////// /* * Initialize some variables and prepare event listeners for when chrome is done * loading */ Scholar_Ingester_Interface.init = function() { Scholar_Ingester_Interface.browsers = new Array(); Scholar_Ingester_Interface.browserData = new Object(); Scholar_Ingester_Interface._scrapePopupShowing = false; Scholar.Ingester.ProxyMonitor.init(); window.addEventListener("load", Scholar_Ingester_Interface.chromeLoad, false); window.addEventListener("unload", Scholar_Ingester_Interface.chromeUnload, false); } /* * When chrome loads, register our event handlers with the appropriate interfaces */ Scholar_Ingester_Interface.chromeLoad = function() { Scholar_Ingester_Interface.tabBrowser = document.getElementById("content"); Scholar_Ingester_Interface.appContent = document.getElementById("appcontent"); Scholar_Ingester_Interface.statusImage = document.getElementById("scholar-status-image"); // this gives us onLocationChange, for updating when tabs are switched/created Scholar_Ingester_Interface.tabBrowser.addProgressListener(Scholar_Ingester_Interface.Listener, Components.interfaces.nsIWebProgress.NOTIFY_LOCATION); // this is for pageshow, for updating the status of the book icon Scholar_Ingester_Interface.appContent.addEventListener("pageshow", Scholar_Ingester_Interface.contentLoad, true); } /* * When chrome unloads, delete our document objects and remove our listeners */ Scholar_Ingester_Interface.chromeUnload = function() { delete Scholar_Ingester_Interface.browserData, Scholar_Ingester_Interface.browsers; this.tabBrowser.removeProgressListener(this); } /* * Scrapes a page (called when the capture icon is clicked) */ Scholar_Ingester_Interface.scrapeThisPage = function(saveLocation) { var browser = Scholar_Ingester_Interface.tabBrowser.selectedBrowser; var data = Scholar_Ingester_Interface._getData(browser); if(data.translators && data.translators.length) { Scholar_Ingester_Interface.Progress.show(); var translate = new Scholar.Translate("web"); translate.setBrowser(browser); // use first translator available translate.setTranslator(data.translators[0]); translate.setHandler("select", Scholar_Ingester_Interface._selectItems); translate.setHandler("itemDone", Scholar_Ingester_Interface._itemDone); translate.setHandler("done", Scholar_Ingester_Interface._finishScraping); translate.translate(); } } /* * An event handler called when a new document is loaded. Creates a new document * object, and updates the status of the capture icon */ Scholar_Ingester_Interface.contentLoad = function(event) { if (event.originalTarget instanceof HTMLDocument) { // Stolen off the Mozilla extension developer's website, a routine to // determine the root document loaded from a frameset if (event.originalTarget.defaultView.frameElement) { var doc = event.originalTarget; while (doc.defaultView.frameElement) { doc=doc.defaultView.frameElement.ownerDocument; } // Frame within a tab was loaded. doc is the root document of the frameset } else { var doc = event.originalTarget; // Page was loaded. doc is the document that loaded. } // Figure out what browser this contentDocument is associated with var browser; for(var i=0; i