Skip to content

Commit 71e01c1

Browse files
committed
Fixed style issues
1 parent cda383b commit 71e01c1

3 files changed

Lines changed: 75 additions & 76 deletions

File tree

context-menu.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
const CONTEXT_HASH = {
1+
var CONTEXT_HASH = {
22
"google-cache": "http://webcache.googleusercontent.com/search?q=cache:",
33
"wayback-machine": "http://web.archive.org/web/*/",
44
"coral-cdn": ".nyud.net"
55
};
66

77
function formUrl(context, url) {
8-
contextUrl = CONTEXT_HASH[context];
9-
isHTTPS = url.substring(0, 6) == 'https:';
8+
var contextUrl = CONTEXT_HASH[context];
9+
var isHTTPS = url.substring(0, 6) === "https:";
1010

1111
// Google and Wayback Machine
12-
if(context != 'coral-cdn') {
13-
return contextUrl + (isHTTPS ? url.substr(8) : url.substr(7))
12+
if(context !== "coral-cdn") {
13+
return contextUrl + (isHTTPS ? url.substr(8) : url.substr(7));
1414
} else { // Coral CDN
15-
if(url.slice(-1) == '/') {
16-
return url.substring(0, url.length -1) + contextUrl;
15+
if(url.slice(-1) === "/") {
16+
return url.substring(0, url.length - 1) + contextUrl;
1717
} else {
1818
return url + contextUrl;
1919
}
2020
}
2121
}
2222

2323
function redirectToCachedUrl(info, tab) {
24-
console.log('meow');
2524
chrome.tabs.update(tab.id, { url: formUrl(info.menuItemId, info.pageUrl) });
2625
}
2726

@@ -30,8 +29,8 @@ function createContextMenu(cache) {
3029
var saveObj = {};
3130
var create_properties = {
3231
id: cache,
33-
title: 'Open page with ' + cache.split('-').join(' '),
34-
contexts: ['page']
32+
title: "Open page with " + cache.split("-").join(" "),
33+
contexts: ["page"]
3534
};
3635
saveObj[cache] = true;
3736

options.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
const CONTEXT_MENU_CACHES = [
1+
var CONTEXT_MENU_CACHES = [
22
"google-cache",
33
"wayback-machine",
44
"coral-cdn"
55
];
66

7-
// Add/Remove context menu caches
8-
function updateContextMenuCaches(event) {
9-
var cache = $(event.target).attr('for');
10-
var add_context_menu = !$('#' + cache).is(':checked');
11-
add_context_menu ? createContextMenu(cache) : removeContextMenu(cache);
12-
}
13-
147
// Remove context menu caches
158
function removeContextMenu(cache) {
169
var saveObj = {};
@@ -24,65 +17,72 @@ function createContextMenu(cache) {
2417
var saveObj = {};
2518
var create_properties = {
2619
id: cache,
27-
title: 'Open page with ' + cache.split('-').join(' '), //$("label[for='"+ cache +"']").text()
28-
contexts: ['page']
20+
title: "Open page with " + cache.split("-").join(" "), //$("label[for=""+ cache +""]").text()
21+
contexts: ["page"]
2922
};
3023
saveObj[cache] = true;
3124

3225
chrome.contextMenus.create(create_properties);
3326
chrome.storage.sync.set(saveObj);
3427
}
3528

29+
// Add/Remove context menu caches
30+
function updateContextMenuCaches(event) {
31+
var cache = $(event.target).attr("for");
32+
var add_context_menu = !$("#" + cache).is(":checked");
33+
add_context_menu ? createContextMenu(cache) : removeContextMenu(cache);
34+
}
35+
3636
var order = [];
37-
$('#sortable').sortable({
37+
$("#sortable").sortable({
3838
stop: function(event, ui) { // Save settings after change
39-
order.splice(order.indexOf(ui.item.attr('id')), 1);
40-
order.splice(ui.item.index(), 0, ui.item.attr('id'));
39+
order.splice(order.indexOf(ui.item.attr("id")), 1);
40+
order.splice(ui.item.index(), 0, ui.item.attr("id"));
4141

4242
var saveObj = {};
43-
saveObj['cacheOrder4'] = order;
43+
saveObj["cacheOrder4"] = order;
4444
chrome.storage.sync.set(saveObj, function() {
45-
console.log('Saved Cache Ordering Preferences');
45+
console.log("Saved Cache Ordering Preferences");
4646
});
4747
},
4848

4949
// Set up sortable, checkboxes, & toggle
5050
create: function(event, ui) {
5151
// Set up sortable
52-
chrome.storage.sync.get('cacheOrder4', function(result) {
53-
order = result['cacheOrder4'] || ['google-cache-sortable', 'wayback-machine-sortable', 'coral-cdn-sortable'];
52+
chrome.storage.sync.get("cacheOrder4", function(result) {
53+
order = result["cacheOrder4"] || ["google-cache-sortable", "wayback-machine-sortable", "coral-cdn-sortable"];
5454

55-
var ul = $('#sortable');
56-
var li = ul.children('li').get();
55+
var ul = $("#sortable");
56+
var li = ul.children("li").get();
5757
li.sort(function(a, b) {
58-
return order.indexOf($(a).attr('id')) - order.indexOf($(b).attr('id'));
58+
return order.indexOf($(a).attr("id")) - order.indexOf($(b).attr("id"));
5959
});
6060
ul.append(li);
6161
});
6262

6363
// Set up auto-detect toggle
64-
chrome.storage.sync.get('auto-detect', function(result) {
65-
toggle = $('#myonoffswitch');
66-
toggle.prop('checked', result['auto-detect']);
64+
chrome.storage.sync.get("auto-detect", function(result) {
65+
var toggle = $("#myonoffswitch");
66+
toggle.prop("checked", result["auto-detect"]);
6767
});
6868

6969
// Set up context menu caches
7070
chrome.storage.sync.get(CONTEXT_MENU_CACHES, function(results) {
7171
Object.keys(results).forEach(function(key) {
72-
$('#' + key).prop('checked', !!results[key]);
72+
$("#" + key).prop("checked", !!results[key]);
7373
});
7474
});
7575
}
7676
});
7777

7878
// Save auto-detect settings
79-
$('#myonoffswitch').click(function(event) {
80-
chrome.storage.sync.set({'auto-detect': $('#myonoffswitch').is(':checked')}, function() {
81-
console.log('Saved Auto-Detect Preferences');
79+
$("#myonoffswitch").click(function(event) {
80+
chrome.storage.sync.set({"auto-detect": $("#myonoffswitch").is(":checked")}, function() {
81+
console.log("Saved Auto-Detect Preferences");
8282
});
8383
});
8484

8585
// Add/Remove context menu caches
86-
$('.context-menu-label').click(updateContextMenuCaches);
86+
$(".context-menu-label").click(updateContextMenuCaches);
8787

88-
$('#sortable').disableSelection();
88+
$("#sortable").disableSelection();

redirect.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
var currentURL = '';
1+
var currentURL = "";
22
var isHTTPS = true;
33
var index = 0;
44
var numberOfRedirects = 0;
55
var redirecting = false;
66

77
var cacheURL = [
8-
'http://webcache.googleusercontent.com/search?q=cache:',
9-
'http://web.archive.org/web/*/',
10-
'.nyud.net'
8+
"http://webcache.googleusercontent.com/search?q=cache:",
9+
"http://web.archive.org/web/*/",
10+
".nyud.net"
1111
];
12-
var cacheNames = ['google-cache-sortable', 'wayback-machine-sortable', 'coral-cdn-sortable'];
12+
var cacheNames = ["google-cache-sortable", "wayback-machine-sortable", "coral-cdn-sortable"];
1313
var URL_HASH = [
14-
{ name: 'google-cache-sortable', URL: 'http://webcache.googleusercontent.com/search?q=cache:' },
15-
{ name: 'wayback-machine-sortable', URL: 'http://web.archive.org/web/*/' },
16-
{ name: 'coral-cdn-sortable', URL: '.nyud.net' }
14+
{ name: "google-cache-sortable", URL: "http://webcache.googleusercontent.com/search?q=cache:" },
15+
{ name: "wayback-machine-sortable", URL: "http://web.archive.org/web/*/" },
16+
{ name: "coral-cdn-sortable", URL: ".nyud.net" }
1717
];
1818

1919
function getURL() {
2020
++numberOfRedirects;
2121
if(cacheURL[index] == cacheURL.length) {
2222
index = 0;
2323
}
24-
if(cacheURL[index] != '.nyud.net') { // Google and Wayback Machine
25-
return cacheURL[index] + (isHTTPS ? currentURL.substr(8) : currentURL.substr(7))
24+
if(cacheURL[index] != ".nyud.net") { // Google and Wayback Machine
25+
return cacheURL[index] + (isHTTPS ? currentURL.substr(8) : currentURL.substr(7));
2626
} else { // Coral CDN
27-
if(currentURL.slice(-1) == '/') {
28-
return currentURL.substring(0, currentURL.length -1) + '.nyud.net';
27+
if(currentURL.slice(-1) == "/") {
28+
return currentURL.substring(0, currentURL.length -1) + ".nyud.net";
2929
} else {
30-
return currentURL + '.nyud.net';
30+
return currentURL + ".nyud.net";
3131
}
3232
}
3333
}
3434

3535
function handler(details) {
36-
//console.log('StatusLine is: ' + details.statusLine);
36+
//console.log("StatusLine is: " + details.statusLine);
3737
if(numberOfRedirects > cacheURL.length) { // There is no cache available
3838
chrome.webRequest.onHeadersReceived.removeListener(handler);
3939
redirecting = false;
4040
return { cancel: true };
4141
}
42-
if(~details.statusLine.search('404')) { // Not found
42+
if(~details.statusLine.search("404")) { // Not found
4343
++index;
4444
return { redirectUrl:getURL() };
4545
}
46-
else if(~details.statusLine.search('403')) { // Forbidden
46+
else if(~details.statusLine.search("403")) { // Forbidden
4747
++index;
4848
return { redirectUrl:getURL() };
4949
}
@@ -55,8 +55,8 @@ function handler(details) {
5555
}
5656

5757
function openPage(currentTab) {
58-
chrome.storage.sync.get('cacheOrder4', function(result) {
59-
var cacheOrder = result['cacheOrder4'] || cacheNames;
58+
chrome.storage.sync.get("cacheOrder4", function(result) {
59+
var cacheOrder = result["cacheOrder4"] || cacheNames;
6060

6161
URL_HASH.sort(function(a, b) {
6262
return cacheOrder.indexOf(a.name) - cacheOrder.indexOf(b.name);
@@ -76,17 +76,17 @@ function openPage(currentTab) {
7676
chrome.webRequest.onHeadersReceived.addListener(
7777
handler,
7878
{
79-
urls: ['<all_urls>'],
80-
types: ['main_frame']
79+
urls: ["<all_urls>"],
80+
types: ["main_frame"]
8181
},
82-
['blocking']
82+
["blocking"]
8383
);
8484

8585
currentURL = currentTab.url;
8686

87-
isHTTPS = (currentURL.substring(0, 6) == 'https:');
87+
isHTTPS = (currentURL.substring(0, 6) == "https:");
8888

89-
//console.log('the tab id for the redirect is ' + currentTab.id + ': The website is: ' + currentURL);
89+
//console.log("the tab id for the redirect is " + currentTab.id + ": The website is: " + currentURL);
9090

9191
chrome.tabs.update(currentTab.id, { url: getURL(index) });
9292

@@ -106,37 +106,37 @@ function autoRedirect(details) {
106106
if(tab == null || redirecting)
107107
return;
108108

109-
if(~details.statusLine.indexOf('408')) {
110-
console.log('408 redirect');
111-
} else if(~details.statusLine.indexOf('503')) {
112-
console.log('503 redirect');
109+
if(~details.statusLine.indexOf("408")) {
110+
console.log("408 redirect");
111+
} else if(~details.statusLine.indexOf("503")) {
112+
console.log("503 redirect");
113113
openPage(tab);
114-
} else if(~details.statusLine.indexOf('521')) {
115-
console.log('521 redirect');
114+
} else if(~details.statusLine.indexOf("521")) {
115+
console.log("521 redirect");
116116
openPage(tab);
117-
} else if(~details.statusLine.indexOf('522')) {
118-
console.log('522 redirect');
117+
} else if(~details.statusLine.indexOf("522")) {
118+
console.log("522 redirect");
119119
openPage(tab);
120120
}
121121
});
122122
}
123123

124-
chrome.storage.sync.get('auto-detect', function(result) {
125-
if(result['auto-detect'] == 'on') {
124+
chrome.storage.sync.get("auto-detect", function(result) {
125+
if(result["auto-detect"] == "on") {
126126
chrome.webRequest.onHeadersReceived.addListener(
127127
autoRedirect,
128-
{ urls: ['<all_urls>'] }
128+
{ urls: ["<all_urls>"] }
129129
);
130130
}
131131
});
132132

133133
// Set defaults on install or update
134134
chrome.runtime.onInstalled.addListener(function(details) {
135-
chrome.storage.sync.get('cacheOrder', function(result) {
135+
chrome.storage.sync.get("cacheOrder", function(result) {
136136
if(Object.keys(result).length == 0) {
137137
var saveObject = {
138-
'cacheOrder4': cacheNames,
139-
'auto-detect': 'off'
138+
"cacheOrder4": cacheNames,
139+
"auto-detect": "off"
140140
};
141141
chrome.storage.sync.set(saveObject);
142142
}

0 commit comments

Comments
 (0)