Fetlife notifications

Fetlife notifications are annoying, this tries to hide it

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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
            }
        }

    }

})();