Fetlife notifications

Fetlife notifications are annoying, this tries to hide it

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Fetlife notifications
// @namespace    B1773rm4n
// @version      2025-12-24
// @description  Fetlife notifications are annoying, this tries to hide it
// @copyright    WTFPL
// @license      WTFPL
// @source       https://github.com/B1773rm4n/Tampermonkey_Userscripts/blob/main/fetlife_Notifications.js
// @author       B1773rm4n
// @match        https://fetlife.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fetlife.com
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Select the target node
    var target = document.querySelector('title');
    var programmaticChange = false; // Flag to track programmatic changes

    // Create an observer instance
    var observer = new MutationObserver(titleIsChangedEvent);

    // Configuration of the observer
    var config = { subtree: true, characterData: true, childList: true };

    // Pass in the target node, as well as the observer options
    observer.observe(target, config);

    // Function to handle title changes
    function titleIsChangedEvent(mutations) {
        mutations.forEach(mutation => {
            if (mutation.type === 'childList' || mutation.type === 'characterData') {
                doChangetitle()
            }
        });
    }

    setInterval(function () {
        doChangetitle()
    }, 10 * 60 * 1000);

    function doChangetitle() {

        const newMessages = document.querySelector('.flex-none.translate-x-2.rounded.bg-red-700.px-1.text-xxs.font-bold.leading-normal.light\\:text-black[aria-hidden="true"]').innerHTML
        // Get the text content
        const value = newMessages.trim();

        // Check if it's a number
        const isNumber = !isNaN(value) && value !== '';

        if (target.textContent !== "FetLife") {
            if (!programmaticChange) {
                console.log(Date()); // Log the current date and time
                // Update the title
                programmaticChange = true; // Set the flag

                if (isNumber && newMessages != 0) {
                    target.textContent = "(" + newMessages + ")" + " Fetlife"; // Change the title text
                } else {
                    target.textContent = "FetLife"; // Change the title text
                }

            } else {
                console.log("Change was made programmatically.");
                programmaticChange = false; // Reset the flag
            }
        }

    }

})();