error reporting cosmetix
[guerillascript.git] / modules / opentab.js
blob7670707a892ef50e1df4bea8b194075a20175a22
1 /* coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://www.wtfpl.net/txt/copying/ for more details.
9 */
10 ////////////////////////////////////////////////////////////////////////////////
11 exports.openTab = function (win, url, inbg) {
12 let afterCurrent = null;
13 if (typeof(inbg) == "object") {
14 afterCurrent = ("afterCurrent" in inbg ? !!inbg.afterCurrent : null);
15 inbg = ("background" in inbg ? !!inbg.background : null);
16 } else if (typeof(inbg) != "boolean") {
17 inbg = null;
19 let dwn = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
20 let chromeWindow =
21 dwn.QueryInterface(Ci.nsIInterfaceRequestor).
22 getInterface(Ci.nsIWebNavigation).
23 QueryInterface(Ci.nsIDocShellTreeItem).
24 rootTreeItem.
25 QueryInterface(Ci.nsIInterfaceRequestor).
26 getInterface(Ci.nsIDOMWindow);
27 if (!chromeWindow) return;
28 let bro = chromeWindow.gBrowser;
29 if (!bro) return;
30 let docbro = bro.getBrowserForDocument(dwn.top.document);
31 if (!docbro) return;
32 //let tabIdx = bro.getBrowserIndexForDocument(dwn.top.document);
33 //let myTab = bro.tabs[tabIdx];
34 let myTab = bro._getTabForContentWindow(dwn.top);
35 let tabIdx = myTab._tPos;
36 let myIsCurrent = (myTab == bro.mCurrentTab);
37 let nt = bro.addTab(url, {ownerTab: myTab, relatedToCurrent: myIsCurrent});
38 let getBool = Services.prefs.getBoolPref;
39 let bg = (inbg !== null ? inbg : getBool("browser.tabs.loadInBackground"));
40 let rel = (afterCurrent !== null ? afterCurrent : getBool("browser.tabs.insertRelatedAfterCurrent"));
41 if (!bg && myIsCurrent) bro.selectedTab = nt;
42 if (myTab && rel) bro.moveTabTo(nt, tabIdx+1);