industry Checker

Add check links to shop names on GoodsFox website

// ==UserScript==
// @name         industry Checker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Add check links to shop names on GoodsFox website
// @author       sheire hu
// @match        https://app.goodsfox.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to add check links
    function addCheckLinks() {
        // Find all a tags with the specified class
        const shopLinks = document.querySelectorAll('a.el-tooltip.gp-table-shop__info-name');

        shopLinks.forEach(link => {
            // Check if check link already exists to avoid duplicates
            if (link.nextElementSibling && link.nextElementSibling.classList.contains('goodsfox-check-link')) {
                return;
            }

            // Extract the text content from the original link
            const shopName = link.textContent.trim();

            // Create new check link
            const checkLink = document.createElement('a');
            checkLink.href = `https://ydcms.umlife.com/#/os_website?page=1&keyword=${encodeURIComponent(shopName)}`;
            checkLink.textContent = '🏠Check';
            checkLink.className = 'goodsfox-check-link';
            checkLink.style.marginLeft = '10px';
            checkLink.style.cursor = 'pointer';
            checkLink.style.color = '#409eff'; // 默认链接蓝色
            checkLink.style.textDecoration = 'underline';

            // 添加点击事件处理程序,打开小窗口
            checkLink.addEventListener('click', function(e) {
                e.preventDefault(); // 阻止默认跳转行为

                // 计算窗口尺寸(浏览器窗口的60%)
                const windowWidth = Math.floor(window.innerWidth * 0.6);
                const windowHeight = Math.floor(window.innerHeight * 0.6);

                // 计算窗口位置(右下角显示)
                const left = Math.floor(window.screenX + window.outerWidth - windowWidth);
                const top = Math.floor(window.screenY + window.outerHeight - windowHeight);

                // 打开小窗口
                const features = `width=${windowWidth},height=${windowHeight},left=${left},top=${top},resizable=yes,scrollbars=yes`;
                window.open(this.href, '_blank', features);
            });

            // Insert the check link after the original link
            link.parentNode.insertBefore(checkLink, link.nextSibling);
        });

        // Find all elements with the ad-card-campaign-item__name class
        const campaignItems = document.querySelectorAll('.ad-card-campaign-item__name');

        campaignItems.forEach(item => {
            // Check if check link already exists to avoid duplicates
            if (item.nextElementSibling && item.nextElementSibling.classList.contains('goodsfox-check-link')) {
                return;
            }

            // Extract the text content from the element
            const itemName = item.textContent.trim();

            // Create new check link
            const checkLink = document.createElement('a');
            checkLink.href = `https://ydcms.umlife.com/#/os_website?page=1&keyword=${encodeURIComponent(itemName)}`;
            checkLink.textContent = '🏠Check';
            checkLink.className = 'goodsfox-check-link';
            checkLink.style.marginLeft = '10px';
            checkLink.style.cursor = 'pointer';
            checkLink.style.color = '#409eff'; // 默认链接蓝色
            checkLink.style.textDecoration = 'underline';

            // 添加点击事件处理程序,打开小窗口
            checkLink.addEventListener('click', function(e) {
                e.preventDefault(); // 阻止默认跳转行为

                // 计算窗口尺寸(浏览器窗口的60%)
                const windowWidth = Math.floor(window.innerWidth * 0.6);
                const windowHeight = Math.floor(window.innerHeight * 0.6);

                // 计算窗口位置(右下角显示)
                const left = Math.floor(window.screenX + window.outerWidth - windowWidth);
                const top = Math.floor(window.screenY + window.outerHeight - windowHeight);

                // 打开小窗口
                const features = `width=${windowWidth},height=${windowHeight},left=${left},top=${top},resizable=yes,scrollbars=yes`;
                window.open(this.href, '_blank', features);
            });

            // Insert the check link after the element
            item.parentNode.insertBefore(checkLink, item.nextSibling);
        });

        // Find all p tags with the gp-shop-base__title-text class
        const shopTitles = document.querySelectorAll('p.gp-shop-base__title-text');

        shopTitles.forEach(title => {
            // Check if check link already exists to avoid duplicates
            if (title.nextElementSibling && title.nextElementSibling.classList.contains('goodsfox-check-link')) {
                return;
            }

            // Extract the text content from the element
            const titleText = title.textContent.trim();

            // Create new check link
            const checkLink = document.createElement('a');
            checkLink.href = `https://ydcms.umlife.com/#/os_website?page=1&keyword=${encodeURIComponent(titleText)}`;
            checkLink.textContent = '🏠Check';
            checkLink.className = 'goodsfox-check-link';
            checkLink.style.marginLeft = '10px';
            checkLink.style.cursor = 'pointer';
            checkLink.style.color = '#409eff'; // 默认链接蓝色
            checkLink.style.textDecoration = 'underline';

            // 添加点击事件处理程序,打开小窗口
            checkLink.addEventListener('click', function(e) {
                e.preventDefault(); // 阻止默认跳转行为

                // 计算窗口尺寸(浏览器窗口的60%)
                const windowWidth = Math.floor(window.innerWidth * 0.6);
                const windowHeight = Math.floor(window.innerHeight * 0.6);

                // 计算窗口位置(右下角显示)
                const left = Math.floor(window.screenX + window.outerWidth - windowWidth);
                const top = Math.floor(window.screenY + window.outerHeight - windowHeight);

                // 打开小窗口
                const features = `width=${windowWidth},height=${windowHeight},left=${left},top=${top},resizable=yes,scrollbars=yes`;
                window.open(this.href, '_blank', features);
            });

            // Insert the check link after the element
            title.parentNode.insertBefore(checkLink, title.nextSibling);
        });
    }

    // Run immediately
    addCheckLinks();

    // Set up a MutationObserver to handle dynamically loaded content
    const observer = new MutationObserver(function(mutations) {
        let shouldAddLinks = false;

        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                shouldAddLinks = true;
            }
        });

        if (shouldAddLinks) {
            addCheckLinks();
        }
    });

    // Start observing
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();