From 8892297877f3125ed96b7da383d344c019d69844 Mon Sep 17 00:00:00 2001 From: pasu Date: Wed, 26 Feb 2020 19:03:05 -0600 Subject: [PATCH] Adding full API replace --- devtools/devtools.js | 42 +++++++++++++++++++++++++++++------------- manifest.json | 2 +- panel/panel.html | 6 +++++- panel/panel.js | 9 +++++++-- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/devtools/devtools.js b/devtools/devtools.js index f217d36..7617872 100644 --- a/devtools/devtools.js +++ b/devtools/devtools.js @@ -31,6 +31,18 @@ function checkURLTagged(url, replaceData) { return replaceData.filter(replaceDatum => url.includes(replaceDatum.url)); } +function submitResponse(filteredData, continueParams) { + let responseLines = []; + if (filteredData.contentType) { + responseLines.push(`Content-Type: ${filteredData.contentType}`); + } + responseLines.push(''); + responseLines.push(''); + responseLines.push(filteredData.replace); + continueParams.rawResponse = btoa(unescape(encodeURIComponent(responseLines.join('\r\n')))); + chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); +} + let debugee = null; function setupDebugger(target) { debugee = { tabId: target.id }; @@ -51,21 +63,25 @@ function setupDebugger(target) { if (filteredData.length > 0) { var responseLines = []; responseLines.push('HTTP/1.1 200 OK'); - ajaxMe(request.url, (data) => { - replaceResponse(data.response, filteredData, (replacedData) => { - let headers = data.getAllResponseHeaders(); - responseLines.push(headers); - responseLines.push(''); - responseLines.push(''); - responseLines.push(replacedData); - continueParams.rawResponse = btoa(unescape(encodeURIComponent(responseLines.join('\r\n')))); + if (filteredData[0].find === '~NO_API~') { + submitResponse(filteredData[0], continueParams) + } else { + ajaxMe(request.url, (data) => { + replaceResponse(data.response, filteredData, (replacedData) => { + let headers = data.getAllResponseHeaders(); + responseLines.push(headers); + responseLines.push(''); + responseLines.push(''); + responseLines.push(replacedData); + continueParams.rawResponse = btoa(unescape(encodeURIComponent(responseLines.join('\r\n')))); + chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); + }); + }, (status) => { + responseLInes[0] = `HTTP/1.1 ${status}`; + continecontinueParams.rawResponse = btoa(responseLines.join('\r\n')); chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); }); - }, (status) => { - responseLInes[0] = `HTTP/1.1 ${status}`; - continecontinueParams.rawResponse = btoa(responseLines.join('\r\n')); - chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); - }); + } } else { chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); } diff --git a/manifest.json b/manifest.json index f0aa2ce..c5a6496 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Chrome Response Override", "short_name": "Chrome Response Override", - "version": "1.2", + "version": "1.3", "description": "Provides support to override API/HTML/* response using simple Find & Replace steps. No external app installation required", "author": "Pasupathi Rajamanickam", "devtools_page": "devtools/devtools.html", diff --git a/panel/panel.html b/panel/panel.html index 6e0bbc8..2b57292 100644 --- a/panel/panel.html +++ b/panel/panel.html @@ -31,7 +31,9 @@ - + +Wiki + @@ -40,6 +42,8 @@ URL Contains Find Replace +Content-Type +Delete
diff --git a/panel/panel.js b/panel/panel.js index 803a1ea..b3bc217 100644 --- a/panel/panel.js +++ b/panel/panel.js @@ -39,6 +39,7 @@ function saveData() { data.url = tds[0].getElementsByTagName('input')[0].value data.find = tds[1].getElementsByTagName('input')[0].value data.replace = tds[2].getElementsByTagName('input')[0].value + data.contentType = tds[3].getElementsByTagName('input')[0].value if (data.url !== '' && data.find !== '' && data.replace !== '') { replaceData.push(data); } @@ -59,10 +60,12 @@ function addRow() { let cell2 = row.insertCell(1); let cell3 = row.insertCell(2); let cell4 = row.insertCell(3); + let cell5 = row.insertCell(4); cell1.innerHTML = ''; cell2.innerHTML = ''; cell3.innerHTML = ''; - cell4.innerHTML = ''; + cell4.innerHTML = ''; + cell5.innerHTML = ''; initDeleteEvent(); } @@ -105,10 +108,12 @@ function initTable() { var cell2 = row.insertCell(1); var cell3 = row.insertCell(2); var cell4 = row.insertCell(3); + var cell5 = row.insertCell(4); cell1.innerHTML = ``; cell2.innerHTML = ``; cell3.innerHTML = ``; - cell4.innerHTML = ``; + cell4.innerHTML = ``; + cell5.innerHTML = ``; }); initDeleteEvent(); } else {