// 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() {} ////////////////////////////////////////////////////////////////////////////// // // 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.browserDocuments = new Object(); Scholar_Ingester_Interface.browserUris = new Array(); 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.browserDocuments; this.tabBrowser.removeProgressListener(this); } /* * Scrapes a page (called when the capture icon is clicked) */ Scholar_Ingester_Interface.scrapeThisPage = function() { var documentObject = Scholar_Ingester_Interface._getDocument(Scholar_Ingester_Interface.tabBrowser.selectedBrowser); if(documentObject.scraper) { Scholar_Ingester_Interface.scrapeProgress = new Scholar_Ingester_Interface.Progress(window, Scholar_Ingester_Interface.tabBrowser.selectedBrowser.contentDocument, Scholar.getString("ingester.scraping")); documentObject.scrapePage(Scholar_Ingester_Interface._finishScraping); } } /* * Updates the status of the capture icon to reflect the scrapability or lack * thereof of the current page */ Scholar_Ingester_Interface.updateStatus = function() { var documentObject = Scholar_Ingester_Interface._getDocument(Scholar_Ingester_Interface.tabBrowser.selectedBrowser); if(documentObject && documentObject.scraper) { //Scholar_Ingester_Interface.statusImage.src = "chrome://scholar/skin/treeitem-"+TYPE+".png"; Scholar_Ingester_Interface.statusImage.hidden = false; } else { Scholar_Ingester_Interface.statusImage.hidden = true; } } /* * 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