librelist archives

« back to archive

[PATCH 0/7] reddit-mode fixes

[PATCH 0/7] reddit-mode fixes

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
In the last month or so some changes have been made by reddit which
broke reddit-mode. This patchset makes reddit-mode work again. No new
features have been added. While working on this I came across some
other miscellaneous bugs and annoyances that were also fixed.

Joren Van Onder (7):
  reddit.js: make highlight stylesheet work on https reddit
  reddit.js: update XPath expression that finds prev and next buttons
  reddit.js: don't try to wrap to the previous page when on the first one
  reddit.js: adjust to new way reddit handles collapsed comments
  reddit.js: handle 'continue this thread' links correctly
  reddit.js: optimize previous link wrap behavior
  reddit.js: restrict stylesheet on domain instead of url-prefix

 modules/page-modes/reddit.js | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

--
2.1.0

[PATCH 5/7] reddit.js: handle 'continue this thread' links correctly

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
Also clean up the way 'load more comments' links are found.
---
 modules/page-modes/reddit.js | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index a3f9e61..bf65a12 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -173,10 +173,13 @@ function get_entries_without_collapsed_comments (entries) {
     var collapsed_parent = null;
     for (var i = 0, elen = entries.length; i < elen; i++) {
         if (collapsed_parent) {
-            // Discard the 'load more comments' buttons
-            var current_classname = 
entries[i].getElementsByTagName("span")[0].className;
+            // Discard the 'load more comments' links
+            var load_more_comments = entries[i].querySelector(".morecomments");
+            // Discard the 'continue this thread' links
+            var continue_this_thread = entries[i].querySelector(".deepthread");
+
             if (!comment_is_child(collapsed_parent, entries[i].parentNode) &&
-                current_classname != "morecomments")
+                !load_more_comments && !continue_this_thread)
             {
                 collapsed_parent = null;
             } else { // Skip collapsed comments
-- 
2.1.0

[PATCH 1/7] reddit.js: make highlight stylesheet work on https reddit

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
Needed because https://www.reddit.com has been officialy launched [1].

[1] http://www.redditblog.com/2014/09/hell-its-about-time-reddit-now-supports.html
---
 modules/page-modes/reddit.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index 4e83127..c9bb8b6 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -22,7 +22,8 @@ register_user_stylesheet(
     "data:text/css," +
         escape (
             "@-moz-document url-prefix(http://www.reddit.com/)," +
-		"url-prefix(https://pay.reddit.com) {" +
+                "url-prefix(https://pay.reddit.com)," +
+                "url-prefix(https://www.reddit.com) {" +
                 "body>.content .last-clicked {" +
                 " background-color: #bfb !important;" +
                 " border: 0px !important;"+
-- 
2.1.0

[PATCH 3/7] reddit.js: don't try to wrap to the previous page when on the first one

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
---
 modules/page-modes/reddit.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index 54c0aa2..ae473c9 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -345,8 +345,9 @@ function reddit_prev_link (I) {
                 if (xpr && (prevpage = xpr.iterateNext())) {
                     dom_remove_class(current, "last-clicked");
                     browser_object_follow(I.buffer, FOLLOW_DEFAULT, prevpage);
-                    return;
                 }
+
+                return;
             }
         }
     }
-- 
2.1.0

[PATCH 2/7] reddit.js: update XPath expression that finds prev and next buttons

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
Changed in:
https://github.com/reddit/reddit/commit/3341b2049e3cdab39c0254d3a1743c13cfcebfc2
---
 modules/page-modes/reddit.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index c9bb8b6..54c0aa2 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -112,7 +112,7 @@ function reddit_next_link (I) {
                 next = first;
             if (reddit_end_behavior == 'page') {
                 let (xpr = doc.evaluate(
-                    '//p[@class="nextprev"]/a[contains(text(),"next")]', 
doc, null,
+                    
'//span[@class="nextprev"]/a[contains(text(),"next")]', doc, null,
                     Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null))
                 {
                     var nextpage;
@@ -338,7 +338,7 @@ function reddit_prev_link (I) {
             }
         } else if (reddit_end_behavior == 'page') {
             let (xpr = doc.evaluate(
-                '//p[@class="nextprev"]/a[contains(text(),"prev")]', doc, null,
+                '//span[@class="nextprev"]/a[contains(text(),"prev")]', 
doc, null,
                 Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null))
             {
                 var prevpage;
-- 
2.1.0

[PATCH 7/7] reddit.js: restrict stylesheet on domain instead of url-prefix

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
This is cleaner because Reddit has a lot of subdomains including
subdomains for a bunch of different languages (eg. en., fr., de., ...).
---
 modules/page-modes/reddit.js | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index cad296e..17ab375 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -21,9 +21,7 @@ define_variable("reddit_end_behavior", "stop",
 register_user_stylesheet(
     "data:text/css," +
         escape (
-            "@-moz-document url-prefix(http://www.reddit.com/)," +
-                "url-prefix(https://pay.reddit.com)," +
-                "url-prefix(https://www.reddit.com) {" +
+            "@-moz-document domain(reddit.com) {" +
                 "body>.content .last-clicked {" +
                 " background-color: #bfb !important;" +
                 " border: 0px !important;"+
-- 
2.1.0

[PATCH 6/7] reddit.js: optimize previous link wrap behavior

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
Checking the display style in the loop doesn't make much sense because
that would only matter if every link on the page was invisible. Even if
this is the case this loop would still not catch that because
dom_add_class() and reddit_scroll_into_view() would later be called with
prev being null.
---
 modules/page-modes/reddit.js | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index bf65a12..cad296e 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -331,11 +331,7 @@ function reddit_prev_link (I) {
         } else if (reddit_end_behavior == 'wrap') {
             // need to get last link on page.
             if (complete) {
-                for (var i = 0; i < llen; i++) {
-                    if (links[i].style.display == 'none')
-                        continue;
-                    prev = links[i];
-                }
+                prev = links[llen - 1];
             }
         } else if (reddit_end_behavior == 'page') {
             let (xpr = doc.evaluate(
-- 
2.1.0

[PATCH 4/7] reddit.js: adjust to new way reddit handles collapsed comments

From:
Joren Van Onder
Date:
2014-09-12 @ 15:36
---
 modules/page-modes/reddit.js | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index ae473c9..a3f9e61 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -184,9 +184,7 @@ function get_entries_without_collapsed_comments (entries) {
             }
         }
         // Collapsed comment
-        if (i != 0 &&
-            entries[i].getElementsByTagName("div")[1].style.display == "none")
-        {
+        if (i != 0 && entries[i].parentNode.className.match(/\bcollapsed\b/)) {
             collapsed_parent = entries[i].parentNode;
         }
         entries_without_collapsed.push(entries[i]);
-- 
2.1.0

[PATCH 0/7] reddit-mode fixes

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
In the last month or so some changes have been made by reddit which
broke reddit-mode. This patchset makes reddit-mode work again. No new
features have been added. While working on this I came across some
other miscellaneous bugs and annoyances that were also fixed.

Joren Van Onder (7):
  reddit.js: make highlight stylesheet work on https reddit
  reddit.js: update XPath expression that finds prev and next buttons
  reddit.js: don't try to wrap to the previous page when on the first one
  reddit.js: adjust to new way reddit handles collapsed comments
  reddit.js: handle 'continue this thread' links correctly
  reddit.js: optimize previous link wrap behavior
  reddit.js: restrict stylesheet on domain instead of url-prefix

 modules/page-modes/reddit.js | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

--
2.1.0

Re: [conkeror] [PATCH 0/7] reddit-mode fixes

From:
John J. Foerch
Date:
2014-10-22 @ 01:59
thanks, all pushed

On Fri, Oct 17, 2014 at 05:14:34PM +0200, Joren Van Onder wrote:
> In the last month or so some changes have been made by reddit which
> broke reddit-mode. This patchset makes reddit-mode work again. No new
> features have been added. While working on this I came across some
> other miscellaneous bugs and annoyances that were also fixed.
> 
> Joren Van Onder (7):
>   reddit.js: make highlight stylesheet work on https reddit
>   reddit.js: update XPath expression that finds prev and next buttons
>   reddit.js: don't try to wrap to the previous page when on the first one
>   reddit.js: adjust to new way reddit handles collapsed comments
>   reddit.js: handle 'continue this thread' links correctly
>   reddit.js: optimize previous link wrap behavior
>   reddit.js: restrict stylesheet on domain instead of url-prefix
> 
>  modules/page-modes/reddit.js | 29 +++++++++++++----------------
>  1 file changed, 13 insertions(+), 16 deletions(-)
> 
> --
> 2.1.0

[PATCH 6/7] reddit.js: optimize previous link wrap behavior

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
Checking the display style in the loop doesn't make much sense because
that would only matter if every link on the page was invisible. Even if
this is the case this loop would still not catch that because
dom_add_class() and reddit_scroll_into_view() would later be called with
prev being null.
---
 modules/page-modes/reddit.js | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index bf65a12..cad296e 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -331,11 +331,7 @@ function reddit_prev_link (I) {
         } else if (reddit_end_behavior == 'wrap') {
             // need to get last link on page.
             if (complete) {
-                for (var i = 0; i < llen; i++) {
-                    if (links[i].style.display == 'none')
-                        continue;
-                    prev = links[i];
-                }
+                prev = links[llen - 1];
             }
         } else if (reddit_end_behavior == 'page') {
             let (xpr = doc.evaluate(
-- 
2.1.0

[PATCH 1/7] reddit.js: make highlight stylesheet work on https reddit

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
Needed because https://www.reddit.com has been officialy launched [1].

[1] http://www.redditblog.com/2014/09/hell-its-about-time-reddit-now-supports.html
---
 modules/page-modes/reddit.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index 4e83127..c9bb8b6 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -22,7 +22,8 @@ register_user_stylesheet(
     "data:text/css," +
         escape (
             "@-moz-document url-prefix(http://www.reddit.com/)," +
-		"url-prefix(https://pay.reddit.com) {" +
+                "url-prefix(https://pay.reddit.com)," +
+                "url-prefix(https://www.reddit.com) {" +
                 "body>.content .last-clicked {" +
                 " background-color: #bfb !important;" +
                 " border: 0px !important;"+
-- 
2.1.0

[PATCH 3/7] reddit.js: don't try to wrap to the previous page when on the first one

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
---
 modules/page-modes/reddit.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index 54c0aa2..ae473c9 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -345,8 +345,9 @@ function reddit_prev_link (I) {
                 if (xpr && (prevpage = xpr.iterateNext())) {
                     dom_remove_class(current, "last-clicked");
                     browser_object_follow(I.buffer, FOLLOW_DEFAULT, prevpage);
-                    return;
                 }
+
+                return;
             }
         }
     }
-- 
2.1.0

[PATCH 2/7] reddit.js: update XPath expression that finds prev and next buttons

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
Changed in:
https://github.com/reddit/reddit/commit/3341b2049e3cdab39c0254d3a1743c13cfcebfc2
---
 modules/page-modes/reddit.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index c9bb8b6..54c0aa2 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -112,7 +112,7 @@ function reddit_next_link (I) {
                 next = first;
             if (reddit_end_behavior == 'page') {
                 let (xpr = doc.evaluate(
-                    '//p[@class="nextprev"]/a[contains(text(),"next")]', 
doc, null,
+                    
'//span[@class="nextprev"]/a[contains(text(),"next")]', doc, null,
                     Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null))
                 {
                     var nextpage;
@@ -338,7 +338,7 @@ function reddit_prev_link (I) {
             }
         } else if (reddit_end_behavior == 'page') {
             let (xpr = doc.evaluate(
-                '//p[@class="nextprev"]/a[contains(text(),"prev")]', doc, null,
+                '//span[@class="nextprev"]/a[contains(text(),"prev")]', 
doc, null,
                 Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null))
             {
                 var prevpage;
-- 
2.1.0

[PATCH 4/7] reddit.js: adjust to new way reddit handles collapsed comments

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
---
 modules/page-modes/reddit.js | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index ae473c9..a3f9e61 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -184,9 +184,7 @@ function get_entries_without_collapsed_comments (entries) {
             }
         }
         // Collapsed comment
-        if (i != 0 &&
-            entries[i].getElementsByTagName("div")[1].style.display == "none")
-        {
+        if (i != 0 && entries[i].parentNode.className.match(/\bcollapsed\b/)) {
             collapsed_parent = entries[i].parentNode;
         }
         entries_without_collapsed.push(entries[i]);
-- 
2.1.0

[PATCH 5/7] reddit.js: handle 'continue this thread' links correctly

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
Also clean up the way 'load more comments' links are found.
---
 modules/page-modes/reddit.js | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index a3f9e61..bf65a12 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -173,10 +173,13 @@ function get_entries_without_collapsed_comments (entries) {
     var collapsed_parent = null;
     for (var i = 0, elen = entries.length; i < elen; i++) {
         if (collapsed_parent) {
-            // Discard the 'load more comments' buttons
-            var current_classname = 
entries[i].getElementsByTagName("span")[0].className;
+            // Discard the 'load more comments' links
+            var load_more_comments = entries[i].querySelector(".morecomments");
+            // Discard the 'continue this thread' links
+            var continue_this_thread = entries[i].querySelector(".deepthread");
+
             if (!comment_is_child(collapsed_parent, entries[i].parentNode) &&
-                current_classname != "morecomments")
+                !load_more_comments && !continue_this_thread)
             {
                 collapsed_parent = null;
             } else { // Skip collapsed comments
-- 
2.1.0

[PATCH 7/7] reddit.js: restrict stylesheet on domain instead of url-prefix

From:
Joren Van Onder
Date:
2014-10-17 @ 15:14
This is cleaner because Reddit has a lot of subdomains including
subdomains for a bunch of different languages (eg. en., fr., de., ...).
---
 modules/page-modes/reddit.js | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/modules/page-modes/reddit.js b/modules/page-modes/reddit.js
index cad296e..17ab375 100644
--- a/modules/page-modes/reddit.js
+++ b/modules/page-modes/reddit.js
@@ -21,9 +21,7 @@ define_variable("reddit_end_behavior", "stop",
 register_user_stylesheet(
     "data:text/css," +
         escape (
-            "@-moz-document url-prefix(http://www.reddit.com/)," +
-                "url-prefix(https://pay.reddit.com)," +
-                "url-prefix(https://www.reddit.com) {" +
+            "@-moz-document domain(reddit.com) {" +
                 "body>.content .last-clicked {" +
                 " background-color: #bfb !important;" +
                 " border: 0px !important;"+
-- 
2.1.0