Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Toggle Hashtag Visibility and Enhance Links Userscript
- // @namespace http://example.com
- // @include https://mastodon.online/*
- // @include https://mastodon.social/*
- // @version 2
- // @grant none
- // ==/UserScript==
- // Options
- const linkColor = '#00A0E9'; // Link color
- const makeLinksBold = true; // Bold links
- let hideHashtags = true; // Hide hashtags by default
- // Store original text content
- const originalText = new WeakMap();
- // Function to toggle hashtag visibility
- function toggleHashtagsVisibility() {
- const links = document.querySelectorAll('a.mention.hashtag'); // Target hashtag links
- links.forEach(link => {
- if (!originalText.has(link)) {
- originalText.set(link, link.textContent); // Cache original text
- }
- const original = originalText.get(link);
- link.textContent = hideHashtags
- ? original.replace(/#/g, '') // Remove hashtags
- : original; // Restore hashtags
- });
- }
- // Function to style links
- function enhanceLinks() {
- const links = document.querySelectorAll('a');
- links.forEach(link => {
- link.style.color = linkColor; // Apply link color
- link.style.fontWeight = makeLinksBold ? 'bold' : 'normal'; // Apply font weight
- });
- }
- // Debounced function to handle DOM changes
- let debounceTimeout;
- function handleDOMChanges() {
- clearTimeout(debounceTimeout);
- debounceTimeout = setTimeout(() => {
- toggleHashtagsVisibility();
- enhanceLinks();
- }, 100); // Debounce updates to reduce strain
- }
- // Observe DOM changes
- function observeDOMChanges() {
- const observer = new MutationObserver(handleDOMChanges);
- observer.observe(document.body, {
- childList: true,
- subtree: true,
- });
- }
- // Toggle hashtags on F2 key
- document.addEventListener('keydown', event => {
- if (event.key === 'F2') {
- hideHashtags = !hideHashtags;
- toggleHashtagsVisibility();
- }
- });
- // Initial calls
- toggleHashtagsVisibility();
- enhanceLinks();
- observeDOMChanges();
Advertisement
Comments
-
- To customize your Mastodon experience by hiding or displaying hashtags and enhancing link appearances, follow these steps to install and configure the userscript:
- Step 1: Install a Userscript Manager
- A userscript manager is required to run custom scripts in your browser. Popular options include:
- Tampermonkey: Compatible with Chrome, Firefox, Edge, Safari, and more.
- Installation link: https://www.tampermonkey.net/
- Greasemonkey: Primarily for Firefox users.
- Installation link: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
- Choose the one that aligns with your browser and install it.
- Step 2: Add the Userscript
- Access the Userscript Manager:
- Click on the Tampermonkey or Greasemonkey icon in your browser's toolbar.
- Create a New Script:
- Select the option to create or add a new script.
- Retrieve the Script Code:
- Navigate to the Pastebin link provided above.
- Copy the entire script code from the Pastebin page.
- Paste the Script:
- In the userscript editor, paste the copied script code.
- Step 3: Configure the Script
- The script offers customization options:
- Link Color:
- Find the line const linkColor = '#00A0E9';
- Replace '#00A0E9' with your preferred color code (e.g., '#FF5733' for a reddish hue).
- Bold Links:
- Locate const makeLinksBold = true;
- Set it to true to make links bold or false to keep them normal.
- Hide Hashtags:
- Identify const hideHashtags = true;
- Set it to true to hide hashtags or false to display them.
- Note: If you're using a Mastodon instance other than mastodon.online or mastodon.social, add your instance's URL to the @include section of the script to ensure it functions correctly.
- Step 4: Save and Activate the Script
- Save the Script:
- Click the save button in the userscript editor to store your changes.
- Enable the Script:
- Ensure the script is active. You might need to refresh your Mastodon page for the changes to take effect.
- By following these steps, you can tailor your Mastodon interface to better suit your preferences.
Add Comment
Please, Sign In to add comment