Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Select all elements with the class .whitespace-pre-wrap
- var allElements = document.querySelectorAll('.whitespace-pre-wrap');
- // Regular expression to match Ethereum wallet addresses starting with "0x" without surrounding spaces (case-insensitive)
- var ethereumWalletRegex = /(^|\s)(0x[a-fA-F0-9]{40})(?=\s|$)/g;
- // Regular expression to match ENS names ending with ".eth" without surrounding spaces (case-insensitive)
- var ensNameRegex = /(^|\s)([a-zA-Z0-9-]+\.eth)(?=\s|$)/g;
- // Arrays to store the results
- var ethereumWalletsArray = [];
- var ensNamesArray = [];
- // Iterate over each element
- allElements.forEach(function(element) {
- // Get all <div> elements inside the current element
- var divsInsideElement = element.querySelectorAll('div');
- // Iterate over each <div> element
- divsInsideElement.forEach(function(div) {
- // Search for Ethereum wallet addresses starting with "0x" without surrounding spaces (case-insensitive)
- var ethereumWallets = div.textContent.match(ethereumWalletRegex);
- if (ethereumWallets) {
- // Convert to lowercase and trim
- ethereumWallets = ethereumWallets.map(function(wallet) {
- return wallet.trim().toLowerCase();
- });
- // Concatenate to the existing array
- ethereumWalletsArray = ethereumWalletsArray.concat(ethereumWallets);
- }
- // Search for ENS names ending with ".eth" without surrounding spaces (case-insensitive)
- var ensNames = div.textContent.match(ensNameRegex);
- if (ensNames) {
- // Convert to lowercase and trim
- ensNames = ensNames.map(function(name) {
- return name.trim().toLowerCase();
- });
- // Concatenate to the existing array
- ensNamesArray = ensNamesArray.concat(ensNames);
- }
- });
- });
- // Convert arrays to Sets to remove duplicates
- var uniqueEthereumWallets = new Set(ethereumWalletsArray);
- var uniqueEnsNames = new Set(ensNamesArray);
- // Convert Sets back to arrays
- var uniqueEthereumWalletsArray = [...uniqueEthereumWallets];
- var uniqueEnsNamesArray = [...uniqueEnsNames];
- // Join the unique arrays with commas
- var concatenatedUniqueEthereumWallets = uniqueEthereumWalletsArray.join(',');
- var concatenatedUniqueEnsNames = uniqueEnsNamesArray.join(',');
- // Log the concatenated unique results
- console.log("Concatenated Unique Ethereum Wallets:", concatenatedUniqueEthereumWallets);
- console.log("Concatenated Unique ENS Names:", concatenatedUniqueEnsNames);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement