為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

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));