Skip to content

Instantly share code, notes, and snippets.

@simonwjackson
Last active October 5, 2017 13:45
Show Gist options
  • Save simonwjackson/56fff7941db54c4afb7ff286b74ec401 to your computer and use it in GitHub Desktop.
Save simonwjackson/56fff7941db54c4afb7ff286b74ec401 to your computer and use it in GitHub Desktop.
// ;(function(options) {
command('reddit', 'reddit list', ([sub]) => {
if (!sub) sub = 'top'
else sub = `r/${sub}`
const subreddit = `https://www.reddit.com/${sub}.json?sort=top&t=day`
function reddit2list(json) {
return json.data.children.map(child => ({
title: child.data.title.trim(),
url: child.data.url
}))
}
fetch(subreddit, { mode: 'cors' })
.then(response => response.json())
.then(reddit2list)
.then(items => {
Front.omnibar.show()
// Omnibar.listWords(words)
Omnibar.listResults(items, item => {
return $('<li/>')
.html(`<span class='title-icon'>📰</span> ${item.title}`)
.data('query', item.title)
.data('url', item.url)
})
})
})
// })(options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment