-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonfeed.js
More file actions
124 lines (114 loc) · 5.87 KB
/
jsonfeed.js
File metadata and controls
124 lines (114 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// 1-1
var nytimes = new Array('nytimes', 'news', 10, 'http://www.nytimes.com', 'NYTimes.com');
var reddit = new Array('reddit', "news", 10, 'https://www.reddit.com/', 'Reddit.com');
var reddittop = new Array('reddittop', 'news', 8, 'https://www.reddit.com/top', 'Reddit.com/r/top');
var redditworld = new Array('redditworld', 'news', 8, 'http://www.reddit.com/r/worldnews/', 'Reddit.com/r/worldnews');
var reddittech = new Array('reddittech', 'news', 8, 'http://www.reddit.com/r/technology/', 'Reddit.com/r/tech');
// 1-2
var redditprogramming = new Array('redditprogramming', 'code', 10, 'http://www.reddit.com/r/programming/', 'Reddit.com/r/programming');
var redditwebdev = new Array('redditwebdev', 'code', 10, 'http://www.reddit.com/r/developer/', 'Reddit.com/r/developer');
var hackernews = new Array('hackernews', 'code', 10, 'https://hacker-news.firebaseio.com/v0/topstories', 'https://hacker-news.firebaseio.com/v0/item/', 'http://news.ycombinator.com/', 'Hacker News');
var redditcoding = new Array('redditcoding', 'code', 10, 'http://www.reddit.com/r/coding/', 'Reddit.com/r/coding');
// 1-3
var redditscience = new Array('redditscience', 'science', 6, 'http://www.reddit.com/r/science/', 'Reddit.com/r/science');
var newscientist = new Array('newscientist', 'science', 6, 'http://www.reddit.com/r/developer/', 'NewScientist.com');
// 2-1
var learncode = new Array('learncode', 'learn', '', '');
var learncodegames = new Array('learncodegames', 'learn', '', '');
var learndatascience = new Array('learndatascience', 'learn', '', '');
var learnlanguages = new Array('learnlanguages', 'learn', '', '');
var learnjobs = new Array('learnjobs', 'learn', '', '');
// 2-2
var indeed1 = new Array('indeed1', 'jobs', '', '');
var indeed2 = new Array('indeed2', 'jobs', '', '');
// 2-3
var redditpics = new Array('redditpics', 'entertain', 12, 'http://www.reddit.com/r/pics/', 'Reddit.com/r/pics');
var reddittil = new Array('reddittil', 'entertain', 8, 'http://www.reddit.com/r/todayilearned/', 'Reddit.com/r/todayilearned');
var redditask = new Array('redditask', 'entertain', 10, 'http://www.reddit.com/r/askreddit/', 'Reddit.com/r/askreddit');
var redditvideos = new Array('redditvideos', 'entertain', 10, 'http://www.reddit.com/r/videos/', 'Reddit.com/r/videos');
// 2-4
//var intp = new Array('intp', 'mbti', 10, 'http://www.reddit.com/r/intp/');
//var entp = new Array('entp', 'mbti', 10, 'http://www.reddit.com/r/entp/');
//
$('ul.tabs li').click(function() {
var tab_id = $(this).attr('data-tab');
tab_id = window[tab_id];
$('ul.' +tab_id[1]+ ' li').removeClass('current');
$(this).addClass('current');
if (tab_id[1] == "learn") {
$('.learntab').removeClass('current');
$("."+tab_id[0]).addClass('current');
}
else if (tab_id[1] == "jobs") {
$('.jobtab').removeClass('current');
$("."+tab_id[0]).addClass('current');
}
else if (tab_id[0] == "nytimes"){
myGetNYTimes(tab_id);
}
else {
myGetJSON(tab_id);
}
});
function myGetJSON(sourceArray) {
if(sourceArray[0]=='hackernews') {
var j = 1;
$.getJSON(
sourceArray[3] + ".json?", //"limitToFirst=" +sourceArray[2],
function parseJSON(data) {
$("." +sourceArray[1]+ "content").empty();
$.each(data.slice(0, sourceArray[2]), function (i, post) {
hackerAppend(sourceArray, post, j);
j += 1;
});
}
);
}
else {
$.getJSON(
sourceArray[3] + ".json?limitToFirst=5", //jsonp=?
function parseJSON(data) {
//console.log("getting");
$("." +sourceArray[1]+ "content").empty();
$.each(data.data.children.slice(0, sourceArray[2]), function (i, post) {
$("." +sourceArray[1]+ "content").append("<a href='" +post.data.permalink+ "' rel='nofollow'><img src='http://www.jimmyr.com/cm.gif' border='0'></a> <a href='" +post.data.url+ "' rel='nofollow' class='bl'>" +post.data.title+ "</a><br>");
$("." +sourceArray[1]+ "content").append("<div class='divider'></div>");
});
$("." +sourceArray[1]+ "content").append("<div class='source'> More at <a href='" +sourceArray[3]+ "' rel='nofollow' class='asource'>" +sourceArray[4]+ "</a></div>");
}
);
}
}
function hackerAppend(sourceArray, post, j) {
$.getJSON(sourceArray[4] +post+ ".json?", function parseJSON(data) {
$("." +sourceArray[1]+ "content").append("<a href='https://news.ycombinator.com/item?id=" +data.id+ "' rel='nofollow'><img src='http://www.jimmyr.com/cm.gif' border='0'></a> <a href='" +data.url+ "' rel='nofollow' class='bl'>" +data.title+ "</a><br>");
$("." +sourceArray[1]+ "content").append("<div class='divider'></div>");
if (j == sourceArray[2]) {
$("." +sourceArray[1]+ "content").append("<div class='source'> More at <a href='" +sourceArray[4]+ "' rel='nofollow' class='asource'>" +sourceArray[5]+ "</a></div>");
}
});
}
function myGetNYTimes(sourceArray) {
var url = "https://api.nytimes.com/svc/topstories/v2/home.json";
url += '?' + $.param({
'api-key': "3e6e052bf4bc4dc69a4d2236ecf8b89c",
'limitToFirst': 2
});
$.ajax({
url: url,
method: 'GET',
})
.done(function(result) {
$("." +sourceArray[1]+ "content").empty();
for (var i = 0; i < sourceArray[2]; i++) {
//console.log(result["results"][i]["title"]);
$("." +sourceArray[1]+ "content").append("<a href='https://news.ycombinator.com/item?id=" +result["results"][i]["url"]+ "' rel='nofollow'><img src='http://www.jimmyr.com/cm.gif' border='0'></a> <a href='" +result["results"][i]["url"]+ "' rel='nofollow' class='bl'>" +result["results"][i]["title"]+ "</a><br>");
$("." +sourceArray[1]+ "content").append("<div class='divider'></div>");
}
$("." +sourceArray[1]+ "content").append("<div class='source'> More at <a href='" +sourceArray[2]+ "' rel='nofollow' class='asource'>" +sourceArray[3]+ "</a></div>");
})
.fail(function(err) {
throw err;
});
}
//ATF 2016-2018