Zillow Sq Ft and Built in Copy

easier way to copy those 2 pieces of information bu clicking the sq ft number

// ==UserScript==
// @name         Zillow Sq Ft and Built in Copy
// @namespace    http://tampermonkey.net/*
// @version      1.0
// @description  easier way to copy those 2 pieces of information bu clicking the sq ft number
// @author       Jamie Cruz
// @match        https://www.zillow.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zillow.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to copy text to clipboard
    function copyToClipboard(text) {
        const textarea = document.createElement('textarea');
        textarea.value = text;
        document.body.appendChild(textarea);
        textarea.select();
        document.execCommand('copy');
        document.body.removeChild(textarea);
    }

    // Function to make elements clickable and copy to clipboard
    function makeElementClickable(element, additionalText = '') {
        const text = element.innerText + additionalText;
        const link = document.createElement('a');
        link.href = '#';
        link.textContent = element.innerText; // Display the original text
        link.style.cursor = 'pointer';

        link.addEventListener('click', (e) => {
            e.preventDefault();
            copyToClipboard(text);
            alert(`Copied:\n${text}`);
        });

        element.innerHTML = '';
        element.appendChild(link);
    }

    // Run the conversion when the page loads
    window.addEventListener('load', () => {
        // Process the "sq ft" element
        const factContainers = document.querySelectorAll('div[data-testid="bed-bath-sqft-fact-container"]');
        if (factContainers.length >= 3) {
            const targetContainer = factContainers[2]; // Third div with the data-testid
            const firstSpan = targetContainer.querySelector('span');
            if (firstSpan) {
                // Placeholder for additional text
                let additionalInfo = '';

                // Look for the "Built in" text
                const glanceContainer = document.querySelector('div[aria-label="At a glance facts"]');
                if (glanceContainer) {
                    const divs = glanceContainer.querySelectorAll('div'); // Find all divs within the container
                    divs.forEach(div => {
                        if (div.innerText.includes('Built in')) {
                            additionalInfo = `\n${div.innerText}`; // Add "Built in" info
                        }
                    });
                }

                // Make the square footage element clickable with additional info
                makeElementClickable(firstSpan, ` sq ft${additionalInfo}`);
            }
        }
    });
})();

QingJ © 2025

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