// ==UserScript==
// @name kbin enhancement script
// @description Few small changes to the kbin UI while they still develop some features
// @namespace com.sirpsychomantis
// @license MIT
// @version 1.4
// @grant none
// @run-at document-end
// @match https://fedia.io/*
// @match https://kbin.social/*
// @downloadURL none
// ==/UserScript==
(function(){
const version = "1.4";
const allSettings = [
{name: "Show domains", value:"show-domains"},
{name: "Show collapse comment", value:"show-collapse"},
{name: "Move comment box to top", value:"comment-box-top"}
];
function getSetting(setting) {
let value = localStorage.getItem("setting-" + setting);
if (value === null)
value = "true";
return value === "true";
}
function setSetting(setting, value) {
localStorage.setItem("setting-" + setting, value);
location.reload();
}
function addDomain(link) {
const parts = link.title.split("@");
if (parts[2] !== location.hostname && !link.innerText.includes("@" + parts[2])) {
const linkText = link.childNodes[link.childNodes.length-1];
linkText.nodeValue += "@" + parts[2];
}
}
function addDomains() {
document.querySelectorAll(".magazine-inline, .user-inline").forEach(link => {
addDomain(link);
});
}
function getComments(comment, allComments) {
const id = comment.id.split('-')[2];
allComments.push(comment);
const subComments = comment.parentElement.querySelectorAll('blockquote[data-subject-parent-value="'+id+'"]');
subComments.forEach(blockquote => { getComments(blockquote, allComments); });
}
function getCollapsos(comment, allCollapsos) {
const id = comment.id.split('-')[2];
if (comment.classList.contains('kes-expand'))
allCollapsos.push(comment);
const subComments = comment.parentElement.querySelectorAll('blockquote[data-subject-parent-value="'+id+'"]');
subComments.forEach(blockquote => { getCollapsos(blockquote, allCollapsos); });
}
function expandComment(blockquote) {
const allComments = [];
getComments(blockquote, allComments);
allComments.forEach(comment => { comment.style.display="" });
// Just remove all these for now, don't want to figure out how to do this cleanly right now.
const allCollapsos = [];
getCollapsos(blockquote, allCollapsos);
allCollapsos.forEach(comment => { comment.remove() });
}
function collapseComment(blockquote) {
const id = blockquote.id.split('-')[2];
let commentLevel = "1";
blockquote.classList.forEach(classItem => {
if (classItem.includes("comment-level"))
commentLevel = classItem.split("--")[1];
});
const allComments = [];
getComments(blockquote, allComments);
allComments.forEach(comment => { comment.style.display="none" });
const username = blockquote.querySelector("header a").innerText;
const newBlockquote = document.createElement('blockquote');
newBlockquote.className = 'kes-expand section comment entry-comment comment-level--' + commentLevel;
newBlockquote.dataset.subjectParentValue = id;
newBlockquote.innerHTML = '