Contract Viewer Extension

Extension for VS Code Extension Contract Viewer

当前为 2022-01-28 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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}`;
  }
})();