1
- // vim: set ts=2 sw=2 et
1
+ /* globals saveToStorage, toggleContentMenus */
2
2
var BADGE_BACKGROUND_COLOR = '#d73f31' ;
3
3
var OPTIONS_VERSION = 3 ; // Increment when there are new options
4
4
@@ -45,6 +45,7 @@ function showNotification(title, body, id = "theoldreader") {
45
45
}
46
46
}
47
47
48
+ /* exported onNotificationClick */
48
49
function onNotificationClick ( id ) {
49
50
switch ( id ) {
50
51
case "theoldreader" :
@@ -58,8 +59,7 @@ function onNotificationClick(id) {
58
59
}
59
60
60
61
function baseUrl ( ) {
61
- return ( localStorage . force_http == 'yes' ?
62
- 'http://theoldreader.com/' : 'https://theoldreader.com/' ) ;
62
+ return ( localStorage . force_http == 'yes' ? 'http://theoldreader.com/' : 'https://theoldreader.com/' ) ;
63
63
}
64
64
65
65
function findOurTab ( callback , windowId ) {
@@ -68,7 +68,7 @@ function findOurTab(callback, windowId) {
68
68
url : "*://theoldreader.com/*" ,
69
69
windowId : windowId
70
70
} ,
71
- function ( tabs ) {
71
+ function ( tabs ) {
72
72
callback ( tabs [ 0 ] ) ;
73
73
}
74
74
) ;
@@ -92,8 +92,8 @@ function reportError(details) {
92
92
93
93
chrome . browserAction . setIcon ( {
94
94
path : {
95
- '19' : 'img/icon-inactive.png' ,
96
- '38' : 'img/icon-inactive-scale2.png'
95
+ 19 : 'img/icon-inactive.png' ,
96
+ 38 : 'img/icon-inactive-scale2.png'
97
97
}
98
98
} ) ;
99
99
@@ -107,7 +107,7 @@ function reportError(details) {
107
107
chrome . browserAction . setBadgeText ( { text : '' } ) ;
108
108
chrome . browserAction . setTitle ( { title : chrome . i18n . getMessage ( 'button_title_fetchError' ) } ) ;
109
109
if ( lastError != details . errorText ) { // Suppress repeat notifications about the same error
110
- showNotification ( chrome . i18n . getMessage ( 'notification_fetchError_title' ) , chrome . i18n . getMessage ( 'notification_fetchError_body' ) + details . errorText ) ;
110
+ showNotification ( chrome . i18n . getMessage ( 'notification_fetchError_title' ) , chrome . i18n . getMessage ( 'notification_fetchError_body' ) + details . errorText ) ;
111
111
}
112
112
}
113
113
@@ -117,8 +117,8 @@ function reportError(details) {
117
117
}
118
118
119
119
function updateIcon ( count ) {
120
- countInt = parseInt ( count ) ;
121
- title_suffix = ': ' + countInt + ' unread' ;
120
+ let countInt = parseInt ( count ) ;
121
+ let title_suffix = ': ' + countInt + ' unread' ;
122
122
if ( countInt === 0 ) {
123
123
count = "" ;
124
124
title_suffix = '' ;
@@ -129,8 +129,8 @@ function updateIcon(count) {
129
129
}
130
130
chrome . browserAction . setIcon ( {
131
131
path : {
132
- '19' : 'img/icon-active.png' ,
133
- '38' : 'img/icon-active-scale2.png'
132
+ 19 : 'img/icon-active.png' ,
133
+ 38 : 'img/icon-active-scale2.png'
134
134
}
135
135
} ) ;
136
136
chrome . browserAction . setBadgeBackgroundColor ( { color : BADGE_BACKGROUND_COLOR } ) ;
@@ -172,16 +172,16 @@ function getCountersFromHTTP() {
172
172
refreshFailed ( { errorText : 'HTTP request timed out' } ) ;
173
173
} , 20000 ) ;
174
174
175
- httpRequest . onerror = function ( err ) {
176
- refreshFailed ( { errorText : 'HTTP request error' } ) ; // No usable error data in err
175
+ httpRequest . onerror = function ( ) {
176
+ refreshFailed ( { errorText : 'HTTP request error' } ) ;
177
177
} ;
178
178
179
179
httpRequest . onreadystatechange = function ( ) {
180
180
if ( httpRequest . readyState == 4 && httpRequest . status !== 0 ) { // (4,0) means onerror will be fired next
181
181
if ( httpRequest . status >= 400 ) {
182
182
refreshFailed ( {
183
- errorText : 'Got HTTP error: ' + httpRequest . status + ' (' + httpRequest . statusText + ')' ,
184
- loggedOut : ( httpRequest . status == 403 || httpRequest . status == 401 )
183
+ errorText : 'Got HTTP error: ' + httpRequest . status + ' (' + httpRequest . statusText + ')' ,
184
+ loggedOut : ( httpRequest . status == 403 || httpRequest . status == 401 )
185
185
} ) ;
186
186
} else if ( httpRequest . responseText ) {
187
187
window . clearTimeout ( requestTimeout ) ;
@@ -209,13 +209,14 @@ function getCountersFromHTTP() {
209
209
function scheduleRefresh ( ) {
210
210
var interval = ( localStorage . refresh_interval || 15 ) * 60 * 1000 ;
211
211
window . clearTimeout ( refreshTimeout ) ;
212
- if ( retryCount ) { // There was an error
213
- interval = Math . min ( interval , 5 * 1000 * Math . pow ( 2 , retryCount - 1 ) ) ;
212
+ if ( retryCount ) { // There was an error
213
+ interval = Math . min ( interval , 5 * 1000 * Math . pow ( 2 , retryCount - 1 ) ) ;
214
214
// 0:05 -> 0:10 -> 0:20 -> 0:40 -> 1:20 -> 2:40 -> 5:20 -> ...
215
215
}
216
216
refreshTimeout = window . setTimeout ( getCountersFromHTTP , interval ) ;
217
217
}
218
218
219
+ /* exported onMessage */
219
220
function onMessage ( request , sender , callback ) {
220
221
if ( typeof request . count !== 'undefined' ) {
221
222
setCountFromObserver ( request . count ) ;
@@ -240,6 +241,7 @@ function setCountFromObserver(count) {
240
241
scheduleRefresh ( ) ;
241
242
}
242
243
244
+ /* exported onExtensionUpdate */
243
245
function onExtensionUpdate ( details ) {
244
246
if ( details . reason == "update" && localStorage . options_version < OPTIONS_VERSION ) {
245
247
showNotification (
@@ -252,13 +254,14 @@ function onExtensionUpdate(details) {
252
254
saveToStorage ( ) ;
253
255
}
254
256
257
+ /* exported startupInject */
255
258
function startupInject ( ) {
256
259
// At this point, all old content scripts, if any, cannot communicate with the extension anymore
257
260
// Old instances of content scripts have a "kill-switch" to terminate their event listeners
258
261
// Here we inject new instances in existing tabs
259
262
chrome . tabs . query (
260
263
{ url : "*://theoldreader.com/*" } ,
261
- function ( tabs ) {
264
+ function ( tabs ) {
262
265
for ( var i in tabs ) {
263
266
chrome . tabs . executeScript ( tabs [ i ] . id , { file : "js/observer.js" } ) ;
264
267
}
0 commit comments