Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from michaelsergio/master
Browse files Browse the repository at this point in the history
Link to comments sections
  • Loading branch information
Charles Cash committed Jul 26, 2014
2 parents 36802ed + b926ffe commit f2cb90c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
55 changes: 49 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ function YComb(callback){
var subtext = a.parent().parent().next().children('.subtext').children(); // gets the subtext from the children
var points = $(subtext).eq(0).text();
var username = $(subtext).eq(1).text();

var YCOMB_COMMENT_URL = "https://news.ycombinator.com/"
var comments = $(subtext).eq(2).text();
var comments_link = YCOMB_COMMENT_URL + $(subtext).eq(2).attr('href');

var metadata = { // creates a new object
rank: parseInt(rank),
title:title,
url:url,
points: parseInt(points),
username: username,
comments: parseInt(comments)
comments: parseInt(comments),
comments_link:comments_link
};
metadataArray.push(metadata); // pushes the object
});
Expand Down Expand Up @@ -67,9 +71,20 @@ function Lobster(callback){
var a=$(this); //selects previous data
var url=a.children().attr('href'); // parses href attribute from "a" element
var title=a.text(); // parses link title

// Note: There currently (2014-07-12) is no comments tag to be parsed
// available by scraping the Loste.rs webpage.
// This means 0 comments will have no link to the comment page.
var comments_label = a.parent().children('.byline').children('span.comments_label');
var comments_link = comments_label.children('a').attr("href");
var commentsMatch = comments_label.text().match("[0-9]+");
var comments = commentsMatch !== null ? commentsMatch[0] : 0;

var metadata = { // creates a new object
title:title,
url:url
url:url,
comments:comments,
comments_link:comments_link
};
metadataArray.push(metadata); // pushes the object
});
Expand Down Expand Up @@ -100,12 +115,18 @@ function RProg(callback){

var a=$(this);

var comments_tag = a.parent().parent().children('.flat-list').children('li.first').children('a');
var comments_link = comments_tag.attr("href");
var comments = parseInt(comments_tag.text());

var title=a.text();
var url=a.attr('href');

var metadata = {
title:title,
url:url
url:url,
comments:comments,
comments_link:comments_link
};

metadataArray.push(metadata);
Expand Down Expand Up @@ -143,15 +164,19 @@ function YCombNew(callback){
var subtext = a.parent().parent().next().children('.subtext').children(); // gets the subtext from the children
var points = $(subtext).eq(0).text();
var username = $(subtext).eq(1).text();

var YCOMB_COMMENT_URL = "https://news.ycombinator.com/"
var comments = $(subtext).eq(2).text();
var comments_link = YCOMB_COMMENT_URL + $(subtext).eq(2).attr('href');

var metadata = { // creates a new object
rank: parseInt(rank),
title:title,
url:url,
points: parseInt(points),
username: username,
comments: parseInt(comments)
comments: parseInt(comments),
comments_link:comments_link
};
metadataArray.push(metadata); // pushes the object
});
Expand Down Expand Up @@ -183,9 +208,21 @@ function LobsterNew(callback){
var a=$(this); //selects previous data
var url=a.children().attr('href'); // parses href attribute from "a" element
var title=a.text(); // parses link title

// Note: There currently (2014-07-12) is no comments tag to be parsed
// available by scraping the Loste.rs webpage.
// This means 0 comments will have no link to the comment page.
var comments_label = a.parent().children('.byline').children('span.comments_label');
var comments_link = comments_label.children('a').attr("href");
var commentsMatch = comments_label.text().match("[0-9]+");
var comments = commentsMatch !== null ? commentsMatch[0] : 0;

var metadata = { // creates a new object
title:title,
url:url
url:url,
comments:comments,
comments_link:comments_link

};
metadataArray.push(metadata); // pushes the object
});
Expand Down Expand Up @@ -219,9 +256,15 @@ function RProgNew(callback){
var title=a.text();
var url=a.attr('href');

var comments_tag = a.parent().parent().children('.flat-list').children('li.first').children('a');
var comments_link = comments_tag.attr("href");
var comments = parseInt(comments_tag.text());

var metadata = {
title:title,
url:url
url:url,
comments:comments,
comments_link:comments_link
};

metadataArray.push(metadata);
Expand Down
27 changes: 23 additions & 4 deletions public/helper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
function commentsTemplate(info){
if (!info.comments_link){
return "No Comments";
}

var numComments = info.comments || 0;

return '<a style="text-decoration:none" href="' + info.comments_link + '">'
+ numComments
+ ' Comments '
+ '</a>';
}

function postTemplate(info, site){
return $('<li id="post"><p><a href="' + info.url
+ ' "style="text-decoration:none" target="_blank">'
+ info.title +'</a> <sup>' + site + " - "
+ commentsTemplate(info)
+ "</sup> </p></li>");
}

function createPost(data, site){
for(var i = 0; i< 15; i++){
if(data[i].title=="scribd"){

}else{
$('<li id="post"><p><a href="' + data[i].url + ' "style="text-decoration:none" target="_blank">'
+ data[i].title +'</a> <sup>' + site + "</sup> </p></li>").appendTo('#helper');
postTemplate(data[i], site).appendTo('#helper');
}
}
}
Expand All @@ -14,8 +34,7 @@ function filteredPost(data, q, site){
var re = new RegExp(q, "i");
var treble = re.test(data[i].title);
if((treble == true) && (data[i].title!="scribd")){
$('<li id="post"><p><a href="' + data[i].url + ' "style="text-decoration:none" target="_blank">' + data[i].title + '</a><sup>' + site + '</sup></p></li>').appendTo('#helper');

postTemplate(data[i], site).appendTo('#helper');
}
}
}
Expand Down

0 comments on commit f2cb90c

Please sign in to comment.