Pinterest - Replace Page Title with Username

Replace the page title with the user profile name on Pinterest

目前為 2025-03-16 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Pinterest - Replace Page Title with Username
// @namespace    
// @version      1.8
// @description  Replace the page title with the user profile name on Pinterest
// @author       wolffgang
// @match        *://*.pinterest.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function removeEmojis(text) {
        return text.replace(/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2B50}\u{2B55}\u{231A}-\u{231B}\u{2328}\u{23CF}\u{23E9}-\u{23EF}\u{23F0}\u{23F1}-\u{23F2}\u{23F3}\u{23F8}-\u{23FA}\u{24C2}\u{25AA}-\u{25AB}\u{25B6}\u{25C0}\u{25FB}-\u{25FE}\u{2600}-\u{26FF}\u{2705}\u{2728}\u{274C}\u{274E}\u{2753}-\u{2755}\u{2757}\u{2795}-\u{2797}\u{27A1}\u{27B0}\u{27BF}\u{2934}-\u{2935}\u{2B05}-\u{2B07}\u{2B1B}-\u{2B1C}\u{2B50}\u{2B55}\u{3030}\u{303D}\u{3297}\u{3299}\u{1F004}\u{1F0CF}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F1E6}-\u{1F1FF}\u{1F201}-\u{1F251}\u{1F4E6}\u{1F4F7}\u{1F916}\u{1F917}\u{1F9D0}-\u{1F9FF}\u{1FA60}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{1FC00}-\u{1FFFD}\u{3040}\u{309F}\u{30A0}-\u{30FF}\u{FF00}-\u{FFEF}\u{1F004}\u{1F0CF}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F1E6}-\u{1F1FF}\u{1F201}-\u{1F251}\u{1F4E6}\u{1F4F7}\u{1F916}\u{1F917}\u{1F9D0}-\u{1F9FF}\u{1FA60}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{1FC00}-\u{1FFFD}]/gu, '');
    }

    function replaceTitle() {
        let usernameElement = null;
        let profileNameElement = null;
        let username = null;

        // Check if it's a pin page
        if (window.location.href.match(/pin\/\d+/)) {
            profileNameElement = document.querySelector('div[data-test-id="creator-profile-name"] div.X8m.zDA.IZT.tBJ.dyH.iFc.j1A.swG');
            usernameElement = document.querySelector('a[data-test-id="creator-profile-link"]');
        }
        // Check if it's a profile page
        else if (window.location.href.match(/\/[a-zA-Z0-9]+\/$/)) {
            profileNameElement = document.querySelector('div[data-test-id="profile-name"] div.zI7.iyn.Hsu[style*="display: inline"]');
            const urlParts = window.location.pathname.split('/');
            username = urlParts[1];
        }

        if (profileNameElement && usernameElement) {
            const displayedUsername = profileNameElement.innerText;
            const linkUsername = usernameElement.getAttribute('href').replace(/\//g, '');
            document.title = removeEmojis(`${displayedUsername} (${linkUsername})`);
        } else if (profileNameElement && username) {
            const displayedUsername = profileNameElement.innerText;
            document.title = removeEmojis(`${displayedUsername} (${username})`);
        }
    }

    // Observe changes in the DOM to handle dynamic content loading
    const observer = new MutationObserver(replaceTitle);
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial call to handle cases where the elements are already loaded
    replaceTitle();

    // Aggressively retry setting the title to ensure it sticks
    const interval = setInterval(() => {
        replaceTitle();
    }, 1000);

    // Stop the interval after a certain amount of time
    setTimeout(() => {
        clearInterval(interval);
    }, 10000); // Retry for 10 seconds
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址