Skip to content

Instantly share code, notes, and snippets.

@mattmess1221
Last active November 10, 2023 18:26
Show Gist options
  • Save mattmess1221/5d8f15405ccb850fed1efe9ad4237151 to your computer and use it in GitHub Desktop.
Save mattmess1221/5d8f15405ccb850fed1efe9ad4237151 to your computer and use it in GitHub Desktop.
User script for lemmy tweaks. Install with violentmonkey or similar browser extension
// ==UserScript==
// @name lemmy style tweaks
// @namespace -
// @match *://*/*
// @grant none
// @version 1.0.1
// @author killjoy1221
// @description Various stylistic tweaks for Lemmy
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2
// ==/UserScript==
(() => {
function isLemmy() {
return document.querySelector("meta[name='Description']")?.content === "Lemmy";
}
if (isLemmy()) {
const styles = `
/* Sticky navbar */
#app > div:not(:is(div~*)) {
position: sticky;
top: 0;
z-index: 999;
background-color: var(--bs-body-bg);
}
`
const styleSheet = document.createElement("style")
styleSheet.innerText = styles
document.head.appendChild(styleSheet)
VM.observe(document.body, () => {
// open external links in a new tab
for (const node of document.querySelectorAll('a:is([href^="https://"], [href^="http://"], [rel*="noopener"]):not([target="_blank"])')) {
node.target = "_blank";
}
// expand text posts by clicking the main icon
for (const node of document.querySelectorAll('.post-listings a.text-body[title="Comments"]:not([data-expandable])')) {
node.setAttribute("data-expandable", "true")
node.addEventListener("click", (e) => {
e.preventDefault();
e.target.closest(".row").querySelector(".post-title>button")?.click();
})
}
// live comment preview
for (const node of document.querySelectorAll(".markdown-textarea textarea.d-none")) {
node.classList.remove("d-none");
}
for (const node of document.querySelectorAll(".markdown-textarea button")) {
if (node.innerText === "Preview") {
node.removeAttribute("disabled")
node.click();
node.remove();
}
}
})
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment