Advertisement
amir_habibzadeh

Warpcast - Select all wallets and ENS addresses in replies

Apr 27th, 2024 (edited)
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.53 KB | Source Code | 0 0
  1. // Select all elements with the class .whitespace-pre-wrap
  2. var allElements = document.querySelectorAll('.whitespace-pre-wrap');
  3.  
  4. // Regular expression to match Ethereum wallet addresses starting with "0x" without surrounding spaces (case-insensitive)
  5. var ethereumWalletRegex = /(^|\s)(0x[a-fA-F0-9]{40})(?=\s|$)/g;
  6.  
  7. // Regular expression to match ENS names ending with ".eth" without surrounding spaces (case-insensitive)
  8. var ensNameRegex = /(^|\s)([a-zA-Z0-9-]+\.eth)(?=\s|$)/g;
  9.  
  10. // Arrays to store the results
  11. var ethereumWalletsArray = [];
  12. var ensNamesArray = [];
  13.  
  14. // Iterate over each element
  15. allElements.forEach(function(element) {
  16.     // Get all <div> elements inside the current element
  17.     var divsInsideElement = element.querySelectorAll('div');
  18.  
  19.     // Iterate over each <div> element
  20.     divsInsideElement.forEach(function(div) {
  21.         // Search for Ethereum wallet addresses starting with "0x" without surrounding spaces (case-insensitive)
  22.         var ethereumWallets = div.textContent.match(ethereumWalletRegex);
  23.         if (ethereumWallets) {
  24.             // Convert to lowercase and trim
  25.             ethereumWallets = ethereumWallets.map(function(wallet) {
  26.                 return wallet.trim().toLowerCase();
  27.             });
  28.             // Concatenate to the existing array
  29.             ethereumWalletsArray = ethereumWalletsArray.concat(ethereumWallets);
  30.         }
  31.  
  32.         // Search for ENS names ending with ".eth" without surrounding spaces (case-insensitive)
  33.         var ensNames = div.textContent.match(ensNameRegex);
  34.         if (ensNames) {
  35.             // Convert to lowercase and trim
  36.             ensNames = ensNames.map(function(name) {
  37.                 return name.trim().toLowerCase();
  38.             });
  39.             // Concatenate to the existing array
  40.             ensNamesArray = ensNamesArray.concat(ensNames);
  41.         }
  42.     });
  43. });
  44.  
  45. // Convert arrays to Sets to remove duplicates
  46. var uniqueEthereumWallets = new Set(ethereumWalletsArray);
  47. var uniqueEnsNames = new Set(ensNamesArray);
  48.  
  49. // Convert Sets back to arrays
  50. var uniqueEthereumWalletsArray = [...uniqueEthereumWallets];
  51. var uniqueEnsNamesArray = [...uniqueEnsNames];
  52.  
  53. // Join the unique arrays with commas
  54. var concatenatedUniqueEthereumWallets = uniqueEthereumWalletsArray.join(',');
  55. var concatenatedUniqueEnsNames = uniqueEnsNamesArray.join(',');
  56.  
  57. // Log the concatenated unique results
  58. console.log("Concatenated Unique Ethereum Wallets:", concatenatedUniqueEthereumWallets);
  59. console.log("Concatenated Unique ENS Names:", concatenatedUniqueEnsNames);
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement