搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Is there an extension that will allow one to close tabs that contain in their titles a given string of characters?

  • 1 个回答
  • 1 人有此问题
  • 2 次查看
  • 最后回复者为 cor-el

more options

I have searched, but I cannot find an extension that will enable the closing of tabs that contain a given string of characters in their titles. If such an extension also enabled other actions to such tabs, such as moving them to another window, that would be great. Thanks for your help, if you can.

I have searched, but I cannot find an extension that will enable the closing of tabs that contain a given string of characters in their titles. If such an extension also enabled other actions to such tabs, such as moving them to another window, that would be great. Thanks for your help, if you can.

所有回复 (1)

more options

The only extension I know that deals with multiple tabs is the Multiple Tab Handler extension

If you know something about programming then you can use this JavaScript code as a start. R sets the regular expression to match the title and T sets the maximum number of tabs to close starting with the last tab and counting backward. With T=0 no tabs are removed, so use this to test the regular expression R. Use this at your own risk. Note that you can undo closed tabs up to the maximum as set via browser.sessionstore.max_tabs_undo and possibly set T=1 to close one tab each time you click Run.

You can use the Scratchpad and run the JavaScript code posted below.

  • open the Environment menu in the Scratchpad and select Browser to run the JavaScript code in Browser context
  • paste the JavaScript code in the editor area
  • click Run to run the JavaScript code

You can see messages in the Browser Console.


var R = RegExp("firefox","i"), T=0;
var wm = Services.wm;
var gB = wm.getMostRecentWindow("navigator:browser").gBrowser;
var tC = gB.mTabContainer;

function objURI(t,u,n){with(this){tab=t; uri=u; name=n;}}
objURI.prototype={tab:"", uri:"", name:""};

var lC = gB.mPanelContainer.childNodes.length, i, t=[], u;
for(i=lC-1; i>=0; i--){
cD=gB.getBrowserAtIndex(i).contentDocument;
if(R.test(cD.title)){
 u=new objURI(i, cD.location.href, cD.title);
 t.push(u);
 if(T){
  T--; 
  tC.selectedIndex = i;
  BrowserCloseTabOrWindow();
  console.log("closed",i, cD.title);
 }
}
}
console.log(JSON.stringify(t, null, 1));