DexScreener Button on Solscan

Adds a Dexscreener button on Solscan page for a token

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         DexScreener Button on Solscan
// @namespace    http://tampermonkey.net/
// @version      2025-01-14
// @description  Adds a Dexscreener button on Solscan page for a token
// @author       Abhishek Prasad
// @match        https://solscan.io/token/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=solscan.io
// @grant        none
// @license      MIT 
// ==/UserScript==

// ==UserScript==
// @name        DexScreener Link on Solscan
// @namespace   http://tampermonkey.net/
// @version     2025-01-14
// @description Adds a Dexscreener link on Solscan page for a token
// @author      Abhishek Prasad
// @match       https://solscan.io/token/*
// @icon        https://www.google.com/s2/favicons?sz=64&domain=solscan.io
// @grant       none
// ==/UserScript==

var input = document.createElement("input");
input.type = "button";
input.value = "DexScreener Link";
input.onclick = showAlert;

// Apply inline styles to the button
input.setAttribute("style", `
  background-color: #007bff; /* Blue background */
  color: white;
  border: none;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 5px; /* Add rounded corners */
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2); /* Add a subtle shadow */
  position: absolute;
  top: 120px;
  right: 40px;
`);

document.body.appendChild(input);

function showAlert() {
  const currentUrl = window.location.href;
  console.log(currentUrl);
  window.location.href = "https://dexscreener.com/solana/" + getLastPartOfUrl(currentUrl);
}

function getLastPartOfUrl(url) {
  const urlObj = new URL(url);
  const pathParts = urlObj.pathname.split('/');
  return pathParts[pathParts.length - 1];
}