From 915d72ebbedc40f27f29e362738fc2899c51bba5 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 25 Apr 2022 17:49:10 +0900 Subject: [PATCH] Update http.js --- lib/http.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/http.js b/lib/http.js index c8dcb57..fedfc66 100644 --- a/lib/http.js +++ b/lib/http.js @@ -642,6 +642,32 @@ var HTTPObject = function(engine) { this.saveTo = filename; }; + this.parseScripts = function() { + var scripts = []; + + if (typeof this.responseBody !== "string") + return scripts; + + var tagName = "script"; + var a = this.responseBody.indexOf('<' + tagName + ' '); + var b = a < 0 ? -1 : this.responseBody.indexOf('', a); + + while (a > -1 && b > -1) { + var outerHTML = this.responseBody.substring(a, b + tagName.length + 3); + var innerHTML = this.responseBody.substring(this.responseBody.indexOf('>', a), b); + + scripts.push({ + 'outerHTML': outerHTML, + 'innerHTML': innerHTML + }); + + a = this.responseBody.indexOf('<' + tagName + ' ', b + tagName.length + 3); + b = a < 0 ? -1 : this.responseBody.indexOf('', a); + } + + return scripts; + }; + this.create(); };