Switch Page Direction

Switch Page Direction from LTR to RTL and vice versa. Hotkey: Command + Shift + D.

  1. // ==UserScript==
  2. // @name Switch Page Direction
  3. // @description Switch Page Direction from LTR to RTL and vice versa. Hotkey: Command + Shift + D.
  4. // @author Schimon Jehudah, Adv.
  5. // @namespace i2p.schimon.direction
  6. // @homepageURL https://greasyfork.org/en/scripts/467248-switch-page-direction-hotkey
  7. // @supportURL https://greasyfork.org/en/scripts/467248-switch-page-direction-hotkey/feedback
  8. // @copyright 2023, Schimon Jehudah (http://schimon.i2p)
  9. // @license Public Domain
  10. // @match file:///*
  11. // @exclude devtools://*
  12. // @match *://*/*
  13. // @version 23.06
  14. // @run-at document-end
  15. // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7ihpTvuI88L3RleHQ+PC9zdmc+Cg==
  16. // ==/UserScript==
  17.  
  18. document.onkeyup = function(e) {
  19. // Command + Shift + D
  20. if (e.metaKey && e.shiftKey && e.which == 68) {
  21. switchPageDirection();
  22. }
  23. };
  24.  
  25. function switchPageDirection() {
  26. if (document.dir == 'ltr' || !document.dir) {
  27. document.dir = 'rtl';
  28. } else {
  29. document.dir = 'ltr';
  30. }
  31. return switchPageDirection;
  32. }
  33.  
  34. /*
  35.  
  36. NOTE In case we can use context-menu and document-end in same userscript
  37.  
  38. // @run-at context-menu
  39. // @run-at document-end
  40.  
  41.  
  42. var switchPageDirection = (function switchPageDirection() {
  43. if (!document.dir) {
  44. document.dir = 'rtl';
  45. } else if (document.dir == 'ltr') {
  46. document.dir = 'rtl';
  47. } else if (document.dir == 'rtl') {
  48. document.dir = 'ltr';
  49. }
  50. return switchPageDirection;
  51. })();
  52.  
  53. */