Skip to content

Instantly share code, notes, and snippets.

@benoitryder
Last active November 21, 2018 20:39
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save benoitryder/db1ed51ca0213b882806fad1f4540796 to your computer and use it in GitHub Desktop.
Save benoitryder/db1ed51ca0213b882806fad1f4540796 to your computer and use it in GitHub Desktop.
Change tabs with mousewheel in Firefox 57
// Change tabs with mousewheel
// Run into Browser Toolbox console
function onTabWheel(ev) {
if (ev.deltaMode == 1 /* DOM_DELTA_LINE */) {
var idx = Array.prototype.slice.call(gBrowser.tabs).indexOf(gBrowser.selectedTab);
if (ev.deltaY > 0) {
if (idx + 1 < gBrowser.tabs.length) {
gBrowser.selectTabAtIndex(idx + 1);
}
} else if (ev.deltaY < 0) {
if (idx > 0) {
gBrowser.selectTabAtIndex(idx - 1);
}
}
}
}
gBrowser.tabs.forEach(function(tab) {
tab.addEventListener("wheel", onTabWheel);
});
var tabObserver = new MutationObserver(function(records, observer) {
records.forEach(function(record) {
record.addedNodes.forEach(function(tab) {
tab.addEventListener("wheel", onTabWheel);
});
record.removedNodes.forEach(function(tab) {
tab.removeEventListener("wheel", onTabWheel);
});
});
});
tabObserver.observe(gBrowser.tabContainer, {childList: true});
@Chaphasilor
Copy link

Hey, I tried running your code but I get an error saying "gBrowser is not defined".
Any ideas?

@benoitryder
Copy link
Author

Did your try to run it in the Browser Toolbox?

@Keith94
Copy link

Keith94 commented Nov 21, 2017

I get the same error in Fx59. :( I put it in Browser Toolbox console.

TypeError: gBrowser.tabContainer.mTabstrip is undefined

@fm3
Copy link

fm3 commented Nov 21, 2017

works for me, thanks! is there a way to run this on startup?

@benoitryder
Copy link
Author

@Keith94 The first revision of the gist doesn't use mTabstrip. It might work with your version.

@fm3 Not that I know of. :(

@sanao
Copy link

sanao commented Jan 25, 2018

The lastest version doesn't works with Firefox 58, but the first version works well.

Vote here to integrate this feature natively.

@fm3
Copy link

fm3 commented Jan 27, 2018

For compatibility with Firefox 58, in my fork I changed mTabstrip._scrollbox to arrowScrollbox. They renamed it in 1415537

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment