-
Notifications
You must be signed in to change notification settings - Fork 2
Community Shared Commands
-
Close all Tabs to Right
{ exec() { var win = Services.wm.getMostRecentWindow('navigator:browser'); if (!win) return; var gbrowser = win.gBrowser; var targettabs = []; var tabs = gbrowser.visibleTabs; var foundself = false; var selftab = gbrowser.selectedTab; for (var tab of tabs) { if (foundself && !tab.pinned) gbrowser.removeTab(tab, { animated:true }) if (tab == selftab) foundself = true; } } }
* **Close Tabs to Left**
{ exec() { var win = Services.wm.getMostRecentWindow('navigator:browser'); if (!win) return; var gbrowser = win.gBrowser; var targettabs = []; var tabs = gbrowser.visibleTabs; var foundself = false; var selftab = gbrowser.selectedTab; for (var tab of tabs) { if (tab == selftab) break; else gbrowser.removeTab(tab, { animated:true }) } } }
* **Close All Other Tabs**
{ exec() { var win = Services.wm.getMostRecentWindow('navigator:browser'); if (!win) return; var gbrowser = win.gBrowser; var targettabs = []; var tabs = gbrowser.visibleTabs; var selftab = gbrowser.selectedTab; for (var tab of tabs) { if (tab != selftab && !tab.pinned) gbrowser.removeTab(tab, { animated:true }) } } }
* **Unbookmark then Close Tab**
{ exec() { // var FOLDER_NAME_ = 'Bollywood Movies'; // set to string, name of folder you want bookmark placed in, if it exists, it adds there, if it doesnt exist, it is created var TOP_LEVEL_GROUP_NAME = 'TOOLBAR'; // MENU, TOOLBAR, UNSORTED
var COMMONJS_URI = 'resource://gre/modules/commonjs';
var { require } = Cu.import(COMMONJS_URI + '/toolkit/require.js', {});
var { Bookmark, Group, save, remove, search, [TOP_LEVEL_GROUP_NAME]:top_level_group } = require('sdk/places/bookmarks');
var win = Services.wm.getMostRecentWindow('navigator:browser');
var title = win.gBrowser.selectedTab.getAttribute('label');
var url = win.gBrowser.currentURI.spec;
var closeTabOrWin = () => win.BrowserCloseTabOrWindow();
// test is it bookmarked
search({query:url})
.on('end', function(results) {
var filtered = results.filter(el => el.url == url);
if (filtered.length) {
// IT IS BOOKMARKED so remove it then close tab
save(remove(filtered)).on('end', ()=>console.log('removed', closeTabOrWin()));
} else {
// IT IS NOT BOOKMARKED so just close tab
closeTabOrWin();
}
});
}
}
* **Toggle Bookmark**
{ exec() { // var FOLDER_NAME_ = 'Bollywood Movies'; // set to string, name of folder you want bookmark placed in, if it exists, it adds there, if it doesnt exist, it is created var TOP_LEVEL_GROUP_NAME = 'TOOLBAR'; // MENU, TOOLBAR, UNSORTED
var COMMONJS_URI = 'resource://gre/modules/commonjs';
var { require } = Cu.import(COMMONJS_URI + '/toolkit/require.js', {});
var { Bookmark, Group, save, remove, search, [TOP_LEVEL_GROUP_NAME]:top_level_group } = require('sdk/places/bookmarks');
var win = Services.wm.getMostRecentWindow('navigator:browser');
var title = win.gBrowser.selectedTab.getAttribute('label');
var url = win.gBrowser.currentURI.spec;
// test is it bookmarked
search({query:url})
.on('end', function(results) {
var filtered = results.filter(el => el.url == url);
if (filtered.length) {
// IT IS BOOKMARKED
save(remove(filtered)).on('end', ()=>console.log('removed'));
} else {
// IT IS NOT BOOKMARKED so bookmark it
save(Bookmark({ title, url, group:top_level_group })).on('end', ()=>console.log('saved'));
}
});
}
}
* **Send Key** - this examples sends paste command (<key>Control</key> + <key>V</key> on Windows/Linux or <key>Meta</key> + <key>V</key> if it's a Mac)
{ exec: function() { var window = Services.wm.getMostRecentWindow(null); var utils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
var key = char => String.charCodeAt(char);
var sendChar = (char, mods) => utils.sendKeyEvent('keypress', key(char), key(char), mods || 0);
sendChar('V', core.os.mname == 'darwin' ? Ci.nsIDOMWindowUtils.MODIFIER_META : Ci.nsIDOMWindowUtils.MODIFIER_CONTROL);
}
}
* **Send Keys** - this examples sends multiple keys known as a "string". This types "yay firefox!"
{ exec: function() { var window = Services.wm.getMostRecentWindow(null); var utils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
var key = char => String.charCodeAt(char);
var sendChar = (char, mods) => utils.sendKeyEvent('keypress', key(char), key(char), mods || 0);
var sendStr = str => Array.forEach.call(null, str, char=>sendChar(char))
sendStr('yay firefox!');
}
}