// 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 var 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.browserData = new Object(); Scholar_Ingester_Interface._scrapePopupShowing = false; Scholar.Ingester.ProxyMonitor.init(); Scholar.Ingester.MIMEHandler.init(); Scholar.Translate.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.addEventListener("TabClose", Scholar_Ingester_Interface.tabClose, false); Scholar_Ingester_Interface.tabBrowser.addEventListener("TabSelect", Scholar_Ingester_Interface.tabSelect, false); // 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; } /* * Scrapes a page (called when the capture icon is clicked); takes a collection * ID as the argument */ 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(); if(saveLocation) { saveLocation = Scholar.Collections.get(saveLocation); } else { // save to currently selected collection, if a collection is selected try { saveLocation = ScholarPane.getSelectedCollection(); } catch(e) {} } var translate = new Scholar.Translate("web"); translate.setDocument(data.document); // use first translator available translate.setTranslator(data.translators[0]); translate.setHandler("select", Scholar_Ingester_Interface._selectItems); translate.setHandler("itemDone", function(obj, item) { Scholar_Ingester_Interface._itemDone(obj, item, saveLocation) }); translate.setHandler("done", function(obj, item) { Scholar_Ingester_Interface._finishScraping(obj, item, saveLocation) }); translate.translate(); } } Scholar_Ingester_Interface.searchFrames = function(rootDoc, searchDoc) { for each(var frame in rootDoc.frames) { if(frame.document == searchDoc || (frame.document.frames && searchFrames(frame, searchDoc))) { return true; } } return false; } /* * 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) { var doc = event.originalTarget; var rootDoc = doc; // get the appropriate root document to check which browser we're on while(rootDoc.defaultView.frameElement) { rootDoc = rootDoc.defaultView.frameElement.ownerDocument; } // Figure out what browser this contentDocument is associated with var browser; for(var i=0; i