Advertisement
Guest User

Disqus comment userscript

a guest
May 16th, 2018
125
0
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 collapser(node) {
  30.         var res = document.createElement("div");
  31.         res.appendChild(document.createTextNode("↸"));
  32.         res.onclick = function(){
  33.                 if (node.style.display == "none"){
  34.                         node.style.display = "block";
  35.                 }else{
  36.                         node.style.display = "none";
  37.                 }
  38.         };
  39.         res.style.fontSizeAdjust = 2;
  40.         res.style.margin = "2em";
  41.         res.style.backgroundColor = "#EFEFFF";
  42.         return res;
  43. }
  44.  
  45. function appendSortedPosts() {
  46.         var holder = document.createElement("div");
  47.         holder.style.margin = "2em";
  48.         sortedPosts().forEach(function(x){
  49.                 var y = holder.appendChild(document.createElement("div"));
  50.                 y.innerHTML = x.innerHTML;
  51.                 y.onclick = function() {
  52.                         console.log(postID(x));
  53.                         document.documentElement.                      
  54.                                       querySelectorAll('div.post-body').    
  55.                         forEach(function(n){                                
  56.                                 if(postID(n)>postID(x)){                
  57.                                         n.style.backgroundColor = '#EEFFF7';
  58.                                 }else{                                      
  59.                                         n.style.backgroundColor = '#FFFFFF';
  60.                                 }                                            
  61.                         });
  62.                 };
  63.         });
  64.         document.body.appendChild(collapser(holder));
  65.         document.body.appendChild(holder);
  66.         document.body.appendChild(collapser(holder)).scrollIntoView();
  67. }
  68.  
  69. function loadAndAppendSorted() {
  70.         loadAll(appendSortedPosts);
  71. }
  72.  
  73. loadAndAppendSorted();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement