Etherscan Contract Downloader

batch download etherscan verified contract

2022-10-20 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

  1. // ==UserScript==
  2. // @name Etherscan Contract Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.7
  5. // @description batch download etherscan verified contract
  6. // @author jason@trillion.fi
  7. // @match https://*.etherscan.io/address/*
  8. // @match https://ftmscan.com/address/*
  9. // @match https://bscscan.com/address/*
  10. // @match https://snowtrace.io/address/*
  11. // @match https://polygonscan.com/address/*
  12. // @match https://hecoinfo.com/address/*
  13. // @match https://optimistic.etherscan.io/address/*
  14. // @match https://arbiscan.io/address/*
  15. // @match https://aurorascan.dev/address/*
  16. // @match https://cronoscan.com/address/*
  17. // @icon https://etherscan.io/images/brandassets/etherscan-logo-circle.png
  18. // @grant unsafeWindow
  19. // @license MIT
  20. // ==/UserScript==
  21. (function() {
  22. 'use strict';
  23.  
  24. // Your code here...
  25. let editorIds = $("[id^=editor]")
  26. let spans = $("span[class=text-secondary]").toArray();
  27. spans.shift();
  28.  
  29. console.log(`found ${editorIds.length-1} editors`);
  30.  
  31.  
  32. function getAddr() {
  33. const regex = /0x[0-9A-Fa-f]{40}/g;
  34. const found = window.location.href.match(regex);
  35. return found[0]
  36. }
  37.  
  38. function getDethUrl() {
  39. let host = window.location.host;
  40. let newHost = host.split(".")[0] + ".deth.net"
  41. let url = window.location.href;
  42. return url.replace(host, newHost);
  43. }
  44.  
  45. function downloadEditor(index) {
  46. let addr = getAddr()
  47. let editor = ace.edit(editorIds[index])
  48. let filename;
  49. try {
  50. filename = `${addr}-${spans[index].innerText.split(":")[1].trim()}`
  51. } catch {
  52. filename = `${addr}.sol`
  53. }
  54. console.log(filename)
  55. let HTMLhiddenElement = document.createElement("a");
  56. HTMLhiddenElement.href = 'data:attachment/text,' + encodeURIComponent(editor.getValue());
  57. HTMLhiddenElement.target = '_blank';
  58. HTMLhiddenElement.download = filename;
  59. HTMLhiddenElement.click();
  60. }
  61.  
  62. function downloadAll() {
  63. if (editorIds.length == 1) {
  64. downloadEditor(0)
  65. return
  66. }
  67. for (let i = 0; i < editorIds.length - 1; i++) {
  68. downloadEditor(i)
  69. }
  70. }
  71.  
  72. if (!unsafeWindow.downloadAll) {
  73. unsafeWindow.downloadAll = downloadAll;
  74. }
  75.  
  76. $("#nav_subtabs").append('<li class="nav-item"><a class="nav-link show" href="#download" data-toggle="tab" onclick="javascript:downloadAll();"><span>Download</span></a></li>');
  77. $("#nav_subtabs").append(`<li class="nav-item"><a class="nav-link show" href="#vscode" onclick="window.open('${getDethUrl()}','_blank')" data-toggle="tab""><span>Edit on Deth.net</span></a></li>`);
  78.  
  79. $('.table th:contains("Age")').css("width", "14%");
  80.  
  81. $('.table span:contains(" ago")').each(function() {
  82. var relTime = $(this).text();
  83. var absTime = $(this).attr('title');
  84. if (!absTime) absTime = $(this).attr('data-original-title');
  85. // absTime = moment(absTime, "MMM-DD-YYYY hh:mm:ss A", "en").add(1, 'h').format("YYYY-MM-DD HH:mm:ss");
  86. absTime = moment(absTime).add(8, 'h').format("YYYY-MM-DD HH:mm:ss");
  87. $(this).attr('title', relTime);
  88. $(this).attr('data-original-title', relTime);
  89. $(this).text(absTime);
  90. });
  91.  
  92. //
  93. })();