-
Notifications
You must be signed in to change notification settings - Fork 3
/
devtools.js
41 lines (36 loc) · 1.14 KB
/
devtools.js
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
function getOptions() {
var options = {}, option, key;
for (key in localStorage) {
if (key.indexOf("settings-") === 0) {
option = JSON.parse(localStorage[key]);
options[option.key] = option.value;
}
}
return options;
}
function validateScript(content, url) {
var isValid = JSHINT(content, getOptions());
if (!isValid) {
JSHINT.errors.forEach(function(error) {
if (error === null) {
// Why does JSHINT return a null terminated array?
return;
}
chrome.experimental.devtools.console.addMessage(chrome.experimental.devtools.console.Severity.Error, error.reason, url, error.line);
});
} else {
chrome.experimental.devtools.console.addMessage(chrome.experimental.devtools.console.Severity.Log, "JSHint: No errors", url);
}
}
chrome.devtools.inspectedWindow.onResourceContentCommitted.addListener(function(resource, content) {
var url = resource.url;
if (url.lastIndexOf(".js") === url.length - 3) {
validateScript(content, resource.url);
}
});
chrome.devtools.panels.create(
'JS Hint',
null, // No icon path
'settings/panel.html',
null // no callback needed
);