Greasy Fork is available in English.

etherscan-helper

Gadget for etherscan.io

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name etherscan-helper
  3. // @version 0.0.1
  4. // @description Gadget for etherscan.io
  5. // @namespace userscripts.henryfour.com
  6. // @homepageURL https://github.com/henryfour/userscripts
  7. // @supportURL https://github.com/henryfour/userscripts/issues
  8. // @author HenryFour
  9. // @copyright 2020+, HenryFour
  10. // @license MIT
  11. //
  12. // @run-at document-start
  13. // @grant GM_addStyle
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @match https://cn.etherscan.com/*
  17. // @match https://*.etherscan.io/*
  18. // @match https://*.bscscan.com/*
  19. // @match https://*.hecoinfo.com/*
  20. // @match https://*.ftmscan.com/*
  21. // @match https://*.polygonscan.com/*
  22. // @match https://*.arbiscan.io/*
  23. // @match https://*.snowtrace.io/*
  24. //
  25. // @icon https://etherscan.io/images/favicon2.ico
  26. // @require https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
  27. // ==/UserScript==
  28.  
  29. GM_addStyle(
  30. // reference: https://gradientbuttons.colorion.co/
  31. ".btn-grad {background-image: linear-gradient(to right, #E55D87 0%, #5FC3E4 51%, #E55D87 100%)}"
  32. + ".btn-grad {margin: 10px; padding: 10px 20px; text-align: center; text-transform: uppercase; transition: 0.5s; background-size: 200% auto; color: white; box-shadow: 0 0 20px #eee; border-radius: 10px; display: block; border-width: 0;}"
  33. + ".btn-grad:hover { background-position: right center; color: #fff; text-decoration: none; }"
  34. + ".auto-jump { margin: 10px; padding: 4px; color: #fff; background-color: #21325b; }"
  35. + ".auto-jump label { margin: 0 0 0 4px; }"
  36. );
  37.  
  38. (function () {
  39. 'use strict';
  40.  
  41. const HostCN = "cn.etherscan.com";
  42. const HostEN = "etherscan.io";
  43.  
  44. const KeyAutoI18n = "etherscan.auto-jump";
  45. function getAutoI18n() {
  46. return GM_getValue(KeyAutoI18n, "");
  47. }
  48.  
  49. function isHostEN() {
  50. return window.location.hostname == HostEN;
  51. }
  52. function isHostCN() {
  53. return window.location.hostname == HostCN;
  54. }
  55.  
  56. function jumpToHost(toHost) {
  57. if (toHost && window.location.hostname != toHost) {
  58. if (getAutoI18n()) {
  59. setAutoI18n(toHost);
  60. }
  61. let jumpUrl = window.location.href.replace(window.location.hostname, toHost);
  62. window.location.href = jumpUrl;
  63. return true;
  64. }
  65. return false;
  66. }
  67.  
  68.  
  69. function setAutoI18n(toHost) {
  70. GM_setValue(KeyAutoI18n, toHost);
  71. }
  72.  
  73. function tryAutoI18n() {
  74. let toHost = getAutoI18n();
  75. switch (toHost) {
  76. case HostEN:
  77. return isHostCN() && jumpToHost(toHost);
  78. case HostCN:
  79. return isHostEN() && jumpToHost(toHost);
  80. default:
  81. return false;
  82. }
  83. }
  84.  
  85. // auto jump before document loaded
  86. if (tryAutoI18n()) {
  87. return;
  88. }
  89.  
  90. function toI18n(parent) {
  91. let btnText, toHost, checkText;
  92. if (isHostEN()) {
  93. btnText = '转到中文站';
  94. toHost = HostCN;
  95. checkText = '自动跳转';
  96. } else if (isHostCN()) {
  97. btnText = 'Goto EN';
  98. toHost = HostEN;
  99. checkText = 'Auto Jump';
  100. } else {
  101. // no jump for testnets
  102. return;
  103. }
  104. addButton(parent, btnText, () => { jumpToHost(toHost) }, 'btn-grad');
  105. addCheckbox(parent, checkText, (checked) => { setAutoI18n(checked ? toHost : ""); });
  106. }
  107.  
  108. // Add button to view code in deth.net
  109. function toCodeViewer(parent) {
  110. // https://github.com/dethcrypto/ethereum-code-viewer/blob/main/docs/supported-explorers.md
  111. let url = location.href;
  112. if (url.indexOf(".io/") > 0) {
  113. url = url.replace(".io/", ".deth.net/");
  114. } else if (url.indexOf(".com") > 0) {
  115. url = url.replace(".com/", ".deth.net/");
  116. }
  117. addButton(parent, 'deth.net', () => window.open(url), 'btn-grad');
  118. }
  119.  
  120. window.addEventListener('load', () => {
  121. // Hide username for screenshots sharing
  122. let profile = document.getElementById("dropdownUser");
  123. if (profile) {
  124. profile.childNodes[1].textContent = "My Profile";
  125. }
  126.  
  127. // floating functions
  128. const floatingArea = addFloatingArea();
  129. toCodeViewer(floatingArea);
  130. toI18n(floatingArea);
  131. })
  132.  
  133. function addButton(parent, text, onclick, cls, styles) {
  134. let button = document.createElement('button');
  135. button.innerHTML = text;
  136. button.onclick = onclick;
  137. button.className = cls;
  138. styles = styles || {}
  139. Object.keys(styles).forEach(key => button.style[key] = styles[key]);
  140. parent.appendChild(button);
  141. return button
  142. }
  143.  
  144. function addCheckbox(parent, text, cb, cls) {
  145. let div = document.createElement('div');
  146. div.className = 'auto-jump';
  147. let input = document.createElement('input');
  148. input.type = 'checkbox';
  149. input.id = 'auto-jump-check';
  150. input.checked = getAutoI18n() ? true : false;
  151. input.value = true;
  152. input.onclick = () => { cb(input.checked); };
  153. let label = document.createElement('label');
  154. label.innerHTML = text;
  155. label.setAttribute('for', input.id);
  156. div.append(input, label);
  157. parent.appendChild(div);
  158. }
  159.  
  160. function addFloatingArea() {
  161. let div = document.createElement('div');
  162. let styles = { position: 'fixed', top: '20%', right: '1%', 'z-index': 9999 };
  163. Object.keys(styles).forEach(key => div.style[key] = styles[key]);
  164. document.body.appendChild(div);
  165. return div;
  166. }
  167. })();