diff --git a/src/content/etherscan/components/DecompileInDedaubBtn/index.tsx b/src/content/etherscan/components/DecompileInDedaubBtn/index.tsx index 5cae2d1..72f7d6c 100644 --- a/src/content/etherscan/components/DecompileInDedaubBtn/index.tsx +++ b/src/content/etherscan/components/DecompileInDedaubBtn/index.tsx @@ -19,7 +19,37 @@ const DecompileInDedaubBtn: FC = ({ mainAddress, chain }) => { `https://library.dedaub.com/${item.pathname}/address/${mainAddress}/decompiled` ) } else { - window.open('https://library.dedaub.com/decompile') + const url = 'https://library.dedaub.com/api/on_demand' + const bytecode = document.getElementById('dividcode') + if (bytecode == null) { + window.open('https://library.dedaub.com/decompile') + return + } + const data = { + hex_bytecode: bytecode.innerText + } + fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + authority: 'api.dedaub.com', + origin: 'https://library.dedaub.com', + referer: 'https://library.dedaub.com/' + }, + body: JSON.stringify(data), + mode: 'cors' + }) + .then(response => response.text()) + .then(data => { + console.log('Success:', data) + window.open( + 'https://library.dedaub.com/decompile?md5=' + data.replace(/"/g, '') + ) + }) + .catch(error => { + console.error('Error:', error) + window.open('https://library.dedaub.com/decompile') + }) } } diff --git a/src/content/scans/components/DecompileInDedaubBtn/index.tsx b/src/content/scans/components/DecompileInDedaubBtn/index.tsx index 5cae2d1..7fb5133 100644 --- a/src/content/scans/components/DecompileInDedaubBtn/index.tsx +++ b/src/content/scans/components/DecompileInDedaubBtn/index.tsx @@ -13,13 +13,42 @@ interface Props { const DecompileInDedaubBtn: FC = ({ mainAddress, chain }) => { const toDedaub = () => { const item = DEDAUB_SUPPORT_DIRECT_LIST.find(item => item.chain === chain) - if (item) { window.open( `https://library.dedaub.com/${item.pathname}/address/${mainAddress}/decompiled` ) } else { - window.open('https://library.dedaub.com/decompile') + const url = 'https://library.dedaub.com/api/on_demand' + const bytecode = document.getElementById('dividcode') + if (bytecode == null) { + window.open('https://library.dedaub.com/decompile') + return + } + const data = { + hex_bytecode: bytecode.innerText + } + fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + authority: 'api.dedaub.com', + origin: 'https://library.dedaub.com', + referer: 'https://library.dedaub.com/' + }, + body: JSON.stringify(data), + mode: 'cors' + }) + .then(response => response.text()) + .then(data => { + console.log('Success:', data) + window.open( + 'https://library.dedaub.com/decompile?md5=' + data.replace(/"/g, '') + ) + }) + .catch(error => { + console.error('Error:', error) + window.open('https://library.dedaub.com/decompile') + }) } }