// ==UserScript== // @name Enhanced Pinterest Page Title with Username and Alt Text // @version 3.0 // @description Replace the page title with the user profile name, username, post title and auto alt text on Pinterest // @author wolffgang // @match *://*.pinterest.com/* // @grant none // @namespace // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Function to remove emojis from a string function removeEmojis(str) { const emojiRegex = /[\p{Emoji}]/gu; return str.replace(emojiRegex, ''); } function updateTitle() { const scriptElement = document.getElementById('__PWS_INITIAL_PROPS__'); if (!scriptElement) return; try { const data = JSON.parse(scriptElement.textContent); const pinData = data.initialReduxState?.pins?.[Object.keys(data.initialReduxState.pins)[0]]; if (!pinData) return; const { closeup_attribution: attribution, closeup_unified_title: title, auto_alt_text: altText } = pinData; const { full_name: fullName, username } = attribution || {}; // Build title components const titleParts = []; if (fullName && username) titleParts.push(`${fullName} (${username})`); if (title) titleParts.push(title); if (altText) titleParts.push(altText); // Update document title if we have any components if (titleParts.length > 0) { document.title = removeEmojis(titleParts.join(' - ')); } } catch (error) { console.error('Error updating Pinterest title:', error); } } // MutationObserver to detect when the JSON script element is added const observer = new MutationObserver((mutations, obs) => { if (document.getElementById('__PWS_INITIAL_PROPS__')) { updateTitle(); obs.disconnect(); // Stop observing once we've found the element } }); // Start observing the document body for changes observer.observe(document.body, { childList: true, subtree: true }); // Try immediately in case the element is already present if (document.getElementById('__PWS_INITIAL_PROPS__')) { updateTitle(); } })();