hello!
I want with one click, a script to scan the text of all the opened tabs and close all those tabs that the webpage has "some text" in it!
thanks!
close per filter
- DanRaisch
- Moderator
- Posts: 127231
- Joined: September 23rd, 2004, 8:57 pm
- Location: Somewhere on the right coast
Re: close per filter
Have you searched the Addons site to see if an extension exists to meet this latest desire? https://addons.mozilla.org/en-US/firefox/
-
- Posts: 1086
- Joined: November 8th, 2011, 12:06 pm
Re: close per filter
DanRaisch wrote:Have you searched the Addons site to see if an extension exists to meet this latest desire? https://addons.mozilla.org/en-US/firefox/
yup, but nothing relevant came up by searching with my search terms
- DanRaisch
- Moderator
- Posts: 127231
- Joined: September 23rd, 2004, 8:57 pm
- Location: Somewhere on the right coast
Re: close per filter
Then it is quite possible that the functionality you seek is not available.
-
- Posts: 1086
- Joined: November 8th, 2011, 12:06 pm
Re: close per filter
is it easy to implement?
- malliz
- Folder@Home
- Posts: 43796
- Joined: December 7th, 2002, 4:34 am
- Location: Australia
Re: close per filter
What sort of man would put a known criminal in charge of a major branch of government? Apart from, say, the average voter.
"Terry Pratchett"
"Terry Pratchett"
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: close per filter
firefoxuse wrote:is it easy to implement?
Try using the nsIFind interface.
http://www.borngeek.com/2011/10/03/usin ... interface/
http://mxr.mozilla.org/mozilla-release/ ... sIFind.idl
http://mxr.mozilla.org/mozilla-release/ ... ar.xml#957
Code: Select all
function searchContent(term, win) {
if (!win) { return false; }
var textFound = false;
// Handle searching within frames
for (var i = 0; win.frames && i < win.frames.length; i++) {
if (searchContent(term, win.frames[i])) {
textFound = true;
}
}
var doc = win.document; // Get a reference to the document
if (!doc) { return false; }
var body = doc.body; // Get a reference to the body element
if (!body) { return false; }
// Create our search range
var searchRange = doc.createRange();
searchRange.selectNodeContents(body);
// Create the start point
var start = searchRange.cloneRange();
start.collapse(true); // Collapse to the beginning
// Create the end point
var end = searchRange.cloneRange();
end.collapse(false); // Collapse to the end
// Create the finder instance
var finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"].
createInstance(Components.interfaces.nsIFind);
// Perform the find operation
var result = finder.Find(term, searchRange, start, end);
if (result) {
textFound = true;
}
return textFound;
}
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
getService(Components.interfaces.nsIPromptService);
var title = "Close Tabs";
var description = "Enter text to search for:";
var input = {value: "Firefox"};
var message = null; // Hide the check box
var state = {value: true};
var ok = ps.prompt(null, title, description, input, message, state);
if (ok) {
for (var i = gBrowser.tabs.length - 1; i >= 0; i--) {
var browser = gBrowser.getBrowserForTab(gBrowser.tabs[i]);
if (searchContent(input.value, browser.contentWindow)) {
gBrowser.removeTab(gBrowser.tabs[i]);
}
}
}