This repository has been archived by the owner on Aug 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.js
116 lines (95 loc) · 3.19 KB
/
post.js
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
var ACCESS_TOKEN = localStorage.getItem('accessToken');
var Snoocore = window.Snoocore;
var hash = window.location.hash;
var reddit = new Snoocore({
userAgent: '',
throttle: 1000,
oauth: {
type: 'implicit',
consumerKey: 'wtf',
redirectUri: 'wtf',
scope: [ 'read', 'submit' ]
}
});
if (document.location.href.split('?').length < 2) {
document.location = '/'
}
var postId = document.location.href.split('?')[1]
$(function() {
reddit.auth(ACCESS_TOKEN).then(function() {
return reddit('/r/hummhumm/comments/'+postId).get()
}).then(function(data) {
var post = data[0].data.children[0].data
var comments = data[1].data.children
var html = '<a href="https://www.reddit.com/r/' + post.subreddit + '/comments/' + postId + '/fuck_your_wrong_console_code/">View Post on /r/HummHumm</a>';
$('#audio').html('<audio controls autoplay preload><source src="' + post.url.replace("player", "sounds") + '" type="audio/wav"></audio>')
for (var i = 0, l = comments.length; i < l; i++) {
var c = comments[i].data;
var youtubeId;
if (c.replies !== '') {
var comments2 = c.replies.data.children;
for (var j = 0, k = comments2.length; j < k; j++) {
var cc = comments2[j];
if (cc.data.author === "humm_youtube") {
youtubeId = cc.data.body.match(/\[(.*)\]\((.*)\)/)[2].match(/watch\?v=(.*)/)[1];
}
}
}
var decoded = $("<div/>").html(c.body_html).text();
var scores =
'<div class="score">' +
'<div class="up"></div>' +
'<p>' + (c.ups - c.downs) + '</p>' +
'<div class="down"></div>' +
'</div>';
html +=
'<div class="post">' +
scores +
'<div id="post-body">' +
'<div class="body">' +
decoded +
'</div>';
if (typeof youtubeId !== 'undefined') {
html += '<iframe width="420" height="345" src="http://www.youtube.com/embed/' + youtubeId + '"></iframe>';
}
html += '<div class="footer">' +
'<small>' +
'<a href="https://www.reddit.com/user/' + c.author + '">' +
c.author +
'</a>' +
' · ' +
'<a href="https://www.reddit.com/r/' + c.subreddit + '/comments/' + postId + '/fuck_your_wrong_console_code/' + c.id + '" title="view/post replies">' +
moment(new Date(c.created_utc * 1000)).fromNow() +
'</a>' +
'<small/>' +
'</div>' +
'</div>' +
'</div>';
}
if (comments.length === 0) {
html += '<div class="post"><p><em>There is no answer yet.</em></p></div>'
}
html += '<div class="post">' +
'<h3>Do you know this song?</h3>' +
'<input type="text" name="artist" id="input-artist" placeholder="Artist"><br>' +
'<input type="text" name="title" id="input-title" placeholder="Title">'+
'<button id="post-comment">Send answer</button>'+
'</div>';
$('#comments').html(html);
$(document).on('click', '#post-comment', function (e) {
var artist = $('#input-artist').val()
var title = $('#input-title').val()
var params = {
api_type: "json",
text: artist + ' - ' + title,
thing_id: post.name
}
reddit.auth(ACCESS_TOKEN).then(function() {
return reddit('/api/comment').post(params)
}).then(function(data) {
console.log(data);
document.location = document.location;
});
})
});
})