From 44f486df954bb4800e2a48298b43e18867b7bc79 Mon Sep 17 00:00:00 2001 From: Mentor Date: Thu, 27 Jan 2022 10:18:37 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Merch=20public=20beta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- community/scraping.js | 108 +++++++++++++++++++++++++++++ minter/src/assets/present-icon.svg | 1 + 2 files changed, 109 insertions(+) create mode 100644 community/scraping.js create mode 100644 minter/src/assets/present-icon.svg diff --git a/community/scraping.js b/community/scraping.js new file mode 100644 index 0000000..808a02e --- /dev/null +++ b/community/scraping.js @@ -0,0 +1,108 @@ +/* /////////////////////////////// +// Twitter +// scraping for signer.is +// /////////////////////////////*/ + +function get_address_from_base64( text ) { + + const [ batch, base64 ] = text.match( /(?:https:\/\/signer.is\/#\/verify\/)(.*?)(?:(<\/)|(">)|($))/ ) || [] + + try { + + const text = atob( base64 ) + const json = JSON.parse( decodeURIComponent( text ) ) + + return json.claimed_signatory + + } catch( e ) { + + console.log( `Decoding error for ${ base64 } `, e ) + return false + + } + +} + +async function get_addresses_from_twitter_links( links ) { + + const resolved_twitter_redirects = await Promise.all( links.map( url => fetch( url ).then( res => res.text() ) ) ) + const addresses = resolved_twitter_redirects.map( get_address_from_base64 ) + return addresses + +} + +async function scrape_signer_links_in_replies( ) { + + console.log( '⚠️ Disable security policy headers with a chrome extension' ) + + const hrefs = document.querySelectorAll( 'a' ) + const has_signer_is = [ ...hrefs ].filter( ( { innerText, ...rest } ) => { + return innerText.includes( 'signer.is/#/verify' ) + } ) + const signer_is_hrefs = has_signer_is.map( ( { href } ) => href ) + const addresses = await get_addresses_from_twitter_links( signer_is_hrefs ) + + console.log( addresses.join( '\n' ) ) + +} + + + +async function scrape_signer_links_in_dm( ) { + + console.log( `This function runs for an indeterminate length, keep an eye on it and run get_addresses_from_twitter_links when results stagnate` ) + + const wait = ( durationinMs=1000 ) => new Promise( resolve => setTimeout( resolve, durationinMs ) ) + function get_handle_from_element( element ) { + const [ match, handle ] = element.innerHTML.match( /(@.+?)(?:<\/)/ ) + if( handle ) return handle + else return false + } + + const hits = [] + const done = [] + + while( true ) { + + const messages = document.querySelectorAll( '[aria-selected=false]' ) + + for (let i = messages.length - 1; i >= 0; i--) { + + // Get the handle of the message we are trying + const handle = get_handle_from_element( messages[i] ) + if( done.includes( handle ) ) continue + if( !messages[i].isConnected ) continue + + // open the message panel and grab the link + messages[i].click() + await wait() + const links = document.querySelectorAll( 'a' ) + const { href, ...rest } = [ ...links ].find( ( { innerText } ) => innerText.includes( 'signer.is/#/verify' ) ) || [] + + // Save the link and mark the handle as done of need be + if( href ) hits.push( href ) + done.push( handle ) + + document.querySelector( '[aria-label="Back"]' ).click() + await wait() + + } + + console.log( `Checked ${ done.length } handles. Found: `, hits ) + + } + +} + +function discord_channel_scraping() { + + const hrefs = document.querySelectorAll( 'a' ) + const has_signer_is = [ ...hrefs ].filter( ( { innerText, ...rest } ) => { + return innerText.includes( 'signer.is/#/verify' ) + } ) + console.log( has_signer_is[0].href ) + const signer_is_hrefs = has_signer_is.map( ( { title } ) => title ) + const addresses = signer_is_hrefs.map( get_address_from_base64 ) + console.log( addresses.join( '\n' ) ) + +} diff --git a/minter/src/assets/present-icon.svg b/minter/src/assets/present-icon.svg new file mode 100644 index 0000000..9019d7b --- /dev/null +++ b/minter/src/assets/present-icon.svg @@ -0,0 +1 @@ + \ No newline at end of file