BLUESKY PLUS

Little tweaks

// ==UserScript==
// @name        BLUESKY PLUS
// @namespace   Violentmonkey Scripts
// @match       *://bsky.app/*
// @version     1.5
// @author      Chaewon
// @grant       GM_addStyle
// @description Little tweaks
// @license     Unlicense
// @icon        https://bsky.app/static/apple-touch-icon.png
// ==/UserScript==

const css = String.raw;
const scriptConfig = {
	centerTab: true,
	removeBsky: true,
};

const style = css`
	.css-175oi2r[data-testid^="homeScreenFeedTabs-selector-"],
	.css-175oi2r[data-testid^="profilePager-selector-"] {
		flex: 1 1 0px;
	}

	.css-175oi2r[data-testid="homeScreenFeedTabs-selector"] > .css-175oi2r,
	.css-175oi2r[data-testid="profilePager-selector"] > .css-175oi2r {
		width: 100%;
	}

	.css-175oi2r[data-testid^="profilePager-selector"] {
		flex-basis: auto;
	}

	.css-146c3p1[data-testid^="homeScreenFeedTabs"],
	.css-146c3p1[data-testid^="profilePager-"] {
		text-align: center;
	}

	@media only screen and (max-width: 600px) {
		.css-175oi2r[data-testid^="profilePager-selector-"] {
			flex: inherit;
		}
	}
`;

scriptConfig.centerTab && GM_addStyle(style);

const targetNode = document.body;

function removeBsky() {
	const pattern = /[@]?[\w-]{3,18}.bsky.social/gi;
	const elements = document.querySelectorAll(
		"span.css-1jxf684:not([data-processed]),a div div.css-146c3p1:not([data-processed]), a.css-1jxf684[href^='/profile/'] span.css-1jxf684:not([data-processed]),a.css-1jxf684.r-1loqt21:not([data-processed]), div.css-146c3p1.r-dnmrzs.r-1udh08x.r-1udbk01.r-3s2u2q.r-1iln25a:not([data-processed]) , div[data-testid='profileHeaderDisplayName']:not([data-processed])"
	);

	const allElements = Array.from(elements).filter(
		(element) => element.children.length === 0
	);
	console.log(elements.length, allElements.length)

	allElements.forEach((element) => {
		element.setAttribute("data-processed", "true");

		if (element.innerText.match(pattern)) {
			//console.log("Matches found:", element.innerText.match(pattern));
			element.innerText = element.innerText.replace(".bsky.social", "");
		}
	});

	const element2 = document.querySelector(
		".css-146c3p1[data-testid='homeScreenFeedTabs-Popular With Friends']:not([data-processed]"
	);
	if (element2) {
		element2.setAttribute("data-processed", "true");
		element2.setAttribute("title", "Popular With Friends");
		element2.innerText = "Popular";
		element2.parentElement?.parentElement?.setAttribute(
			"title",
			"Popular With Friends"
		);
	}
}

const observer = new MutationObserver((mutationsList) => {
	for (const mutation of mutationsList) {
		if (mutation.type === "childList") {
			removeBsky();
		}
	}
});

const config = { childList: true, subtree: true };
scriptConfig.removeBsky && removeBsky();
scriptConfig.removeBsky && observer.observe(targetNode, config);