-
Notifications
You must be signed in to change notification settings - Fork 1
/
panel.js
46 lines (41 loc) · 1.56 KB
/
panel.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
41
42
43
44
45
46
// This one acts in the context of the panel in the Dev Tools
//
// Can use
// chrome.devtools.*
// chrome.extension.*
document.addEventListener("click", handleClick, false);
function handleClick(event) {
if (event.target.className=="button-show-content") {
document.querySelector('#img').style.display = 'none';
document.querySelector('#dataDiv').style.visibility = 'visible';
document.querySelector('#dataDiv').innerHTML = "<div style=\"word-wrap: break-word;color:white;\">"+ event.target.dataset.content +"</div>";
}
}
chrome.devtools.network.onRequestFinished.addListener(
function(request) {
if (request.response.content.mimeType == "application/json") {
request.getContent(function(body){
var postData = request.request.postData.params,
data = {};
for (var i = 0; i < postData.length; i++) {
if(postData[i].value.indexOf('%') >= 0){
postData[i].value = postData[i].value.replace(/%/g, ",");
}
data[postData[i].name] = postData[i].value;
};
var mockObject = {
request: {
path: request.request.url.split(':')[2].substring(4),
method: request.request.method,
},
response: {
data: JSON.parse(body)
}
};
mockObject.request.data = data;
sendObjectToInspectedPage({action: "code", content: mockObject});
chrome.extension.sendMessage({name: JSON.stringify(request.request.url), content: JSON.stringify(mockObject)}, function(message){});
});
}
}
);