Guest User

Disqus Sorted Comments.

a guest
May 15th, 2018
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function want(selector) {
  2.         return document.documentElement.querySelectorAll(selector);
  3. }
  4.  
  5. function loadAll(thendo, timeout) {
  6.         var loader = want('[data-action="more-posts"]');
  7.         if(loader[0].parentElement.style.display!="none"){
  8.                 loader[0].click();
  9.                 setTimeout(function(){loadAll(thendo,timeout);},timeout||1000);
  10.         } else {
  11.                 if(thendo){thendo();};
  12.         }
  13. }
  14.  
  15. function posts() {
  16.         return want('div.post-body');
  17. }
  18.  
  19. function postID(post) {
  20.         return Number(post.querySelector('a.time-ago').href.replace(/.*\/#comment-/,""));
  21. }
  22.  
  23. function sortedPosts () {
  24.         var postlist = [];
  25.         posts().forEach(function(x){postlist.push([postID(x),x]);});
  26.         return postlist.sort().map(function(x) {return x[1];});
  27. }
  28.  
  29. function appendSortedPosts() {
  30.         var holder = document.createElement("div");
  31.         holder.style.margin = "2em";
  32.         sortedPosts().forEach(function(x){
  33.                 holder.appendChild(document.createElement("div")).
  34.                         innerHTML = x.innerHTML;
  35.         });
  36.         document.body.appendChild(holder);
  37. }
  38.  
  39. function loadAndAppendSorted() {
  40.         loadAll(appendSortedPosts);
  41. }
  42.  
  43. loadAndAppendSorted();
RAW Paste Data