Created
June 20, 2022 15:13
-
-
Save protozoo/8a351e652bbd66faf50bdf22b92e397b to your computer and use it in GitHub Desktop.
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
/* | |
Javscript snippet inteded to make it a bit easier to obtain list of tezos addresses | |
in Twitter comments, usually for Reserve Lists in fxhash and other marketplaces. | |
Also includes function to run random raffle. | |
How to use: | |
Just open the twitter page listing all the RL requests, zoom out + scroll to get full list, then open | |
devTool's console and run the script to get the functions declared. Then call the main function as needed, i.e: | |
raffle( getTezosAddresses(), 50 ); | |
*/ | |
function removeDuplicates( array ){ | |
let uniqueDict = {}; | |
let uniqueList = []; | |
array.forEach( (item)=>{ | |
if( uniqueDict[item] == null ){ | |
uniqueDict[item] = true; | |
uniqueList.push( item ); | |
} | |
} ); | |
return uniqueList; | |
} | |
function getTezosAddresses(){ | |
// Get the page's text | |
let body = document.body; | |
let textContent = body.innerText; | |
// Find all tezos addresses | |
let extractorExpression = /((?<=\s)tz\w+)|(\w+\.tez)/g; | |
let results = [...textContent.matchAll(extractorExpression)] | |
results = results.map( (item)=>{return item[0];} ); | |
// Remove duplicates | |
console.log( "# of tezos addresses found: ", results.length ); | |
results = removeDuplicates(results); | |
console.log( "# of UNIQUE tezos addresses found: ", results.length ); | |
return results; | |
} | |
function raffle( list, numWinners ){ | |
list = [...list]; // Make a copy of the array so we can modify it without affecting the source one | |
let lucky = []; | |
for (let i = 0; i < Math.min(list.length, numWinners); i++) { | |
const element = list.splice( Math.floor(Math.random()*list.length), 1 ); | |
lucky.push( element ); | |
} | |
console.log( `Selected ${lucky.length} lucky ones` ) | |
console.log( lucky.join('\n') ); | |
return lucky; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment