forked from hitode909/google-chrome-hatena-blog-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
125 lines (114 loc) · 3.58 KB
/
popup.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
117
118
119
120
121
122
123
124
125
// Generated by CoffeeScript 1.3.3
(function() {
var HOST, entryList, getAntenna, getUnreadCount, hideButton, openEntry, showEmptyMessage, showEntry, showNextEntry;
HOST = 'http://tanpaku.grouptube.jp/';
entryList = [];
getAntenna = function(callback) {
return $.ajax({
url: HOST,
dataType: 'html',
success: function(res) {
var items;
$('#indicator').hide();
items = [];
$(res).find('ul.information li').each(function() {
var entry_title, entry_titles, group_name, user_name;
entry_titles = $(this).contents().filter(function() {
return 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 = '■';
}
return 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"
});
});
return callback(items.reverse());
}
});
};
getUnreadCount = function() {
return entryList.length;
};
openEntry = function(entry) {
return chrome.tabs.getSelected(null, function(tab) {
if (tab.url === entry.entry_url) {
return;
}
return chrome.tabs.update(tab.id, {
url: entry.entry_url
});
});
};
showEntry = function(entry, unread_count) {
openEntry(entry);
$('#title').text(entry.entry_title);
if (entry.user_name != null) {
$('#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));
}
return $('#unread_count').text(unread_count);
};
hideButton = function() {
return $('#next-button').hide();
};
showEmptyMessage = function() {
$('.small-info').hide();
return $('#title').text('未読記事はありません');
};
showNextEntry = function() {
return chrome.extension.sendRequest({
method: "getNextEntry"
}, function(res) {
if (res.entry) {
showEntry(res.entry, res.unread_count);
}
if (res.unread_count === 0) {
hideButton();
}
if (!res.entry) {
return showEmptyMessage();
}
});
};
$(function() {
showNextEntry();
$('#next-button').click(function() {
showNextEntry();
return false;
});
$('#user_name a').live('click', function() {
chrome.tabs.create({
url: $(this).attr('href')
});
return window.close();
});
return $('#next-button').focus();
});
}).call(this);