JSFiddle - React, Tailwind, and code Playground
by octatone
HTML
<h1>r/distilled</h1>
<h2>cut through the crap!</h2>
<div id="options">[ <a href="#" id="front">front page</a> | <a href="#" id="all">/r/all</a> ]</div>
<div id="listing"></div>
<div id="footer">
<p>r/distilled filters your front page and /r/all down to one post per subreddit preventing circlejerks and bandwagons from taking over your reddit experience</p>
<p>r/distilled is not associated with reddit.com, reddit inc. or any of their affiliates. All trademarks are property of their owners.</p>
</div>
CSS
body {
font: normal x-small verdana, arial, helvetica, sans-serif;
}
h1 {
text-align: center;
font-size: xx-large;
}
h2 {
margin: 0 0 .5em;
font-style: italic;
text-align: center;
font-size: small;
}
#options {
text-align: center;
}
#listing {
width: 100%;
margin-top: 15px;
}
.thing div {
margin-bottom: 30px;
}
.entry {
overflow: hidden;
margin-left: 3px;
opacity: 1;
}
.title {
font-size: medium;
font-weight: normal;
margin-bottom: 1px;
}
.thing .title {
color: blue;
padding: 0px;
overflow: hidden;
}
.domain {
color: #888;
font-size: x-small;
}
.tagline {
color: #888;
font-size: x-small;
}
.tagline a, #options a {
color: #369;
text-decoration: none;
}
a.author {
}
.subreddit {
margin-bottom: 10px;
}
.thumbnail {
float: left;
margin: 0px 5px 30px 5px;
overflow: hidden;
width: 70px;
}
.clearleft {
clear: left;
height: 0px;
}
.score {
font-weight: bold;
}
.ups {
color: blue;
}
.downs {
color: red;
}
.flat-list {
display: block;
list-style-type: none;
padding: 1px 0;
}
.entry li a {
color: #888;
font-weight: bold;
padding: 0 1px;
}
a {
text-decoration: none;
}
#footer {
margin: 15px;
text-align: center;
}
#footer p {
margin-bottom: 1em;
}
#loading {
color: green;
width: 100%;
text-align: center;
font-weight: bold;
}
#error {
color: red;
width: 100%;
text-align: center;
font-weight: bold;
}
JavaScript
function display(data) {
var content, $listing = $('#listing');
$listing.empty().hide();
for (x in data) {
content = '<div class="thing">' + '<a href="' + data[x].data.url + '" class="thumbnail" target="_blank"><img src="' + data[x].data.thumbnail + '" width="70"/></a>' + '<div class="entry">' + '<p class="title">' + '<a href="' + data[x].data.url + '" class="title" target="_blank">' + data[x].data.title + '</a>' + ' <span class="domain">(' + data[x].data.domain + ')</span>' + '</p>' + '<p class="tagline">' + '<span class="score">' + data[x].data.score + '</span> (<span class="ups">' + data[x].data.ups + '</span>|<span class="downs">' + data[x].data.downs + '</span>) ' + 'submitted ' + longAgo(data[x].data.created_utc) + ' hours ago by ' + '<a href="http://reddit.com/user/' + data[x].data.author + '" class="author" target="_blank">' + data[x].data.author + '</a> to ' + '<a href="http://reddit.com/r/' + data[x].data.subreddit + '" class="subreddit" target="_blank">' + data[x].data.subreddit + '</a>' + '</p>' + '<ul class="flat-list">' + '<li><a href="http://reddit.com' + data[x].data.permalink + '" class="comments" target="_blank">' + data[x].data.num_comments + ' comments</a></li>' + '</ul>' + '</div></div>' + '<div class="clearleft"></div>';
$listing.append(content);
}
$listing.hide().fadeIn('slow');
}
function filterDupes(arr) {
var i, out = [],
obj = {},
original_length = arr.length;
//remove dupes
for (i = arr.length - 1; i >= 0; i--) {
if (typeof obj[arr[i].data.subreddit] != 'undefined') {
delete obj[arr[i].data.subreddit];
}
obj[arr[i].data.subreddit] = arr[i];
}
for (i in obj) {
out.push(obj[i]);
}
return out.reverse();
}
function loadPosts(option) {
var sub = '',
$listing = $('#listing');
$listing.fadeOut(function() {
$listing.empty().show(function() {
$listing.append('<div...