Skip to content

Instantly share code, notes, and snippets.

@leggsimon
Last active July 26, 2018 09:27
Show Gist options
  • Save leggsimon/cc9fe96391a6b951e88d41045e93a001 to your computer and use it in GitHub Desktop.
Save leggsimon/cc9fe96391a6b951e88d41045e93a001 to your computer and use it in GitHub Desktop.
const toBool = str => {
if (!str) {
return false
}
return str === 'true'
? true
: str === 'false'
? false
: true
}
let tweets = [...document.querySelectorAll('.tweet')].map(tweet => {
const { attributes } = tweet
return {
screenName: attributes['data-screen-name'] && attributes['data-screen-name'].value,
retweet: Boolean(attributes['data-retweeter'] && attributes['data-retweeter'].value),
retweeter: attributes['data-retweeter'] && attributes['data-retweeter'].value,
youFollow: toBool(attributes['data-you-follow'] && attributes['data-you-follow'].value),
followsYou: toBool(attributes['data-follows-you'] && attributes['data-follows-you'].value),
href: `https://twitter.com${attributes['data-permalink-path'] && attributes['data-permalink-path'].value}`,
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment