Touch UI back and forward buttons for FireFox

Fixing FireFox Touch navigation

  1. // ==UserScript==
  2. // @name Touch UI back and forward buttons for FireFox
  3. // @namespace userscript@fabian.dk
  4. // @version 0.2
  5. // @description Fixing FireFox Touch navigation
  6. // @author Tony Fabian
  7. // @include *://*/*
  8. // @grant none
  9. // @license MIT
  10. // @noframes
  11. // ==/UserScript==
  12. (function () {
  13. // Register touchstart and touchend listeners for element 'source'
  14. var src = document.getElementsByTagName("body")[0];
  15. var clientX, clientY;
  16. src.addEventListener('touchstart', function (e) {
  17. // Cache the client X/Y coordinates
  18. clientX = e.touches[0].clientX;
  19. clientY = e.touches[0].clientY;
  20. }, false);
  21. src.addEventListener('touchend', function (e) {
  22. var deltaX, deltaY;
  23. // Compute the change in X and Y coordinates.
  24. // The first touch point in the changedTouches
  25. // list is the touch point that was just removed from the surface.
  26. deltaX = e.changedTouches[0].clientX - clientX;
  27. deltaY = e.changedTouches[0].clientY - clientY;
  28. if (deltaX <= -75) {
  29. console.log("navigate back");
  30. history.back();
  31. }
  32. if (deltaX >= 75) {
  33. console.log("navigate forward");
  34. history.forward();
  35. }
  36. }, false);
  37. })();