Created
February 21, 2013 21:13
-
-
Save anonymous/5008313 to your computer and use it in GitHub Desktop.
attempts at FF stuff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] | |
.getService(Components.interfaces.nsIWindowMediator); | |
var enumy = wm.getEnumerator('navigator:browser'); | |
var tabbrowser = enumy.getNext().gBrowser; | |
var browserTimeouts = {}; | |
for (var index = 0; index <= tabbrowser.tabContainer.childNodes.length; index++) { | |
// Get the next tab | |
kango.console.log(index); | |
kango.console.log(tabbrowser.tabContainer.childNodes.length); | |
kango.console.log(index < tabbrowser.tabContainer.childNodes.length); | |
var currentTab = tabbrowser.tabContainer.childNodes[index]; | |
if (!tabbrowser.browserid) { | |
tabbrowser.browserid = ffBrowserId++; | |
(function (tabbrowser, index) { | |
var timers = []; | |
var announceContentLoaded; | |
var goDoIt = function (aEvent) { | |
for (var i = 0; i < timers.length; i++) { | |
kango.console.log("Clearing timeout: "+timers[i]+", browserId:" + tabbrowser.browserid); | |
clearTimeout(timers[i]); | |
} | |
timers.push(setTimeout(function () { | |
announceContentLoadedFunctino(aEvent); | |
}, 250)); | |
}; | |
tabbrowser.addEventListener("DOMContentLoaded", goDoIt, false); | |
var announceContentLoadedFunctino = function (aEvent) { | |
if (aEvent.originalTarget.nodeName === "#document") { | |
kango.console.log("tabbrowser DOMContentLoaded " + aEvent.originalTarget.nodeName); | |
} | |
}; | |
})(tabbrowser, index); | |
kango.console.log("Setting browser id: " + tabbrowser.browserid); | |
} else { | |
kango.console.log("Reading browser id: " + tabbrowser.browserid); | |
} | |
// Does this tab contain our custom attribute? | |
if (currentTab && currentTab.hasAttribute("tabId")) { | |
// Yes--select and focus it. | |
// tabbrowser.selectedTab = currentTab; | |
// Focus *this* browser window in case another one is currently focused | |
// tabbrowser.ownerDocument.defaultView.focus(); | |
kango.console.log("Reading tab id: " + currentTab.getAttribute("tabId")); | |
} else if (currentTab & currentTab.setAttribute) { | |
currentTab.setAttribute("tabId", ffTabId++); | |
kango.console.log("Setting tab id: " + currentTab.getAttribute("tabId")); | |
// currentTab.addEventListener("DOMContentLoaded", function (aEvent) { | |
// kango.console.log("currentTab DOMContentLoaded"); | |
// }, false); | |
} | |
if (index == tabbrowser.tabContainer.childNodes.length) { | |
break; | |
} | |
} | |
// var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); | |
// var enumerator = wm.getEnumerator(type); | |
// while(enumerator.hasMoreElements()) { | |
// var win = enumerator.getNext(); | |
// // win is [Object ChromeWindow] (just like window), do something with it | |
// } | |
// var currentWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser"); | |
// // var currBrowser = currentWindow.getBrowser(); | |
// // var gBrowser = currentWindow.getBrowser(); | |
// // var contentLoadedListener = function (aEvent) { | |
// // var tab = currBrowser.getBrowserForDocument(aEvent.originalTarget); | |
// // var url = aEvent.originalTarget.location.href; | |
// // if (!isBannedUrl(url) && !tab.tabId) { | |
// // kango.console.log(tab.tabId); | |
// // var script = aEvent.originalTarget.defaultView.document.createElement("script"); | |
// // script.src="https://hp.groupnotes.ca:3002/deepnote.js?extension=true"; | |
// // aEvent.originalTarget.defaultView.document.body.appendChild(script); | |
// // tab.tabId = ffTabId++; | |
// // } | |
// // }; | |
// // currBrowser.addEventListener("DOMContentLoaded", contentLoadedListener, false); | |
// // currBrowser.addEventListener("unload", function (aEvent) { | |
// // var tab = currBrowser.getBrowserForDocument(aEvent.originalTarget); | |
// // kango.console.log(tab.tabId); | |
// // }, false); | |
// var myExtension = { | |
// init: function() { | |
// // The event can be DOMContentLoaded, pageshow, pagehide, load or unload. | |
// if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false); | |
// }, | |
// onPageLoad: function(aEvent) { | |
// var doc = aEvent.originalTarget; // doc is document that triggered the event | |
// var win = doc.defaultView; // win is the window for the doc | |
// var tab = gBrowser.getBrowserForDocument(aEvent.originalTarget); | |
// if (tab && !tab.tabId) { | |
// tab.tabId = ffTabId++; | |
// } | |
// kango.console.log("page is loaded \n" +doc.nodeName); | |
// // test desired conditions and do something | |
// // if (doc.nodeName == "#document"){ | |
// // alert("page is loaded \n" +doc.location.href); | |
// // } // only documents | |
// // if (win != win.top) { | |
// // alert("page is loaded \n" +doc.location.href); | |
// // } //only top window. | |
// // if (win.frameElement) return; // skip iframes/frames | |
// } | |
// } | |
// window.addEventListener("load", function load(event){ | |
// window.removeEventListener("load", load, false); //remove listener, no longer needed | |
// myExtension.init(); | |
// },false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment