Skip to content

Instantly share code, notes, and snippets.

@hubgit
Last active October 4, 2022 07:53
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hubgit/d9cf2c23b9c31ab50c6c3510e7b3825e to your computer and use it in GitHub Desktop.
Save hubgit/d9cf2c23b9c31ab50c6c3510e7b3825e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<title>Twitter Archive Viewer</title>
<script>window.YTD = { tweet: {} }</script>
<script src="tweet.js"></script><!-- this is loading a file from the archive -->
<style>
.tweet { border: 1px solid #eee; margin: 8px }
.full_text { padding: 8px }
.created_at { padding: 8px; color: #777 }
</style>
<body>
<div id="root"></div>
<script>
const tweets = []
for (const part of Object.values(window.YTD.tweet)) {
tweets.push(...part)
}
const newestFirst = (a, b) => new Date(b.created_at) - new Date(a.created_at)
const renderTweet = tweet => `
<div class="tweet">
<div class="full_text">${tweet.full_text}</div>
<div class="created_at">${tweet.created_at}</div>
</div>`
document.getElementById('root').innerHTML = tweets.sort(newestFirst).map(renderTweet).join('\n')
</script>
@himari0623
Copy link

@7mr_himari

@seghier
Copy link

seghier commented Dec 11, 2019

Hi
how to use this to view twitter archive?

@durdevic
Copy link

durdevic commented Dec 26, 2019

@seghier Simply download a copy of this file and paste it in the root folder of your unarchived Twitter profile and double click.

You're going to get a list of every tweet 👌

P.S. Thanks to @hubgit for making this 💪

@spacecentrist
Copy link

im new to github but need this badly. how do i do this

@doctorgrondo
Copy link

Thank you @hubgit for making this. I copied this into the root folder of my unzipped Twitter archive (same place as tweet.js), but when I run it in my browser, I get "undefined" listed down the page.
undefined
I have no script blocking active. What could cause this?

@frozenpandaman
Copy link

frozenpandaman commented Jan 25, 2020

@hugbit Seems to be loading tweets as 'undefined' currently.

EDIT: Here's an alternate version that works for me – https://gist.github.com/tiffany352/9ee7e0d4fd7e08ede9d0314df9eab672

And a script to convert the JSON to CSV, if it's helpful to anyone – https://gist.github.com/jessefogarty/b0f2d4ea6bdd770e5e9e94d54154c751

@doctorgrondo
Copy link

EDIT: Here's an alternate version that works for me – https://gist.github.com/tiffany352/9ee7e0d4fd7e08ede9d0314df9eab672

Thanks @frozenpandaman, that one worked for me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment