forked from hitode909/google-chrome-hatena-blog-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.coffee
86 lines (72 loc) · 2.55 KB
/
popup.coffee
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
HOST = 'http://tanpaku.grouptube.jp/'
entryList = []
getAntenna = (callback) ->
$.ajax
url: HOST
dataType: 'html'
success: (res) ->
$('#indicator').hide()
items = []
$(res).find('ul.information li').each ->
entry_titles = $(this).contents().filter(-> this.textContent.match(/\S/))
if /^(?:event|diary|file)\/user\/(.+?)\/.*/.test($(this).find('a + a').attr('href'))
user_name = $(this).find('a + a').attr('href')
.replace(/^(?:event|diary|file)\/user\/(.+?)\/.*/, "$1")
else
group_name = $(this).find('a + a').attr('href')
.replace(/.*group\/(\d+)\/.+$/, "$1")
if entry_titles.length > 0
entry_title = entry_titles[0].textContent
else
entry_title = '■'
items.push
blog_title: $(this).find('a + a').text()
entry_title: entry_title
entry_url: HOST + $(this).find('a + a').attr('href')
user_name: user_name
user_image: "#{HOST}images/users/#{user_name}/icon/s.jpg"
group_name: group_name
group_image: "#{HOST}images/groups/#{group_name}/s.jpg"
callback items.reverse()
getUnreadCount = ->
entryList.length
openEntry = (entry) ->
chrome.tabs.getSelected null, (tab) ->
return if tab.url == entry.entry_url
chrome.tabs.update tab.id, {url: entry.entry_url}
showEntry = (entry, unread_count) ->
openEntry(entry)
$('#title').text entry.entry_title
if entry.user_name?
$('#user_icon').empty()
.append $('<img>').attr(src: entry.user_image, title: entry.user_name)
$('#user_name').empty()
.append $('<a>').attr(href: "#{HOST}user/#{entry.user_name}").text(entry.user_name)
else
$('#user_icon').empty()
.append $('<img>').attr(src: entry.group_image, title: entry.group_name)
$('#user_name').empty().append $('<a>').attr(href: "#{HOST}group/#{entry.group_name}").text(entry.group_name)
$('#unread_count').text(unread_count)
hideButton = ->
$('#next-button').hide()
showEmptyMessage = ->
$('.small-info').hide()
$('#title').text('未読記事はありません')
showNextEntry = ->
chrome.extension.sendRequest {method: "getNextEntry"}, (res) ->
if res.entry
showEntry(res.entry, res.unread_count)
if res.unread_count == 0
hideButton()
if ! res.entry
showEmptyMessage()
$ ->
showNextEntry()
$('#next-button').click ->
showNextEntry()
false
$('#user_name a').live 'click', ->
chrome.tabs.create
url: $(this).attr('href')
window.close()
$('#next-button').focus()