|
@@ -6,8 +6,49 @@
|
|
|
//Get the target webpage body
|
|
|
requirelib("http");
|
|
|
var websiteContent = http.get(url);
|
|
|
+var rootURL = url.split("/");
|
|
|
+rootURL.pop();
|
|
|
+rootURL = rootURL.join("/");
|
|
|
+
|
|
|
|
|
|
//replace the relative path files with absolutes
|
|
|
-websiteContent = websiteContent.split('src="/').join('src="' + url + '/');
|
|
|
-websiteContent = websiteContent.split('href="/').join('href="' + url + '/');
|
|
|
+websiteContent = websiteContent.split('src="/').join('src="' + rootURL + '/');
|
|
|
+websiteContent = websiteContent.split('href="/').join('href="' + rootURL + '/');
|
|
|
+
|
|
|
+//Replace href with redirection code
|
|
|
+var htmlSegmentChunks = websiteContent.split(" ");
|
|
|
+var chunksToBeReplaced = [];
|
|
|
+for (var i = 0; i < htmlSegmentChunks.length; i++){
|
|
|
+ var thisSegment = htmlSegmentChunks[i].trim();
|
|
|
+ if (thisSegment.substring(0, 5) == "href="){
|
|
|
+ //Process the segment and trim out only the href="xxx" part
|
|
|
+ var cutPosition = thisSegment.lastIndexOf('"');
|
|
|
+ thisSegment = thisSegment.substring(0, cutPosition + 1)
|
|
|
+ if (thisSegment.trim().length > 6){
|
|
|
+ chunksToBeReplaced.push(thisSegment);
|
|
|
+ //console.log("SEGMENT:", thisSegment, thisSegment.trim().length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+for (var k= 0; k < chunksToBeReplaced.length; k++){
|
|
|
+ var thisSegment = chunksToBeReplaced[k];
|
|
|
+ thisSegment = thisSegment.replace('href="', "parent.loadWebsite(\"")
|
|
|
+ thisSegment = thisSegment + ");"
|
|
|
+ thisSegment = thisSegment.split("\"").join("'");
|
|
|
+ thisSegment = "onclick=\"" + thisSegment + "\"";
|
|
|
+
|
|
|
+
|
|
|
+ //Check if this is css / style files. If yes, bypass it
|
|
|
+ var expectedFileExtension = thisSegment.trim().substring(thisSegment.lastIndexOf("."), thisSegment.length -4);
|
|
|
+ if (expectedFileExtension == ".css" || expectedFileExtension == ".js" || thisSegment.indexOf(".css") >= 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //console.log("REPLACING", chunksToBeReplaced[k], thisSegment);
|
|
|
+ websiteContent = websiteContent.replace(chunksToBeReplaced[k], thisSegment);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//console.log(websiteContent);
|
|
|
sendResp(websiteContent);
|