-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiffs
350 lines (320 loc) · 9.9 KB
/
diffs
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
Index: youtube.js
===================================================================
--- youtube.js (revision 2)
+++ youtube.js (working copy)
@@ -38,6 +38,7 @@
'video_liked': localStorage['video_rated'],
'video_commented': localStorage['video_commented']
};
+ this.numNewItems_ = 0;
};
@@ -60,6 +61,13 @@
/**
+ * A list of all feed items.
+ * @type {Array.<Object>}
+ */
+YouTube.prototype.feedItems_;
+
+
+/**
* The id of the interval used for polling.
* @type {number}
*/
@@ -74,6 +82,20 @@
/**
+ * Personalized user configs.
+ * @type {Object}
+ */
+YouTube.prototype.options_;
+
+
+/**
+ * The number of items since the last time the user accessed the extension.
+ * @type {number}
+ */
+YouTube.prototype.numNewItems_;
+
+
+/**
* The API key for YouTube requests.
* @type {String}
*/
@@ -123,6 +145,13 @@
/**
+ * Feature parameter for the extension. Used for analytics.
+ * @type {string}
+ */
+YouTube.FEATURE_YOUTUBE_FEED_CHROME_EXTENSION = 'ytfce';
+
+
+/**
* The prefix URL for a user's channel.
* @type {string}
*/
@@ -183,16 +212,20 @@
* Supported event types.
* @type {Array.<String>}
*/
-YouTube.SUPPORTED_EVENT_TYPES = ['video_uploaded', 'video_favorited',
- 'video_rated', 'video_liked',
- 'video_commented'];
+YouTube.SUPPORTED_EVENT_TYPES = [
+ 'video_uploaded',
+ 'video_favorited',
+ 'video_rated',
+ 'video_liked',
+ 'video_commented'
+];
/**
* Initializes a YouTube object.
*/
YouTube.prototype.initialize = function() {
- this.setVisualState_();
+ this.setVisualState();
chrome.tabs.onRemoved.addListener(Util.bind(this.onTabRemoved_, this));
};
@@ -219,7 +252,7 @@
*/
YouTube.prototype.logout = function() {
this.oauth_.clearTokens();
- this.setVisualState_();
+ this.setVisualState();
};
@@ -238,6 +271,14 @@
/**
+ * Resets the number of new items.
+ */
+YouTube.prototype.resetNumNewItems = function() {
+ this.numNewItems_ = 0;
+};
+
+
+/**
* Marks the feed item as removed and removes it from the feed array and map.
* @param {string} feedItemId The id of the feed item whose video will be
* played.
@@ -249,7 +290,6 @@
mapEntry['removed'] = true;
delete mapEntry['item']; // No need to keep the item anymore.
localStorage['rm-' + feedItemId] = 'true'; // Persist in localStorage.
- this.setVisualState_();
}
};
@@ -283,7 +323,7 @@
try {
if (this.shouldShowFeedItem_(this.feedItems_[i], this.options_)) {
var child = this.buildFeedItemElement_(feedEntryTemplate,
- this.feedItems_[i]);
+ this.feedItems_[i]);
if (child) {
div.appendChild(child);
++count;
@@ -363,7 +403,7 @@
videoInfo['author'][0]['name']['$t'];
// Prepare the content for the basic DOM for the feed entry.
- var userChannelUrl = YouTube.CHANNEL_PREFIX_URL + username;
+ var userChannelUrl = Util.channelUrl(username);
var feedEntryTitle = chrome.i18n.getMessage('eventType_' + eventType,
[userChannelUrl, username]);
@@ -380,10 +420,9 @@
if (videoInfo) {
// Prepare the content for the video info for the feed entry.
- var videoUrl = YouTube.WATCH_VIDEO_PREFIX_URL + videoId;
- var videoAuthorChannelUrl = YouTube.CHANNEL_PREFIX_URL + videoAuthorUsername;
- var videoThumbnailSrc = YouTube.VIDEO_THUMBNAIL_PREFIX_URL + videoId +
- '/default.jpg';
+ var videoUrl = Util.videoWatchUrl(videoId);
+ var videoAuthorChannelUrl = Util.channelUrl(videoAuthorUsername);
+ var videoThumbnailSrc = Util.thumbnailUrl(videoId);
var formattedViewCount = Util.formatViewCount(videoViewCount);
var viewCountText = chrome.i18n.getMessage('viewCount',
[formattedViewCount]);
@@ -421,7 +460,7 @@
* Sets the objects visual state.
* @return
*/
-YouTube.prototype.setVisualState_ = function() {
+YouTube.prototype.setVisualState = function() {
this.setIcon_();
this.setBadgeText_();
};
@@ -431,7 +470,7 @@
* Executed when a user has been authorized.
*/
YouTube.prototype.onAuthorized_ = function() {
- this.setVisualState_();
+ this.setVisualState();
this.getTheFeed_();
};
@@ -488,6 +527,7 @@
'item': feedItem,
'removed': false
};
+ ++this.numNewItems_;
}
}
this.sortItems_();
@@ -497,19 +537,6 @@
/**
- * Executed when the video metadata has been received from the GData server.
- * @param {Object} feedItem The feed item for which the video metadata is
- * retrieved.
- * @param {string} text The parsed text from the xhr.
- * @param {XmlHttpRequest} xhr The XmlHttpRequest that finished executing.
- */
-YouTube.prototype.onVideoMetadataReceived_ = function(feedItem, text, xhr) {
- var data = JSON.parse(text);
- feedItem['videoInfo'] = data['entry'];
-};
-
-
-/**
* Sets the proper icon based on the state of the system.
*/
YouTube.prototype.setIcon_ = function() {
@@ -525,16 +552,8 @@
* Sets the proper badge text based on the state of the system.
*/
YouTube.prototype.setBadgeText_ = function() {
- if (this.oauth_.hasToken() && !!this.feedItems_.length) {
- var count = 0;
- for (var i = 0; i < this.feedItems_.length; ++i) {
- if (this.shouldShowFeedItem_(this.feedItems_[i], this.options_)) {
- ++count;
- } else {
- }
- }
- count = Math.min(count, this.options_['numFeedItems']);
- chrome.browserAction.setBadgeText({'text': '' + count});
+ if (this.oauth_.hasToken() && this.numNewItems_ > 0) {
+ chrome.browserAction.setBadgeText({'text': '' + this.numNewItems_});
} else {
chrome.browserAction.setBadgeText({'text': ''});
}
@@ -845,3 +864,35 @@
}
return result;
};
+
+
+/**
+ * Builds a video watch url given a video id.
+ * @param {string} videoId The id of the video.
+ * @return {string} The watch url for the video.
+ */
+Util.videoWatchUrl = function(videoId) {
+ return YouTube.WATCH_VIDEO_PREFIX_URL + videoId + '&feature=' +
+ YouTube.FEATURE_YOUTUBE_FEED_CHROME_EXTENSION;
+};
+
+
+/**
+ * Builds a channel url given a username.
+ * @param {string} username The username for the channel.
+ * @return {string} The channel url for that user's channel.
+ */
+Util.channelUrl = function(username) {
+ return YouTube.CHANNEL_PREFIX_URL + username + '&feature=' +
+ YouTube.FEATURE_YOUTUBE_FEED_CHROME_EXTENSION;
+};
+
+
+/**
+ * Builds a thumbnail url given a video.
+ * @param {string} videoId The id of the video.
+ * @return {string} The thumbnail url for the video.
+ */
+Util.thumbnailUrl = function(videoId) {
+ return YouTube.VIDEO_THUMBNAIL_PREFIX_URL + videoId + '/default.jpg';
+};
Index: feeds.html
===================================================================
--- feeds.html (revision 2)
+++ feeds.html (working copy)
@@ -97,6 +97,7 @@
needLoginDiv.appendChild(needLoginH2);
feedDom.innerHTML = needLoginDiv.innerHTML;
}
+ youtube.resetNumNewItems();
}
</script>
</head>
Index: img/icon16.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/icon16.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: img/icon-off.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: img/icon-on.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: img/icon128.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/icon128.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: img/icon48.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/icon48.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: img/options-logo-big.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/options-logo-big.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: manifest.json
===================================================================
--- manifest.json (revision 2)
+++ manifest.json (working copy)
@@ -1,15 +1,20 @@
{
"name": "__MSG_extName__",
- "version": "1.3.1",
+ "version": "1.3.2",
"description": "__MSG_extDescription__",
"default_locale": "en",
"background_page": "background.html",
"options_page": "options.html",
"browser_action": {
- "default_icon": "img/icon-off.png",
+ "default_icon": "img/icon16.png",
"default_title": "__MSG_extTitle__",
"popup": "feeds.html"
},
+ "icons": {
+ "16": "icon16.png",
+ "48": "icon48.png",
+ "128": "icon128.png"
+ },
"permissions": [
"tabs",
"http://gdata.youtube.com/",
Index: options.html
===================================================================
--- options.html (revision 2)
+++ options.html (working copy)
@@ -144,6 +144,7 @@
</head>
<body onload='initialize()'>
<div class="main">
+ <img src="img/options-logo-big.png"/>
<div id='message' style='display: none;'></div>
<div id='options'>
<div id='option_polling_interval' class='optionDiv'>