Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Re-order SoTT Comments
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match *://*.sott.net/article/*
- // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABOUExURQAqgExpcQAqgAAqgAAqgAAqgAAqgAAqgAAqgAAqgAAqgAAnfgU1hvj49YugwiJMk8vT4YGXve3u8ERnoubp7U1upmyHtKa1z56vyzddnIDdR+YAAAAKdFJOU/0AmG0CPirx3a00twh2AAAACXBIWXMAAC4iAAAuIgGq4t2SAAAAjElEQVQY02VPRxKEMAwTLCU4cTrt/x9d28xwQReXkSUZw7zSi3UeMI3aeYHWccLipIZWSgvSuAU/yBwrc42ykXET/l57jD0nudogF77wSdSSijiIhz8434FMdYVapMw9X8YAzD9dubNpABbLU7gzH15PnDEa0cnFq+hmGmpbd7P9BPtE/zz3vI8H8v4f3EcKw0zZ0KIAAABXelRYdFJhdyBwcm9maWxlIHR5cGUgaXB0YwAAeJzj8gwIcVYoKMpPy8xJ5VIAAyMLLmMLEyMTS5MUAxMgRIA0w2QDI7NUIMvY1MjEzMQcxAfLgEigSi4A6hcRdPJCNZUAAAAASUVORK5CYII=
- // @grant GM_registerMenuCommand
- // ==/UserScript==
- GM_registerMenuCommand("Re-order comments (new to old)", do_something);
- console.log("is this thing on?");
- let docFragment = document.createDocumentFragment();
- function do_something(){
- let comments_section = document.getElementsByClassName("comment");
- let tdivs = [].slice.call(comments_section);
- tdivs.sort(sort_divs).forEach(display_current_attribute);
- document.getElementById("article_comments").appendChild(docFragment);
- }
- function sort_divs(a,b){
- const dval1 = new Date(a.getElementsByClassName('comment-timestamp')[0].getAttribute('title'));
- const dval2 = new Date(b.getElementsByClassName('comment-timestamp')[0].getAttribute('title'));
- if(dval1 > dval2){
- return -1;
- }
- else{
- return 1;
- }
- }
- function display_current_attribute(tdiv_obj){
- const tdiv_header = tdiv_obj.getElementsByClassName('comment-timestamp');
- const td_style = tdiv_obj.getAttribute('class');
- const new_td_style = td_style.replace(/reply/, "");
- tdiv_obj.setAttribute('class', new_td_style);
- docFragment.appendChild(tdiv_obj);
- }
Add Comment
Please, Sign In to add comment