'use strick';

var fs = require('fs');

var $ = require('cheerio');

// get links from html
exports.getLinks = function getLinks(html) {
	var arr = [];
	$(html).find('a').each(function (i, e) {
		arr[i] = $(this).attr('href');
	});
	return arr;
};

// load request headers from file
exports.loadHeaders = function loadHeaders(file) {
	try {
		var content = fs.readFileSync(file, 'utf8');
		var arr = content.split('\n');
		var headers = {};
		for (var i in arr) {
			var map = arr[i].split(':');
			map[1] = map[1].length - map[1].lastIndexOf('\r') == 1 ? map[1].slice(0, map[1].length-1) : map[1];
			headers[map[0]] = map[1];
		}
		return headers;
	} catch (err) {
		console.log('Load Headers Error');
		console.error(err);
		return {};
	}
};

@@ -396,24 +396,88 @@
 , 'utf8');%0D%0A
+%09%09var separator = process.platform == 'win32' ? '%5Cr%5Cn' : '%5Cn';%0D%0A
 %09%09var arr = 
@@ -490,20 +490,25 @@
 t.split(
-'%5Cn'
+separator
 );%0D%0A%09%09va
@@ -585,112 +585,8 @@
 );%0D%0A
-%09%09%09map%5B1%5D = map%5B1%5D.length - map%5B1%5D.lastIndexOf('%5Cr') == 1 ? map%5B1%5D.slice(0, map%5B1%5D.length-1) : map%5B1%5D;%0D%0A
 %09%09%09h

Update fix a bug.