Skip to content

Instantly share code, notes, and snippets.

@matbee-eth
Forked from anonymous/gist:5008313
Last active December 14, 2015 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matbee-eth/5008601 to your computer and use it in GitHub Desktop.
Save matbee-eth/5008601 to your computer and use it in GitHub Desktop.
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
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++) {
clearTimeout(timers[i]);
}
timers.push(setTimeout(function () {
announceContentLoadedFunctino(aEvent);
}, 250));
};
tabbrowser.addEventListener("DOMContentLoaded", goDoIt, false);
var announceContentLoadedFunctino = function (aEvent) {
if (aEvent.originalTarget.nodeName === "#document") {
}
};
})(tabbrowser, index);
} else {
}
// 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();
} else if (currentTab & currentTab.setAttribute) {
currentTab.setAttribute("tabId", ffTabId++);
// 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://domain.com: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