// ==UserScript== // @name GMGN KOL喊单快捷跳转 // @namespace http://tampermonkey.net/ // @version 2.0 // @description 快速跳转到X3.pro查看代币KOL喊单信息 // @author Crypto.MX // @match https://gmgn.ai/* // @grant GM_addStyle // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/544296/GMGN%20KOL%E5%96%8A%E5%8D%95%E5%BF%AB%E6%8D%B7%E8%B7%B3%E8%BD%AC.user.js // @updateURL https://update.greasyfork.icu/scripts/544296/GMGN%20KOL%E5%96%8A%E5%8D%95%E5%BF%AB%E6%8D%B7%E8%B7%B3%E8%BD%AC.meta.js // ==/UserScript== (function() { 'use strict'; // 全局变量 let currentChain = ''; let currentTokenAddress = ''; console.log(` ========================================== 🎯 GMGN KOL喊单快捷跳转脚本已启动 ========================================== 版本: 2.0 功能: 快速跳转到X3.pro查看KOL喊单 作者: Crypto.MX ========================================== `); /** * 添加CSS样式 */ function addStyles() { GM_addStyle(` .kol-jump-icon { display: flex; gap: 2px; align-items: center; font-size: 13px; line-height: 16px; font-weight: normal; color: rgb(156, 163, 175); transition: colors 0.2s ease; cursor: pointer; padding: 4px 6px; border-radius: 4px; background: transparent; border: none; } .kol-jump-icon:hover { color: rgb(229, 231, 235); background: rgba(75, 85, 99, 0.1); } .kol-jump-icon svg { width: 14px; height: 14px; fill: currentColor; } `); } /** * 解析当前URL获取链网络和代币地址 */ function parseCurrentUrl() { const url = location.href; console.log(`[URL解析] 开始解析URL: ${url}`); const match = url.match(/\/([^\/]+)\/token\/([^?&#]+)/); if (match) { currentChain = match[1]; let rawAddress = match[2]; // 处理可能存在的前缀 if (rawAddress.includes('_')) { const parts = rawAddress.split('_'); if (parts.length >= 2) { currentTokenAddress = parts[1]; console.log(`[URL解析] 检测到前缀格式,原始: ${rawAddress}, 提取代币地址: ${currentTokenAddress}`); } else { currentTokenAddress = rawAddress; } } else { currentTokenAddress = rawAddress; } if (currentTokenAddress.length >= 32) { console.log(`[URL解析] ✅ 解析成功 - 链网络: ${currentChain}, 代币地址: ${currentTokenAddress}`); } else { console.warn(`[URL解析] ⚠️ 代币地址长度异常: ${currentTokenAddress} (长度: ${currentTokenAddress.length})`); } } else { currentChain = ''; currentTokenAddress = ''; console.log('[URL解析] ❌ 无法从URL解析出代币信息'); } } /** * 跳转到X3.pro页面 */ function jumpToX3Pro() { if (!currentTokenAddress) { console.warn('[跳转] ❌ 无有效的代币地址,无法跳转'); return; } const x3ProUrl = `https://x3.pro/trending-tweets/coin-search?address=${currentTokenAddress}`; console.log(`[跳转] 🚀 跳转到X3.pro: ${x3ProUrl}`); window.open(x3ProUrl, '_blank'); } /** * 设置UI界面 */ function setupUI() { const observer = new MutationObserver(() => { if (currentTokenAddress) { injectKolIcon(); } }); observer.observe(document.body, { childList: true, subtree: true }); // 初始尝试注入 setTimeout(() => { if (currentTokenAddress) { injectKolIcon(); } }, 1000); } /** * 注入KOL图标 */ function injectKolIcon() { // 查找目标容器 const targetSelector = '.flex.items-center.text-sm.gap-x-4px.text-text-300.whitespace-nowrap'; const container = document.querySelector(targetSelector); if (!container) { console.log('[UI注入] 未找到目标容器,稍后重试'); return; } // 检查是否已经注入过 if (container.querySelector('.kol-jump-icon')) { return; } // 创建KOL图标元素 const kolIcon = document.createElement('button'); kolIcon.className = 'kol-jump-icon'; kolIcon.title = '查看KOL喊单信息'; // 使用类似风格的KOL分析图标 kolIcon.innerHTML = ` KOL `; // 绑定点击事件 kolIcon.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); jumpToX3Pro(); }); // 插入到容器中 container.appendChild(kolIcon); console.log(`[UI注入] ✅ KOL图标已注入,代币地址: ${currentTokenAddress}`); } /** * 监听URL变化 */ function setupUrlChangeListener() { let lastUrl = location.href; // 监听浏览器历史变化 window.addEventListener('popstate', () => { if (location.href !== lastUrl) { lastUrl = location.href; handleUrlChange(); } }); // 监听pushState和replaceState const originalPushState = history.pushState; const originalReplaceState = history.replaceState; history.pushState = function() { originalPushState.apply(history, arguments); setTimeout(handleUrlChange, 100); }; history.replaceState = function() { originalReplaceState.apply(history, arguments); setTimeout(handleUrlChange, 100); }; // 使用MutationObserver监听DOM变化 const observer = new MutationObserver(() => { if (location.href !== lastUrl) { lastUrl = location.href; handleUrlChange(); } }); observer.observe(document.body, { childList: true, subtree: true }); } /** * 处理URL变化 */ function handleUrlChange() { console.log('[URL监听] 检测到URL变化:', location.href); const oldTokenAddress = currentTokenAddress; parseCurrentUrl(); if (currentTokenAddress !== oldTokenAddress) { console.log(`[URL监听] 代币地址已变化: ${oldTokenAddress} -> ${currentTokenAddress}`); // 移除旧的图标 const oldIcons = document.querySelectorAll('.kol-jump-icon'); oldIcons.forEach(icon => icon.remove()); // 延迟注入新图标 setTimeout(() => { if (currentTokenAddress) { injectKolIcon(); } }, 500); } } /** * 初始化脚本 */ function init() { console.log('[脚本初始化] 🚀 开始初始化KOL快捷跳转脚本'); addStyles(); parseCurrentUrl(); setupUI(); setupUrlChangeListener(); console.log('[脚本初始化] ✅ KOL快捷跳转脚本初始化完成'); } // 等待DOM加载完成后初始化 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();