Last active
November 22, 2023 02:13
-
-
Save Sciman101/782795e14217e7aac2452b38dfdeb4b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name cohost De-Numberifier | |
// @description Removes comment numbers | |
// @version 0.2 | |
// @author @sciman101 | |
// @match *://cohost.org/* | |
// @grant none | |
// ==/UserScript== | |
// A lot of this code was stolen from gyoza's fantastic audio enhancements userscript | |
const yesCommentsString = 'yes comments'; | |
const noCommentsString = 'no comments'; | |
const observer = new MutationObserver(mutations => { | |
mutations | |
.flatMap(mutation => Array.from(mutation.addedNodes)) | |
.flatMap(addedNode => Array.from(addedNode.querySelectorAll('footer'))) | |
.forEach(processFooter); | |
}); | |
function startObserving() { | |
let mainContent = document.querySelector('main'); | |
if (!mainContent) { | |
mainContent = document.querySelector('[data-view="post-preview"]')?.parentElement?.parentElement | |
if (!mainContent) return; | |
} | |
observer.disconnect(); | |
observer.observe(mainContent, {subtree: true, childList: true}); | |
} | |
function processFooter(footer) { | |
const commentLabel = footer.querySelector('.text-sm'); | |
if (/(\d+) comments?/.test(commentLabel.innerText)) { | |
if (commentLabel.innerText === '0 comments') { | |
commentLabel.innerText = noCommentsString; | |
}else{ | |
commentLabel.innerText = yesCommentsString; | |
} | |
} | |
} | |
function main() { | |
const initialPosts = Array.from(document.querySelectorAll('footer.bg-notWhite')) | |
initialPosts.forEach(processFooter) | |
startObserving() | |
} | |
if (document.readyState === 'complete') { | |
setTimeout(main, 500) | |
} else { | |
document.addEventListener('readystatechange', e => { | |
if (document.readyState === 'complete') setTimeout(main, 500) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment