Notion Navigation Fixer

Allow browser nav options like back forward pgup pgdown

  1. // ==UserScript==
  2. // @name Notion Navigation Fixer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Allow browser nav options like back forward pgup pgdown
  6. // @author Andreas Huttenrauch
  7. // @match *://www.notion.so/*
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function uniqid() {
  17. return (new Date().getTime()).toString(16) + Math.random().toString(16).substring(2, 15);
  18. }
  19.  
  20. function windowId() {
  21. var id = window.name;
  22. if ( id == "" ) {
  23. id = uniqid();
  24. window.name = id;
  25. }
  26. return id;
  27. }
  28.  
  29. function getStack() {
  30. var stack = JSON.parse(GM_getValue("notion_stack_"+windowId(), "{}"));
  31. if ( typeof stack != "object" ) stack = {};
  32. if ( ! ("index" in stack) ) stack.index = 0;
  33. if ( ! ("data" in stack) ) stack.data = [];
  34. return stack;
  35. }
  36.  
  37. function setStack(stack) {
  38. GM_setValue("notion_stack_"+windowId(), JSON.stringify(stack));
  39. }
  40.  
  41. function pushLoc() {
  42. var loc = window.location.href;
  43. var stack = getStack();
  44. if ( stack.index < stack.data.length ) return; // don't push if we navigated back in history
  45. stack.data.push(loc);
  46. stack.data = stack.data.slice(-20);
  47. stack.index = stack.data.length;
  48. setStack(stack);
  49. }
  50.  
  51. function goBack() {
  52. var stack = getStack();
  53. if ( stack.index < 1 ) return;
  54. stack.index--;
  55. var loc = stack.data[stack.index];
  56. setStack(stack);
  57. window.location.href = loc;
  58. }
  59.  
  60. function goForward() {
  61. var stack = getStack();
  62. if ( stack.index >= stack.data.length ) return;
  63. stack.index++;
  64. var loc = stack.data[stack.index];
  65. setStack(stack);
  66. window.location.href = loc;
  67. }
  68.  
  69. /*
  70. window.addEventListener('popstate', function(e) {
  71. if ( trapInit && trapCaught ) {
  72. e.preventDefault();
  73. e.stopImmediatePropagation();
  74. }
  75. trapCaught = true;
  76. });
  77. */
  78.  
  79. document.addEventListener('mousedown', function(e) {
  80. if ( (e.buttons & 8) == 8 ) {
  81. e.stopImmediatePropagation();
  82. e.preventDefault();
  83. goBack();
  84. }
  85. if ( (e.buttons & 16) == 16 ) {
  86. e.stopImmediatePropagation();
  87. e.preventDefault();
  88. goForward();
  89. }
  90. });
  91.  
  92. document.addEventListener('keydown', function(e) {
  93. //console.log(e);
  94. /*
  95. if ( e.target.contentEditable ) {
  96. console.log("not moving because you are editing something important");
  97. return;
  98. }
  99. */
  100. if ( e.keyCode == 37 && e.altKey ) {
  101. goBack();
  102. }
  103. if ( e.keyCode == 39 && e.altKey ) {
  104. goForward();
  105. }
  106. var mainDiv = document.querySelector(".notion-frame .notion-scroller");
  107. if ( mainDiv == "undefined" ) return;
  108. var scrollAmt = parseInt(window.innerHeight*0.8);
  109. if ( e.keyCode == 34 && e.shiftKey == false && e.ctrlKey == false ) {
  110. e.stopImmediatePropagation();
  111. e.preventDefault();
  112. mainDiv.scrollBy(0, scrollAmt);
  113. }
  114. if ( e.keyCode == 33 && e.shiftKey == false && e.ctrlKey == false ) {
  115. e.stopImmediatePropagation();
  116. e.preventDefault();
  117. mainDiv.scrollBy(0, -scrollAmt);
  118. }
  119. });
  120.  
  121.  
  122. pushLoc();
  123.  
  124. })();
  125.  
  126.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址