const DEXSCREENER_API_URL = "https://api.dexscreener.io/latest/dex/tokens/"; function isSmartContract(address) { return address.includes('0x'); } function fetchTokenData(contractAddress,x,y) { const url = `${DEXSCREENER_API_URL}${contractAddress}`; chrome.runtime.sendMessage({ action: "fetchData", url: url }, (response) => { const data = response.data.pairs[0]; // Assuming the first pair is what you want if (data) { //alert(data.baseToken.symbol); const tooltip = createTooltip(data.baseToken.symbol, data.priceUsd || data.priceNative, data.url,x,y); document.body.appendChild(tooltip); } }); } function extractTicker(text){ const index = text.indexOf('0x'); if (index !== -1 && text.length >= index + 42) { // 2 characters for '0x' + 40 characters for the address return text.substring(index, index + 42); // Extract '0x' + 40 characters } return null; } function createTooltip(ticker, price, chartUrl,x,y) { const tooltip = document.createElement('div'); tooltip.style.position = 'absolute'; tooltip.style.background = '#333'; tooltip.style.color = '#fff'; tooltip.style.padding = '5px'; tooltip.style.borderRadius = '5px'; tooltip.style.zIndex = '9999'; tooltip.style.left = `${x}px`; tooltip.style.top = `${y}px`; tooltip.innerHTML = `Ticker: ${ticker}
Price: ${price}`; tooltip.addEventListener('click', () => window.open(chartUrl, '_blank')); return tooltip; } function handleMouseOver(event) { const target = event.target; if (target.nodeType === Node.TEXT_NODE || target.nodeType === Node.ELEMENT_NODE) { const text = target.textContent.trim(); if (isSmartContract(text)) { const extractedTicker = extractTicker(text); const rect = target.getBoundingClientRect(); // Get the target's position relative to the viewport const x = rect.left + window.scrollX; // X-coordinate const y = rect.top + window.scrollY; fetchTokenData(extractedTicker,x,y); } } } document.addEventListener('mouseover', handleMouseOver);