For a mouseless future.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1021B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var tabs = require("sdk/tabs");
  2. var self = require("sdk/self");
  3. tabs.on("ready", function(tab) {
  4. var worker = tab.attach({
  5. contentScriptFile: self.data.url("onload.js")
  6. });
  7. function selectRelativeTab(n) {
  8. var tabList = [];
  9. var currentTabIndex;
  10. for (let t of tabs) {
  11. tabList[t.index] = t;
  12. if (t.index == tab.index) {
  13. currentTabIndex = t.index;
  14. }
  15. }
  16. var newTabIndex = currentTabIndex + n;
  17. if (newTabIndex >= tabList.length) {
  18. newTabIndex = 0;
  19. } else if (newTabIndex < 0) {
  20. newTabIndex = tabList.length - 1;
  21. }
  22. tabList[newTabIndex].activate();
  23. }
  24. function moveRelativeTab(n) {
  25. tab.index += n;
  26. }
  27. worker.port.on("tab_open", function(url) {
  28. tabs.open(url);
  29. });
  30. worker.port.on("change_tab_left", function() {
  31. selectRelativeTab(-1);
  32. });
  33. worker.port.on("change_tab_right", function() {
  34. selectRelativeTab(1);
  35. });
  36. worker.port.on("move_tab_left", function() {
  37. moveRelativeTab(-1);
  38. });
  39. worker.port.on("move_tab_right", function() {
  40. moveRelativeTab(1);
  41. });
  42. });