Skip to content

Commit efac0d6

Browse files
committed
Clean up JSHint errors and whitespace
1 parent ea9e729 commit efac0d6

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

Gruntfile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = function(grunt) {
1515
grunt.loadNpmTasks('grunt-contrib-jshint');
1616
grunt.loadNpmTasks('grunt-contrib-nodeunit');
1717

18-
// Default task(s).
1918
grunt.registerTask('default', ['uglify']);
2019

2120
};

background.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Can use:
44
// chrome.tabs.*
55
// chrome.extension.*
6+
67
var tabInspected;
78
var ports = [];
89
chrome.runtime.onConnect.addListener(function (port) {
@@ -18,14 +19,14 @@ chrome.runtime.onConnect.addListener(function (port) {
1819
});
1920
});
2021

21-
chrome.tabs.onUpdated.addListener(function (tabId, changes, tabObject) {
22-
if (tabId == tabInspected && changes.status == "complete") {
22+
chrome.tabs.onUpdated.addListener(function (tabId, changes) {
23+
if (tabId === tabInspected && changes.status === "complete") {
2324
getJsonResource(tabId);
2425
}
2526
});
2627

2728
function processBackgroundIncomingMessage(msg) {
28-
console.log("Processing Message in Background", msg)
29+
console.log("Processing Message in Background", msg);
2930
if (msg.tabId) {
3031
tabInspected = msg.tabId;
3132
getJsonResource(tabInspected);
@@ -43,26 +44,26 @@ function notifyDevtools(msg) {
4344
}
4445

4546
function getJsonResource(tabID) {
46-
var pageContext;
4747
chrome.tabs.get(tabID, function(tab) {
4848
var jsonResourceURL = tab.url+".json";
4949
var xhr = new XMLHttpRequest();
5050
xhr.open("GET", jsonResourceURL, true);
5151
xhr.onreadystatechange = function() {
52-
if (xhr.readyState === 4 && xhr.getResponseHeader("X-Powered-By").substring(0, 7) === "Solidus") {
53-
if(xhr.status === 200){ //Check this separately so we can notify devtools if we don't get a 200 response.
52+
var isSolidus = (xhr.getResponseHeader("X-Powered-By").substring(0, 7) === "Express");
53+
if (xhr.readyState === 4 && isSolidus) { // Check for completed Solidus response
54+
if(xhr.status !== 200){ // Check that Solidus response didn't fail
55+
notifyDevtools(JSON.parse('{"error":"Failed to get Solidus page context."}'));
56+
} else {
5457
try {
5558
notifyDevtools(JSON.parse(xhr.responseText));
5659
} catch (e) {
5760
notifyDevtools(JSON.parse('{"error":"' + e + '"}'));
5861
}
59-
} else {
60-
notifyDevtools(JSON.parse('{"error":"Solidus Page Context Not Found!"}'));
6162
}
6263
} else {
6364
notifyDevtools(JSON.parse('{"error":"Looks like you\'re not inspecting a Solidus Page."}'));
6465
}
65-
}
66+
};
6667
xhr.send();
6768
});
6869
}

main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function(panel){
88

99
var _window;
1010
var data = [];
11-
var port = chrome.runtime.connect({name: 'devtools'});
11+
var port = chrome.runtime.connect({name: "devtools"});
1212

1313
port.onMessage.addListener(function(msg) {
1414

@@ -27,14 +27,16 @@ function(panel){
2727
_window = panelWindow;
2828

2929
var msg;
30-
while (msg = data.shift()) {
30+
while (msg === data) {
31+
msg = data.shift();
3132
_window.processMainIncomingMessage(msg);
3233
}
3334
_window.respond = function(msg) {
3435
console.log("Main.js Sending Message", msg);
3536
port.postMessage(msg);
3637
};
3738

39+
//Tell background.js which tab is being inspected
3840
panelWindow.respond(chrome.devtools.inspectedWindow);
3941
});
4042
});

views/devpanel.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Runs in the context of the DevTools panel
2-
//
32
// Can use
43
// chrome.devtools.*
54
// chrome.extension.*
@@ -8,19 +7,18 @@ var inspector;
87

98
function processMainIncomingMessage(msg) {
109
console.log("Devpanel Processing Message", msg);
11-
if (msg.hasOwnProperty('page')) {
10+
if (msg.hasOwnProperty("page")) {
1211
displayMessage("Looks like a Solidus page!");
1312
//Check if there is an initialized InspectorJSON that hasn't been destroyed
1413
if ((inspector instanceof InspectorJSON) && (inspector.page)) {
1514
inspector.view(msg);
16-
}
17-
else {
15+
} else {
1816
inspector = new InspectorJSON({
19-
element: 'pagecontext',
17+
element: "pagecontext",
2018
json: msg
2119
});
2220
}
23-
} else if (msg.hasOwnProperty('error')) {
21+
} else if (msg.hasOwnProperty("error")) {
2422
if (inspector instanceof InspectorJSON) {
2523
inspector.destroy();
2624
}
@@ -31,6 +29,6 @@ function processMainIncomingMessage(msg) {
3129
}
3230

3331
function displayMessage(msg) {
34-
document.querySelector('#messageholder').innerHTML = msg;
32+
document.querySelector("#messageholder").innerHTML = msg;
3533
console.log("Updated Panel With Message", msg);
3634
}

0 commit comments

Comments
 (0)