Hi all,
I have a couple of questions for you experts.
The first one is about this script:
Code: Select all
//close prev tab
var tab = gBrowser.mCurrentTab.boxObject.previousSibling;
if (tab)
{ gBrowser.removeTab(tab); }
//close next tab
var tab = gBrowser.mCurrentTab.boxObject.nextSibling;
if (tab)
{ gBrowser.removeTab(tab); }
//close left tabs
while (gBrowser.mCurrentTab.boxObject.previousSibling)
{ gBrowser.removeTab(gBrowser.mCurrentTab.boxObject.previousSibling); }
//close right tabs
while (gBrowser.mCurrentTab.boxObject.nextSibling)
{ gBrowser.removeTab(gBrowser.mCurrentTab.boxObject.nextSibling); }
I modified the "close prev/next tab" scripts to create the other two: close all rifgt/left tabs without confirmation. They seem to work fine but I don't know much about scripts, are they safe to use?
The second question is about a Firegestures script, and I know maybe this is not the right place to ask and I apologize, but their site is dead and I didn't know where else to go. Here it is:
Code: Select all
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var recentWindow = wm.getMostRecentWindow("navigator:browser");
var browser = recentWindow.gBrowser;
searchTab1 = function(url) //open in current tab
{
if (!url)
{ FireGestures.setStatusText("Invalid URL.");
FireGestures.clearStatusText(2000);
return; }
browser.loadURI(url);
};
searchTab2 = function(url) //open in next tab and select it
{
if (!url)
{ FireGestures.setStatusText("Invalid URL.");
FireGestures.clearStatusText(2000);
return; }
var pos = browser.selectedTab._tPos;
var tab = browser.addTab(url);
browser.moveTabTo(tab,pos+1);
browser.selectedTab = tab;
};
searchTab3 = function(url) //open in next tab
{
if (!url)
{ FireGestures.setStatusText("Invalid URL.");
FireGestures.clearStatusText(2000);
return; }
var pos = browser.selectedTab._tPos;
var tab = browser.addTab(url);
browser.moveTabTo(tab,pos+1);
};
searchTab4 = function(url) //open in last tab and select it
{
if (!url)
{ FireGestures.setStatusText("Invalid URL.");
FireGestures.clearStatusText(2000);
return; }
var tab = browser.addTab(url);
browser.selectedTab = tab;
};
searchTab5 = function(url) //open in last tab
{
if (!url)
{ FireGestures.setStatusText("Invalid URL.");
FireGestures.clearStatusText(2000);
return; }
var tab = browser.addTab(url);
};
searchCommand = function(nm,text)
{
if (!text)
{ var text = ""; }
var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var engine = ss.getEngineByName(nm);
if (!engine)
{ return; }
var submission = engine.getSubmission(text,null);
if (!submission)
{ return; }
searchTab3(submission.uri.spec);
};
searchArray = function(text) // need a way to decide the tab from here????????????
{
if (!text)
{ var text = ""; }
var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService).getEngines([]);
var arr = [];
for (var i in ss)
{ arr.push(
{
label: ss[i].name,
oncommand: "searchCommand('" + ss[i].name + "','" + text + "');",
class: "menuitem-iconic searchbar-engine-menuitem menuitem-with-favicon",
src: ss[i].iconURI.spec
} );
}
return arr;
};
customMenuArray = function(url)
{
var a =
[
{
label: "Open Selection as URL",
oncommand: "searchTab3(" + '"' + url + '"' + ");",
},
null,
];
return a;
};
//search terms: from selected text or clipboard or whatever
if (event.ctrlKey)
{ var str = readFromClipboard(); }
else
{ var str = FireGestures.getSelectedText(); }
menu = customMenuArray(str);
menu.push.apply(menu,searchArray(str));
FireGestures.generatePopup(event,menu);
I put this togheter from parts that I found via google on a chinese website where i learned from a chinese God coder that firegestures can be used to create entire totally custom context menus (with submenus, icons, separators, external apps, etc.) using arrays of names and commands.
This particular one recreate the "[Popup] Search for Selection with..." function (select some text and choose which of your installed search engines to use to do a search).
The good thing is that here I can decide the search terms to use and in which tab to perform the search. What I need (if possible) is a way to determine the search tab form the LAST function (searchArray) without having to duplicate things around over and over.
But all this functions inside functions business is way too much for me; in fact I really understand only half of all this. So, if anyone understood anything I wrote, I accept suggestions.
Thanks for the help.
Edit
Other problems after a bit of testing: the search is broken it the apostrophe (') char is selected or by end of paragraph.
Edit2
I worked out some problems and all seems fine now. This is the result:
Code: Select all
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var recentWindow = wm.getMostRecentWindow("navigator:browser");
var browser = recentWindow.gBrowser;
openSearchLink = function(i)
{
url = searchUrls[i];
if (!url)
{ alert("Invalid URL.");
return; }
else if (event.shiftKey) // press SHIFT: open tab at end
{ browser.addTab(url); }
else if (event.ctrlKey) // press CTRL: open in current tab
{ var tab = browser.loadURI(url); }
else // press nothing: open in next tab
{ var pos = browser.selectedTab._tPos;
var tab = browser.addTab(url);
browser.moveTabTo(tab,pos+1); }
};
openCustomLink = function(i)
{
url = customUrls[i];
if (!url)
{ alert("Invalid URL.");
return; }
else if (event.shiftKey) // press SHIFT: open tab at end
{ browser.addTab(url); }
else if (event.ctrlKey) // press CTRL: open in current tab
{ var tab = browser.loadURI(url); }
else // press nothing: open in next tab
{ var pos = browser.selectedTab._tPos;
var tab = browser.addTab(url);
browser.moveTabTo(tab,pos+1); }
};
createSearchArray = function(text)
{
var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var tt = ss.getEngines([]);
var arr = [];
for (var i in tt)
{ var engine = ss.getEngineByName(tt[i].name);
var submission = engine.getSubmission(text,null);
searchUrls.push(submission.uri.spec);
arr.push(
{
label: tt[i].name,
oncommand: "openSearchLink(" + i + ");",
class: "menuitem-iconic searchbar-engine-menuitem menuitem-with-favicon",
src: tt[i].iconURI.spec,
}
);
}
return arr;
};
if (event.altKey) // press ALT: search from clipboard
{ var str = readFromClipboard();
if (!str)
{ alert("Clipboard is empty.");
return; }
}
else // press nothing: search from selection
{ var str = FireGestures.getSelectedText(); }
var searchUrls = [];
searchArray = createSearchArray(str);
var customUrls = [str];
var customArray =
[
{
label: "Open as URL",
oncommand: "openCustomLink(0);",
},
null,
];
menuArray = customArray.concat(searchArray);
FireGestures.generatePopup(event,menuArray);
Could you point out problems and improvements if you find any? Thanks.