Guest User

Re-order SotT comments

a guest
Mar 3rd, 2022
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Re-order SoTT Comments
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        *://*.sott.net/article/*
  8. // @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABOUExURQAqgExpcQAqgAAqgAAqgAAqgAAqgAAqgAAqgAAqgAAqgAAnfgU1hvj49YugwiJMk8vT4YGXve3u8ERnoubp7U1upmyHtKa1z56vyzddnIDdR+YAAAAKdFJOU/0AmG0CPirx3a00twh2AAAACXBIWXMAAC4iAAAuIgGq4t2SAAAAjElEQVQY02VPRxKEMAwTLCU4cTrt/x9d28xwQReXkSUZw7zSi3UeMI3aeYHWccLipIZWSgvSuAU/yBwrc42ykXET/l57jD0nudogF77wSdSSijiIhz8434FMdYVapMw9X8YAzD9dubNpABbLU7gzH15PnDEa0cnFq+hmGmpbd7P9BPtE/zz3vI8H8v4f3EcKw0zZ0KIAAABXelRYdFJhdyBwcm9maWxlIHR5cGUgaXB0YwAAeJzj8gwIcVYoKMpPy8xJ5VIAAyMLLmMLEyMTS5MUAxMgRIA0w2QDI7NUIMvY1MjEzMQcxAfLgEigSi4A6hcRdPJCNZUAAAAASUVORK5CYII=
  9. // @grant        GM_registerMenuCommand
  10.  
  11.  
  12. // ==/UserScript==
  13.  
  14. GM_registerMenuCommand("Re-order comments (new to old)", do_something);
  15. console.log("is this thing on?");
  16. let docFragment = document.createDocumentFragment();
  17.  
  18. function do_something(){
  19.     let comments_section = document.getElementsByClassName("comment");
  20.     let tdivs = [].slice.call(comments_section);
  21.     tdivs.sort(sort_divs).forEach(display_current_attribute);
  22.     document.getElementById("article_comments").appendChild(docFragment);
  23. }
  24. function sort_divs(a,b){
  25.     const dval1 = new Date(a.getElementsByClassName('comment-timestamp')[0].getAttribute('title'));
  26.     const dval2 = new Date(b.getElementsByClassName('comment-timestamp')[0].getAttribute('title'));
  27.     if(dval1 > dval2){
  28.         return -1;
  29.     }
  30.     else{
  31.          return 1;
  32.     }
  33. }
  34. function display_current_attribute(tdiv_obj){
  35.     const tdiv_header = tdiv_obj.getElementsByClassName('comment-timestamp');
  36.     const td_style = tdiv_obj.getAttribute('class');
  37.     const new_td_style = td_style.replace(/reply/, "");
  38.     tdiv_obj.setAttribute('class', new_td_style);
  39.     docFragment.appendChild(tdiv_obj);
  40. }
Add Comment
Please, Sign In to add comment