-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
36 lines (33 loc) · 1.2 KB
/
main.js
File metadata and controls
36 lines (33 loc) · 1.2 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
source = null;
extract_text = function(html) {
text = $('<div>' + html + '</div>').text();
if (text.length > 100)
text = text.substring(0, 96) + '...';
return text;
}
on_start_stop_click = function() {
if (source == null) {
source = new EventSource("http://forcefeed.ir/sse");
source.onopen = function() {
$('#status-label').html('اتصال برقرار شد.');
}
source.addEventListener('post', function(e) {
post = JSON.parse(e.data);
newdiv = '<div class="js-example-message">' +
'عنوان: ' +
'<a href="' + post['link'] + '">' + extract_text(post['title']) + '</a><br>' +
'شرح: ' +
extract_text(post['description']) +
'</div>';
$('#feed-stream-container').append(newdiv)
});
$('#start-stop-button').attr('value', 'توقف');
$('#status-label').html('برقراری اتصال...');
$('#feed-stream-container').html('');
} else {
$('#start-stop-button').attr('value', 'آغاز');
$('#status-label').html('توقف');
source.close();
source = null;
}
}