NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Small kbin.social improvements // @namespace https://kbin.social/ // @version 0.1 // @description Collapsible comment threads. Highlighting OP's username in the comments. // @author H2SO4 // @match https://kbin.social/* // @license MIT // @grant none // ==/UserScript== /* Highlight OP's name and add [OP] to clearly indicate which comments are by the OP */ function changeOPusername(user) { user.innerText = user.innerText+" [OP]"; user.style.color="blue"; } (function() { 'use strict'; let authorlink = document.querySelector("article.entry aside.meta a.user-inline"); if(!authorlink) return; let author = authorlink.innerText let authorcomments = document.querySelectorAll("div#comments section.comments blockquote.author header a.user-inline"); let comments = [...authorcomments]; comments.map( user => changeOPusername(user) ); })(); /* Collapsible comment threads */ function toggleElementVisibility(element) { element.style.display == "none" ? element.style.display = "block" : element.style.display = "none"; } function handleCollapserClick(e, comment) { if(comment.classList.contains("collapsed")) { e.target.innerText = "[-]"; comment.classList.remove("collapsed"); } else { e.target.innerText = "[+]"; comment.classList.add("collapsed"); } let level = comment.getAttribute("class").match(/\d/)[0]; var subcomment = comment.nextElementSibling; while(subcomment && !subcomment.classList.contains("comment-level--"+level)) { subcomment.style.display == "none" ? subcomment.style.display = "grid" : subcomment.style.display = "none"; subcomment = subcomment.nextElementSibling; } toggleElementVisibility(comment.getElementsByClassName("content")[0]); toggleElementVisibility(comment.getElementsByTagName("aside")[0]); toggleElementVisibility(comment.getElementsByTagName("footer")[0]); return false; } (function() { 'use strict'; document.querySelectorAll("div#comments section.comments blockquote.comment").forEach(function(comment){ let header = comment.getElementsByTagName("header")[0]; let collapser = document.createElement("a"); collapser.classList.add("collapser"); collapser.innerText = "[-]"; collapser.href = "#"; collapser.onclick = (e) => handleCollapserClick(e, comment); header.append(collapser); }); })();