Skip to content

Commit b456bee

Browse files
committed
The Great Lintening (#57)
(except quotes)
1 parent 4b8aa01 commit b456bee

File tree

6 files changed

+89
-85
lines changed

6 files changed

+89
-85
lines changed

source/js/background.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// vim: set ts=2 sw=2 et
1+
/* global onStorageChange, loadFromStorage, getCountersFromHTTP, openOurTab, onMessage, onExtensionUpdate, onNotificationClick, startupInject */
22
// synchronize settings
33
chrome.storage.onChanged.addListener(onStorageChange);
44
loadFromStorage();

source/js/functions.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// vim: set ts=2 sw=2 et
1+
/* globals saveToStorage, toggleContentMenus */
22
var BADGE_BACKGROUND_COLOR = '#d73f31';
33
var OPTIONS_VERSION = 3; // Increment when there are new options
44

@@ -45,6 +45,7 @@ function showNotification(title, body, id = "theoldreader") {
4545
}
4646
}
4747

48+
/* exported onNotificationClick */
4849
function onNotificationClick(id) {
4950
switch (id) {
5051
case "theoldreader":
@@ -58,8 +59,7 @@ function onNotificationClick(id) {
5859
}
5960

6061
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/');
6363
}
6464

6565
function findOurTab(callback, windowId) {
@@ -68,7 +68,7 @@ function findOurTab(callback, windowId) {
6868
url: "*://theoldreader.com/*",
6969
windowId: windowId
7070
},
71-
function (tabs) {
71+
function(tabs) {
7272
callback(tabs[0]);
7373
}
7474
);
@@ -92,8 +92,8 @@ function reportError(details) {
9292

9393
chrome.browserAction.setIcon({
9494
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'
9797
}
9898
});
9999

@@ -107,7 +107,7 @@ function reportError(details) {
107107
chrome.browserAction.setBadgeText({text: ''});
108108
chrome.browserAction.setTitle({title: chrome.i18n.getMessage('button_title_fetchError')});
109109
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);
111111
}
112112
}
113113

@@ -117,8 +117,8 @@ function reportError(details) {
117117
}
118118

119119
function updateIcon(count) {
120-
countInt = parseInt(count);
121-
title_suffix = ': ' + countInt + ' unread';
120+
let countInt = parseInt(count);
121+
let title_suffix = ': ' + countInt + ' unread';
122122
if (countInt === 0) {
123123
count = "";
124124
title_suffix = '';
@@ -129,8 +129,8 @@ function updateIcon(count) {
129129
}
130130
chrome.browserAction.setIcon({
131131
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'
134134
}
135135
});
136136
chrome.browserAction.setBadgeBackgroundColor({color: BADGE_BACKGROUND_COLOR});
@@ -172,16 +172,16 @@ function getCountersFromHTTP() {
172172
refreshFailed({errorText: 'HTTP request timed out'});
173173
}, 20000);
174174

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'});
177177
};
178178

179179
httpRequest.onreadystatechange = function() {
180180
if (httpRequest.readyState == 4 && httpRequest.status !== 0) { // (4,0) means onerror will be fired next
181181
if (httpRequest.status >= 400) {
182182
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)
185185
});
186186
} else if (httpRequest.responseText) {
187187
window.clearTimeout(requestTimeout);
@@ -209,13 +209,14 @@ function getCountersFromHTTP() {
209209
function scheduleRefresh() {
210210
var interval = (localStorage.refresh_interval || 15) * 60 * 1000;
211211
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));
214214
// 0:05 -> 0:10 -> 0:20 -> 0:40 -> 1:20 -> 2:40 -> 5:20 -> ...
215215
}
216216
refreshTimeout = window.setTimeout(getCountersFromHTTP, interval);
217217
}
218218

219+
/* exported onMessage */
219220
function onMessage(request, sender, callback) {
220221
if (typeof request.count !== 'undefined') {
221222
setCountFromObserver(request.count);
@@ -240,6 +241,7 @@ function setCountFromObserver(count) {
240241
scheduleRefresh();
241242
}
242243

244+
/* exported onExtensionUpdate */
243245
function onExtensionUpdate(details) {
244246
if (details.reason == "update" && localStorage.options_version < OPTIONS_VERSION) {
245247
showNotification(
@@ -252,13 +254,14 @@ function onExtensionUpdate(details) {
252254
saveToStorage();
253255
}
254256

257+
/* exported startupInject */
255258
function startupInject() {
256259
// At this point, all old content scripts, if any, cannot communicate with the extension anymore
257260
// Old instances of content scripts have a "kill-switch" to terminate their event listeners
258261
// Here we inject new instances in existing tabs
259262
chrome.tabs.query(
260263
{url: "*://theoldreader.com/*"},
261-
function (tabs) {
264+
function(tabs) {
262265
for (var i in tabs) {
263266
chrome.tabs.executeScript(tabs[i].id, {file: "js/observer.js"});
264267
}

source/js/menu.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* global baseUrl, getBrowserName */
12
function addContentMenus() {
23
chrome.contextMenus.create(
3-
{"title": "The Old Reader", id: "root", contexts: ["page"]}
4+
{title: "The Old Reader", id: "root", contexts: ["page"]}
45
);
5-
6+
67
var bookmark = function bookmark(base_url, url, selection) {
78
var f = document.createElement('form');
89
f.setAttribute('method','post');
@@ -27,11 +28,11 @@ function addContentMenus() {
2728
}.toString().replace(/(\n|\t)/gm,'');
2829

2930
chrome.contextMenus.create({
30-
"title": chrome.i18n.getMessage('contextMenu_subscribeToPage'),
31-
"id": "subscribe",
32-
"parentId": "root",
31+
title: chrome.i18n.getMessage('contextMenu_subscribeToPage'),
32+
id: "subscribe",
33+
parentId: "root",
3334
contexts: ["page"],
34-
"onclick": function(info, tab) {
35+
onclick: function(info, tab) {
3536
chrome.tabs.create({
3637
url: baseUrl() + "feeds/subscribe?url=" + encodeURIComponent(tab.url)
3738
});
@@ -42,44 +43,40 @@ function addContentMenus() {
4243
// Temporarily disabling those bookmaklet-like entries, will need a rewrite
4344
if (getBrowserName() == "Chrome") {
4445
chrome.contextMenus.create({
45-
"title": chrome.i18n.getMessage('contextMenu_bookmarkPage'),
46-
"id": "bookmarkPage",
47-
"parentId": "root",
46+
title: chrome.i18n.getMessage('contextMenu_bookmarkPage'),
47+
id: "bookmarkPage",
48+
parentId: "root",
4849
contexts: ["page"],
49-
"onclick": function(info, tab) {
50-
var args = "\""+baseUrl()+"bookmarks/bookmark\",\""+info.pageUrl+"\"";
50+
onclick: function(info) {
51+
var args = "\"" + baseUrl() + "bookmarks/bookmark\",\"" + info.pageUrl + "\"";
5152
chrome.tabs.create({
52-
url: "javascript:"+bookmark+";bookmark("+args+")"
53+
url: "javascript:" + bookmark + ";bookmark(" + args + ")"
5354
});
5455
}
5556
});
5657

5758
chrome.contextMenus.create({
58-
"title": chrome.i18n.getMessage('contextMenu_bookmarkSelection'),
59-
"id": "bookmarkSelection",
59+
title: chrome.i18n.getMessage('contextMenu_bookmarkSelection'),
60+
id: "bookmarkSelection",
6061
contexts: ["selection"],
61-
"onclick": function(info, tab) {
62-
var selection = info.selectionText.replace(/\"/gm, '\\"');
63-
var args = "\""+baseUrl()+"bookmarks/bookmark\",\""+info.pageUrl+"\", \""+selection+"\"";
62+
onclick: function(info) {
63+
var selection = info.selectionText.replace(/"/gm, '\\"');
64+
var args = "\"" + baseUrl() + "bookmarks/bookmark\",\"" + info.pageUrl + "\", \"" + selection + "\"";
6465
console.log(args);
6566
chrome.tabs.create({
66-
url: "javascript:"+bookmark+";bookmark("+args+")"
67+
url: "javascript:" + bookmark + ";bookmark(" + args + ")"
6768
});
6869
}
6970
});
7071
}
7172
}
7273

73-
var contextMenusEnabled = false;
74-
7574
function toggleContentMenus(state) {
76-
if(state == 'no') {
75+
if (state == 'no') {
7776
chrome.contextMenus.removeAll();
78-
contextMenusEnabled = false;
7977
} else {
8078
chrome.contextMenus.removeAll(function() {
8179
addContentMenus();
82-
contextMenusEnabled = true;
8380
});
8481
}
8582
}

source/js/observer.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
// vim: set ts=2 sw=2 et
22
// Credit for the solution goes to http://stackoverflow.com/a/11694229
33

4-
if(typeof(window.injected) == "undefined") { // Inject guard for #40
4+
if (typeof window.injected === "undefined") { // Inject guard for #40
55
window.injected = true;
66

77
var target = document.querySelector('head > title');
88

99
var observer = new window.MutationObserver(
1010
function(mutations) {
1111
mutations.forEach(
12-
function(mutation){
12+
function(mutation) {
1313
notify(mutation.target.textContent, true);
1414
}
1515
);
1616
}
1717
);
1818

1919
observer.observe(
20-
target,
21-
{
22-
subtree: true,
23-
characterData: true,
20+
target,
21+
{
22+
subtree: true,
23+
characterData: true,
2424
childList: true
2525
}
2626
);
@@ -29,15 +29,15 @@ if(typeof(window.injected) == "undefined") { // Inject guard for #40
2929

3030
// Declare extension capabilities to the page
3131
var capabilities = {
32-
openInBackground : true
32+
openInBackground: true
3333
};
3434

3535
exposeCapabilities(capabilities);
3636

3737
// Add an event listener for openPostInBackground
3838
window.addEventListener(
39-
"tor:openPostInBackground",
40-
openInBackgroundHandler,
39+
"tor:openPostInBackground",
40+
openInBackgroundHandler,
4141
false
4242
);
4343

@@ -57,7 +57,7 @@ function exposeCapabilities(capabilities) {
5757

5858
var script = document.createElement('script');
5959
script.textContent = code;
60-
(document.head||document.documentElement).appendChild(script);
60+
(document.head || document.documentElement).appendChild(script);
6161
script.parentNode.removeChild(script);
6262
}
6363

@@ -75,8 +75,8 @@ function notify(title, changed) {
7575

7676
if (count >= 0) {
7777
try {
78-
chrome.runtime.sendMessage({'count' : count});
79-
} catch(e) { // Happens when parent extension is no longer available or was reloaded
78+
chrome.runtime.sendMessage({count: count});
79+
} catch (e) { // Happens when parent extension is no longer available or was reloaded
8080
console.warn("Could not communicate with parent extension, deregistering observer");
8181
observer.disconnect();
8282
}

0 commit comments

Comments
 (0)