2024-07-10 15:41:21 -04:00
|
|
|
// ==UserScript==
|
2024-07-10 17:15:21 -04:00
|
|
|
// @name name-color: cohost edition!
|
2024-07-10 15:41:21 -04:00
|
|
|
// @namespace https://terezi.pyrope.net
|
|
|
|
// @version 2024-07-10
|
2024-07-10 17:15:21 -04:00
|
|
|
// @description colors names based on `name-color:` statements in profiles. there are no other editions
|
2024-07-10 15:41:21 -04:00
|
|
|
// @author mehbark
|
|
|
|
// @match https://*.cohost.org/*
|
|
|
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=cohost.org
|
|
|
|
// @grant none
|
|
|
|
// ==/UserScript==
|
|
|
|
|
2024-07-10 17:15:21 -04:00
|
|
|
const mentionee = elem => elem.href.split("/").at(-1);
|
2024-07-10 15:41:21 -04:00
|
|
|
|
2024-07-10 17:15:21 -04:00
|
|
|
function doit() {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// not just literal mentions btw
|
|
|
|
const mentions = [
|
|
|
|
...document.querySelectorAll("a[href^='https://cohost.org/']"),
|
|
|
|
].filter(
|
|
|
|
a =>
|
|
|
|
!(
|
|
|
|
a.href.includes("/rc/") ||
|
|
|
|
// sorry, @post
|
|
|
|
a.href.includes("/post/") ||
|
|
|
|
// sorry, @tagged
|
|
|
|
a.href.includes("/tagged/") ||
|
|
|
|
// sorry, @ask
|
|
|
|
a.href.endsWith("/ask") ||
|
|
|
|
a.href.endsWith("/")
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
const names = [...new Set(mentions.map(mentionee))];
|
|
|
|
|
|
|
|
const requester = document
|
|
|
|
.querySelector("header")
|
|
|
|
.querySelector("span")
|
|
|
|
.innerText.slice(1);
|
|
|
|
|
|
|
|
const url = new URL("https://pyrope.net/name-color/style.css");
|
|
|
|
|
|
|
|
url.searchParams.append("requester", requester);
|
|
|
|
for (const name of names) {
|
|
|
|
url.searchParams.append("name", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
let style = document.head.querySelector("#name-color-stylesheet");
|
|
|
|
if (!style) {
|
|
|
|
style = document.createElement("link");
|
|
|
|
style.id = "name-color-stylesheet";
|
|
|
|
style.rel = "stylesheet";
|
|
|
|
document.head.appendChild(style);
|
|
|
|
}
|
|
|
|
style.href = url.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
new MutationObserver(doit).observe(document, {
|
|
|
|
subtree: true,
|
|
|
|
childList: true,
|
|
|
|
});
|