-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopup.js
More file actions
193 lines (174 loc) · 6.92 KB
/
Copy pathpopup.js
File metadata and controls
193 lines (174 loc) · 6.92 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
var bkg = chrome.extension.getBackgroundPage();
var current = 'HackerNews';
function reloadTab() {
chrome.extension.sendMessage({requestTab: true} , function(response) {
if (response.currentTab == 'HackerNews') {
getHackerNews();
} else if (response.currentTab == 'Reddit') {
getReddit();
} else if (response.currentTab == 'ReadingList') {
getBookmarks();
}
});
}
function setShortMessage(message) {
$('#messagebox').text(message);
$('#messagebox').finish().show().fadeOut(4500);
}
function getHackerNews(reload) {
chrome.extension.sendMessage({timeSinceUpdate: true, site: 'hackernews', reload: reload} , function(response) {
if (response.needsUpdate) {
$('#messagebox').finish().show().text('Loading Hacker News...');
}
chrome.extension.sendMessage({tabRequest: 'hackernews'}, function(response) {
$('#messagebox').hide()
$('ul').addClass('hide-list');
$('#hacker-news-column').removeClass('hide-list');
$('#hacker-news-column').html(response.html);
$('#hacker-news-column > ul > li > a.site-link').each(function(index, link) {
$(link).siblings().each(function(index, sibling) {
$(sibling).height($(link).height());
});
});
$('#hacker-news-column a').click(function(){
chrome.tabs.create({url: $(this).attr('href')});
return false;
});
$('#hacker-news-column a').hover(function(){$(this).addClass('highlight-link');}, function(){$(this).removeClass('highlight-link');});
$('#hacker-news-column .add-bookmark').hover(function(){$(this).addClass('highlight-link');}, function(){$(this).removeClass('highlight-link');});
$('#hacker-news-column .add-bookmark').click(addBookmark);
$('#tab-title').text('Hacker News');
current = 'HackerNews';
});
});
}
function getReddit(reload) {
chrome.extension.sendMessage({timeSinceUpdate: true, site: 'reddit', reload: reload} , function(response) {
if (response.needsUpdate) {
$('#messagebox').finish().show().text('Loading Reddit Programming News...');
}
chrome.extension.sendMessage({tabRequest: 'reddit'}, function(response) {
$('#messagebox').hide()
$('ul').addClass('hide-list');
$('#reddit-column').removeClass('hide-list');
$('#reddit-column').html(response.html);
$('#reddit-column > ul > li > a.site-link').each(function(index, link) {
$(link).siblings().each(function(index, sibling) {
$(sibling).height($(link).height());
});
});
$('#reddit-column a').click(function(){
chrome.tabs.create({url: $(this).attr('href')});
return false;
});
$('#reddit-column a').hover(function(){$(this).addClass('highlight-link');}, function(){$(this).removeClass('highlight-link');});
$('#reddit-column .add-bookmark').hover(function(){$(this).addClass('highlight-link');}, function(){$(this).removeClass('highlight-link');});
$('#reddit-column .add-bookmark').click(addBookmark);
$('#tab-title').text('r/programming');
current = 'Reddit';
});
});
}
function reload() {
if (current == 'HackerNews') {
getHackerNews(true);
} else if (current == 'Reddit') {
getReddit(true);
}
}
function getBookmarks() {
chrome.extension.sendMessage({bookmarkAction : 'getBookmarks'}, function(response) {
$('ul').addClass('hide-list');
$('#bookmarks-column').removeClass('hide-list');
$('#bookmarks-column').html(response.html);
$('#bookmarks-column > ul > li > a.site-link').each(function(index, link) {
$(link).siblings().each(function(index, sibling) {
$(sibling).height($(link).height());
});
});
$('#bookmarks-column a').click(function(){
chrome.tabs.create({url: $(this).attr('href')});
return false;
});
$('#bookmarks-column a').hover(function(){$(this).addClass('highlight-link');}, function(){$(this).removeClass('highlight-link');});
$('#bookmarks-column .delete-bookmark').click(deleteBookmark);
$('#bookmarks-column .delete-bookmark').hover(function(){$(this).addClass('highlight-link');}, function(){$(this).removeClass('highlight-link');});
$('#delete-all-bookmarks').click(showDeleteAllBookmarks);
$('#tab-title').text('Reading List');
current = 'ReadingList';
});
}
function addBookmark() {
var bookmark = {
'site' : $(this).siblings().eq(0).text(),
'siteLink' : $(this).siblings().eq(0).attr('href'),
'comments' : $(this).siblings().eq(1).text(),
'commentsLink' : $(this).siblings().eq(1).attr('href')
}
chrome.extension.sendMessage({bookmarkAction : 'addBookmark', bookmark: bookmark}, function(response) {
//need the bookmark name
if (response.result == 'added') {
setShortMessage('"' + bookmark.site + '" has been added to your reading list.');
} else if (response.result == 'moved') {
setShortMessage('"' + bookmark.site + '" is already in your reading list. It has been moved to the top.');
} else if (response.result == 'addAndPop') {
setShortMessage('Your reading list is larger than 100 items. "' + bookmark.site + '"has been added and the last item removed.');
}
});
}
function deleteBookmark() {
var site = $(this).siblings().eq(0).text();
chrome.extension.sendMessage({bookmarkAction : 'deleteBookmark', index: $(this).attr('data-index')}, function(response) {
if (response.deleted) {
getBookmarks();
setShortMessage('"' + site + '" has been removed from your reading list.');
}
});
}
function deleteAllBookmarks() {
chrome.extension.sendMessage({bookmarkAction : 'deleteAllBookmarks'}, function(response) {
$('#okbox').hide();
if (response.deletedAll) {
getBookmarks();
setShortMessage('All items in your reading list have been removed.');
}
});
}
function showDeleteAllBookmarks() {
$('#okbox').show();
}
$('#okbox-cancel').click(function(){$('#okbox').hide();});
$('#okbox-delete-all').click(deleteAllBookmarks);
reloadTab();
$('#hacker-news-logo').click(function(){getHackerNews(false);});
$('#reddit-logo').click(function(){getReddit(false);});
$('#reading-list-logo').click(getBookmarks);
$('#reload-icon').click(reload);
$('#hacker-news-logo').hover(function(e) {
$('#cursor-popup').css({
'top' : 50,
'left' : 10
});
$('#cursor-popup').show().text('Hacker News');
}, function(e) {
$('#cursor-popup').hide();
});
$('#reddit-logo').hover(function(e) {
$('#cursor-popup').css({
'top' : 50,
'left' : 50
});
$('#cursor-popup').show().text('/r/programming');
}, function(e) {
$('#cursor-popup').hide();
});
$('#reload-icon').hover(function(e) { $('#cursor-popup').css({'top' : 50,'left' : 355}); $('#cursor-popup').show().text('Reload');}, function(e) { $('#cursor-popup').hide();});
$('#reading-list-logo').hover(function(e) {
$('#cursor-popup').css({
'top' : 50,
'left' : 330
});
$('#cursor-popup').show().text('Reading List');
}, function(e) {
$('#cursor-popup').hide();
});