Patch to add follow next/prev link when page scrolling at bot/top Rated 5 out of 5 stars

Hi, I added a patch so that when use PageUp/PageDown, and if the document is at beginning/end, Firemacs will try to find a prev/next link/image, and follow that link. This way, one more mouse clicking is reduced for me:-)Thanks for the great Add-on. you can check my patch at http://github.com/baohaojun/windows-config/raw/master/gcode/Firemacs

This review is for a previous version of the add-on (3.8). 

Rated 5 out of 5 stars

Hi, I added a patch so that when use PageUp/PageDown, and if the document is at beginning/end, Firemacs will try to find a prev/next link/image, and follow that link. This way, one more mouse clicking is reduced for me:-)

Thanks for the great Add-on. Here's the patch (you can also check it at http://github.com/baohaojun/windows-config/raw/master/gcode/Firemacs):

<pre><code>diff --git a/gcode/Firemacs/chrome/content/db/firemacs.yml b/gcode/Firemacs/chrome/content/db/firemacs.yml
index 89a16e9..b6428bf 100644
--- a/gcode/Firemacs/chrome/content/db/firemacs.yml
+++ b/gcode/Firemacs/chrome/content/db/firemacs.yml
@@ -114,14 +114,14 @@ type:
name: ViScrollPageUp
case: View
keyx: DEL
-body: goDoCommand('cmd_scrollPageUp');
+body: this._sfun.subPageUp(e);
desc: scrolls a page up
type:
-
name: ViScrollPageDown
case: View
keyx: SPC
-body: goDoCommand('cmd_scrollPageDown');
+body: this._sfun.subPageDown(e);
desc: scrolls a page down
type:
-
diff --git a/gcode/Firemacs/chrome/content/keybinding.js b/gcode/Firemacs/chrome/content/keybinding.js
index 8562007..e574eb2 100644
--- a/gcode/Firemacs/chrome/content/keybinding.js
+++ b/gcode/Firemacs/chrome/content/keybinding.js
@@ -31,10 +31,10 @@ Firemacs.Commands.View = {
this._sfun.moveTab(1);
},
ViScrollPageUp: function(e) {
- goDoCommand('cmd_scrollPageUp');
+ this._sfun.subPageUp(e);
},
ViScrollPageDown: function(e) {
- goDoCommand('cmd_scrollPageDown');
+ this._sfun.subPageDown(e);
},
PreviousPage: function(e) {
if (typeof(BrowserBack) == 'function') { BrowserBack(); }
diff --git a/gcode/Firemacs/chrome/content/subfunc.js b/gcode/Firemacs/chrome/content/subfunc.js
index ff6d6f7..64d2132 100644
--- a/gcode/Firemacs/chrome/content/subfunc.js
+++ b/gcode/Firemacs/chrome/content/subfunc.js
@@ -179,6 +179,48 @@ Firemacs.SubFunc = {
}
}
},
+
+ subPageDown: function(e) {
+ var doc = e.target.ownerDocument;
+ var wnd = doc.defaultView;
+ if (wnd.pageYOffset + wnd.innerHeight &gt;= doc.height) {
+ this._followLink(1, wnd, doc);
+ } else {
+ goDoCommand('cmd_scrollPageDown');
+ }
+ },
+
+ subPageUp: function(e) {
+ var doc = e.target.ownerDocument;
+ var wnd = doc.defaultView;
+ if (wnd.pageYOffset == 0) {
+ this._followLink(-1, wnd, doc);
+ } else {
+ goDoCommand('cmd_scrollPageUp');
+ }
+ },
+
+ _followLink: function(dir, wnd, doc) {
+ var re;
+ if (dir &gt; 0) {
+ re = /next|&gt;|下一/i;
+ } else {
+ re = /prev|&lt;|上一/i;
+ }
+ var links = doc.links;
+ for (i = 0; i &lt; links.length; ++i) {
+ if (links[i].textContent &amp;&amp; links[i].textContent.search(re) != -1 &amp;&amp;
+ links[i].href) {
+ loadURI(links[i].href);
+ return;
+ }
+ imgElems = links[i].getElementsByTagName("img"); // Is it an image tag?
+ if (imgElems.length &gt; 0 &amp;&amp; imgElems[0].src &amp;&amp; imgElems[0].src.search(re) != -1 &amp;&amp; links[i].href) {
+ loadURI(links[i].href);
+ return;
+ }
+ }
+ },

////////////////////////////////////////////////////////////////
//
</code></pre>

This review is for a previous version of the add-on (3.8).