DexScreener Button on Solscan

Adds a Dexscreener button on Solscan page for a token

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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];
}