// PrefBar Clone Tab button
// Copyright (C) Manuel Reimer (Manuel _dot_ Reimer _at_ gmx _dot_ de)
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation
var curTab = gBrowser.mCurrentTab;
var curBrowser = curTab.linkedBrowser;
var curX = curBrowser.contentWindow.scrollX;
var curY = curBrowser.contentWindow.scrollY
var curHistory = curBrowser.sessionHistory;
var newTab = gBrowser.addTab("about:blank");
var newBrowser = newTab.linkedBrowser;
var newHistory = newBrowser.sessionHistory;
newHistory.QueryInterface(Components.interfaces.nsISHistoryInternal);
for (var i = 0; i < curHistory.count; i++) {
newHistory.addEntry(curHistory.getEntryAtIndex(i, false), true);
}
if (curHistory.count) newBrowser.gotoIndex(curHistory.index);
var background = navigator.preference("browser.tabs.loadInBackground");
if (!background)
gBrowser.selectedTab = newTab;
function doScroll(browser, x, y, tries) {
if (!tries) tries = 0;
if (tries > 20) return;
if (browser.docShell.busyFlags != browser.docShell.BUSY_FLAGS_NONE)
setTimeout(doScroll, 10, browser, x, y, tries + 1);
else
browser.contentWindow.scrollTo(x, y);
}
doScroll(newBrowser, curX, curY);