Convert Value to Link by ID

Convert value attributes to clickable links for elements with a specific ID on https://cab.meest.cn

当前为 2023-11-10 提交的版本,查看 最新版本

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Convert Value to Link by ID
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Convert value attributes to clickable links for elements with a specific ID on https://cab.meest.cn
// @author       max5555
// @match        https://cab.meest.cn/*
// @grant        none
// @license  	MIT

// ==/UserScript==

(function() {
    'use strict';

    function convertValueToLink() {
        const elements = document.querySelectorAll('#photo-product');
        for (const element of elements) {
            const url = element.getAttribute('value');
            if (url && !element.nextElementSibling?.classList.contains('converted-link')) {
                const anchor = document.createElement('a');
                anchor.href = url;
                anchor.target = '_blank';
                anchor.textContent = url;
                anchor.classList.add('converted-link');  // To avoid adding the same link multiple times
                element.insertAdjacentElement('afterend', anchor);
            }
        }
    }

    // Use a MutationObserver to detect dynamic content changes
    const observer = new MutationObserver(mutations => {
        convertValueToLink();
    });
    observer.observe(document.body, { childList: true, subtree: true });

    // Convert existing elements on page load
    convertValueToLink();
})();