Created
February 21, 2024 07:10
-
-
Save ardislu/09b0393ae632756e2cf879cc4231f41a to your computer and use it in GitHub Desktop.
Simple script to copy all the code blocks at once from an Etherscan smart contract code page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple script to copy all the code blocks at once from an Etherscan smart contract code page | |
// (example: https://etherscan.io/address/0x43506849d7c04f9138d1a2050bbf3a0c054402dd#code). | |
// Uses a hardcoded CSS selector, must update if Etherscan updates its frontend markup | |
// (this script was last updated February 2024). | |
// References: | |
// 1. Etherscan uses Ace for code blocks (https://ace.c9.io/) | |
// - API reference: https://ajaxorg.github.io/ace-api-docs/ | |
// 2. Etherscan's "Copy source to clipboard" button is implemented in `copySourceCodeBtn`, | |
// which can be found in assets/js/custom/addresspage4.js. | |
let allCodeBlocks = ''; | |
document.querySelectorAll('pre[id^=editor]').forEach(node => { | |
const editor = ace.edit(node.id); | |
editor.selectAll(); | |
const text = editor.getCopyText(); | |
allCodeBlocks += text + '\n\n'; | |
}); | |
navigator.clipboard.writeText(allCodeBlocks); | |
// Bookmarklet version: | |
// javascript:allCodeBlocks="";document.querySelectorAll("pre[id^=editor]").forEach(t=>{const e=ace.edit(t.id);e.selectAll();const o=e.getCopyText();allCodeBlocks+=o+"\n\n"}),navigator.clipboard.writeText(allCodeBlocks); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment