TLDR: the script sorts comments under the article in the order of addition, without taking into account the level of nesting and discussions. You can view it every few days until the feeling of deja vu.
I caught myself thinking that it was inconvenient to follow long discussions on the habr, especially if they stretch for several days. Especially if there is some kind of lively flower there, where the participants water on each other with the truth for several days. Especially if in this stream of truth you just need to extract opinions and facts without plunging into the discussion itself. Maybe someone else will be useful.
A quick option to run in the developer console:
(function() { function sortComments() { let comments = Array.from( document.querySelectorAll(".comment") ); comments.sort(function (a,b) { let times = [ a.querySelector("time"), b.querySelector("time") ]; for (let i in times) { times[i] = (( times[i] !== null ) ? times[i].innerText : "").replace(/([0-9]{2})\.([0-9]{2})\.([0-9]{2}).+?([0-9]{2}):([0-9]{2})/, "$3.$2.$1 $4:$5"); } return times[1].localeCompare(times[0]); }); let rendered = ""; for (let i = 0; i < comments.length; i++) { rendered += comments[i].innerHTML + "<br/><br/>"; } document.querySelector("#comments").innerHTML = rendered; document.querySelector("#comments").scrollIntoView(); } sortComments(); })();
Option for GreaseMonkey (a button appears in the upper right corner):
// ==UserScript== // @name // @version 1 // @grant none // @include https://habr.com/*/post/* // @include https://habr.com/*/blog/* // @include https://habr.com/*/article/*/ // ==/UserScript== (function() { function sortComments() { let comments = Array.from( document.querySelectorAll(".comment") ); comments.sort(function (a,b) { let times = [ a.querySelector("time"), b.querySelector("time") ]; for (let i in times) { times[i] = (( times[i] !== null ) ? times[i].innerText : "").replace(/([0-9]{2})\.([0-9]{2})\.([0-9]{2}).+?([0-9]{2}):([0-9]{2})/, "$3.$2.$1 $4:$5"); } return times[1].localeCompare(times[0]); }); let rendered = ""; for (let i = 0; i < comments.length; i++) { rendered += comments[i].innerHTML + "<br/><br/>"; } document.querySelector("#comments").innerHTML = rendered; document.querySelector("#comments").scrollIntoView(); } let sortButton = document.createElement("div"); sortButton.style["position"] = "fixed"; sortButton.style["top"] = 0; sortButton.style["right"] = 0; sortButton.style["height"] = "1.3em"; sortButton.style["width"] = "11em"; sortButton.style["border"] = "1px solid grey"; sortButton.style["text-align"] = "center"; sortButton.style["cursor"] = "pointer"; sortButton.style["z-index"] = 999; sortButton.innerText = " "; sortButton.addEventListener("click", function (event) { event.preventDefault(); sortComments(); event.target.remove(); }); document.body.appendChild(sortButton); })();
I would like to see such functionality as part of the site, because “comments are more useful than articles” is a classic. And something interesting can be caught a week after publication.
Source: https://habr.com/ru/post/419297/
All Articles