Contract Viewer Extension

Extension for VS Code Extension Contract Viewer

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Contract Viewer Extension
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Extension for VS Code Extension Contract Viewer
// @author       EndureBlaze
// @match        https://etherscan.io/address/*
// @match        https://bscscan.com/address/*
// @icon         https://raw.githubusercontent.com/MetaplasiaTeam/vscode-contract-viewer/main/image/logo.png
// @run-at document-end
// @license MIT
// @grant       GM_addStyle
// ==/UserScript==
/* jshint esversion: 6 */
(function () {
  "use strict";

  // 插入下载按钮
  GM_addStyle(".download-btn:hover { color: #3498db; }");
  let downloadBtn = document.createElement("div");
  downloadBtn.innerHTML =
    '<a class="download-btn" href="javascript:;" style="color: #000">Download Contract   </a>';
  downloadBtn.addEventListener("click", downloadContract);
  let navBar = document.querySelector(
    "div.flex-wrap:nth-child(1) > div:nth-child(2)"
  );
  navBar.insertBefore(downloadBtn, navBar.firstChild);

  function downloadContract() {
    if (document.domain === "etherscan.io") {
      console.log(parserLink("eth"));
      window.open(parserLink("eth"));
    }
    if (document.domain === "bscscan.com") {
      window.open(parserLink("bsc"));
    }
  }

  function parserLink(type) {
    let url = document.location.toString();
    let addr = url.substring(url.lastIndexOf("/"), url.length);
    return `vscode://Metaplasia.contract-viewer/download?type=${type}&addr=${addr}`;
  }
})();