问题描述
- 网页里的一段超级复杂的javascript代码,不知道做什么用的,问了几个高手都无法解答
-
第一段:
<br>
/*<![CDATA[*/<br>
var DataBrainConfig = {'SiteId':'5960','ConfigurationId':'1','AutoIntegration':true,'checkTimeMeter':1,'useDMP':true,'timeRequestLimit':500,'dmpPartnerKey':'6SysO2MEZq69sDxIvJm58g2','customAttributes':[{'Name':'vertical','Value':'dating'}]};var data_brain = false;<br>
var JSON; if (!JSON) { JSON = {}; }</p><p>if (typeof JSON.stringify !== 'function') {<br>
JSON.stringify = function (value, replacer, space) {<br>
var i; gap = ''; indent = ''; if (typeof space === 'number') { for (i = 0; i < space; i += 1) { indent += ' '; } } else if (typeof space === 'string') { indent = space; }<br>
rep = replacer; if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) { throw new Error('JSON.stringify'); }<br>
return str('', { '': value });<br>
};<br>
}</p><p>/**<br>
*</p><ul>
<li>@constructor
*/
function DataBrain() {
this.TrackerUrl = '<a href="http://tracker.databrain.com">http://tracker.databrain.com</a>';
this.AT_LOADPAGE = 1;
this.siteid = 0;
this.cfid = 0;
this.at = 0;
this.vid = 0;
this.checkTimeMeter = 0;
this.startTime = 0;
this.startResponseTime = 0;
this.endTime = 0;
this.trackError = 0;
this.RequestStatuses = ['start', 'progress', 'finished', 'error'];
this.requestStatus = this.RequestStatuses[0];
this.methods = ['ajax', 'script'];
this.method = this.methods[1];
this.ap = {};
this.timeRequestLimit = 300;
this.useDMP = false;
this.mergeData = {};
this.dmpPartnerKey = '';
this.ca = [];
this.init();
}</li>
</ul><p>/**</p>
<ul>
<li>init
*/
DataBrain.prototype.init = function() {
this.getVid();
this.setParam();
if ( 0 != this.checkTimeMeter) {
this.startTrackMeter();
}
this.trackDataBrain();
};</li>
</ul><p>/**</p>
<ul>
<li>Start Track Meter
*/
DataBrain.prototype.startTrackMeter = function() {
this.startTime = new Date().getTime();
};</li>
</ul><p>/**</p>
<ul>
<li>Start Track Response Meter
*/
DataBrain.prototype.startReponseMeter = function() {
this.startResponseTime = new Date().getTime();
};</li>
</ul><p>/**</p>
<ul>
<li>End Track Meter
*/
DataBrain.prototype.endTrackMeter = function() {
this.endTime = new Date().getTime();
};</li>
</ul><p>/**</p>
<ul>
<li>End Track Meter
*/
DataBrain.prototype.getTrackMeterTime = function() {
var timeDiff = this.endTime - this.startTime;
return timeDiff;
};</li>
</ul><p>DataBrain.prototype.getCurrentMeterTime = function() {<br>
return new Date().getTime() - this.startResponseTime;<br>
}</p><p>/**</p>
<ul>
<li>Get Vid
*/
DataBrain.prototype.getVid = function() {
this.vid = document.cookie.substr(document.cookie.indexOf('vid=')+4, 36);
};</li>
</ul><p>/**<br>
*</p><ul>
<li>@param cookieName</li>
<li>@param cookieValue</li>
<li>@param nDays</li>
<li>@constructor
*/
DataBrain.prototype.SetCookie = function(cookieName,cookieValue,nDays) {
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+'='+escape(cookieValue)
+ ';expires='+expire.toGMTString() + ';path=/';
};</li>
</ul><p>/**</p>
<ul>
<li>Set Vid To Cookie
*/
DataBrain.prototype.setVid = function(vid) {
this.SetCookie('vid', vid, 365);
};</li>
</ul><p>/**</p>
<ul>
<li>Check Vid</li>
<li>@returns {boolean}
*/
DataBrain.prototype.isSettedVid = function() {
var result = false;
if ( 0 < parseInt(this.vid) ) {
result = true;
}
return result;
};</li>
</ul><p>/**</p>
<ul>
<li>Set Parameters to track action in DataBrain
*/
DataBrain.prototype.setParam = function() {
this.siteid = DataBrainConfig.SiteId;
this.cfid = parseInt(DataBrainConfig.ConfigurationId);
this.at = parseInt(DataBrainConfig.AutoIntegration);
this.checkTimeMeter = parseInt(DataBrainConfig.checkTimeMeter);
this.ap = this.getActionParam();
this.ca = DataBrainConfig.customAttributes;
this.useDMP = DataBrainConfig.useDMP;
this.timeRequestLimit = parseInt(DataBrainConfig.timeRequestLimit);
this.dmpPartnerKey = DataBrainConfig.dmpPartnerKey;
};</li>
</ul><p>/**</p>
<ul>
<li>Return parameters of page to Action</li>
<li><p>@returns {{Content: string, Referrer: string, Title: string}}<br>
*/<br>
DataBrain.prototype.getActionParam = function() {<br>
var _location = document.location.href.substring(0, 300);<br>
var _referrer = document.referrer.substring(0, 300);<br>
var _title = document.title.substring(0, 300);</p><p>return { Content: _location, Referrer: _referrer, Title: _title };<br>
};</p></li>
</ul><p>/**</p>
<ul>
<li>init request to trackDataBrain
*/
DataBrain.prototype.trackDataBrain = function() {
if ( this.methods[1] == this.method ) {
this.scriptDataBrain();
} else {
this.requestToDataBrain();
}
};</li>
</ul><p>/**</p>
<ul>
<li>Prepare Data to send request</li>
<li><p>@returns {string}<br>
*/<br>
DataBrain.prototype.prepareData = function() {</p><p>var params = 'siteid=' + this.siteid + '&cfid=' + this.cfid + '&at=' + this.AT_LOADPAGE;</p>
<p>if (this.useDMP != true) {<br>
params = '/track.ashx?' + params;<br>
} else {<br>
params = '/bridge.ashx?' + params + '&partnerKey=' + this.dmpPartnerKey;<br>
}</p><p>params += (this.ap == {} ? '' : '&ap=' + escape(JSON.stringify(this.ap)));<br>
params += (this.ca ? '&ca=' + escape(JSON.stringify(this.ca)) : '');<br>
return params;<br>
};</p></li>
</ul><p>/**</p>
<ul>
<li>Prepare Data to send request</li>
<li><p>@returns {string}<br>
*/<br>
DataBrain.prototype.prepareDataScript = function() {<br>
var params = 'siteid=' + this.siteid + '&cfid=' + this.cfid + '&at=' + this.AT_LOADPAGE;</p><p>if (this.useDMP != true) {<br>
params = '/track.ashx?' + params;<br>
} else {<br>
params = '/bridge.ashx?' + params + '&partnerKey=' + this.dmpPartnerKey;<br>
}</p><p>params += (this.ap == {} ? '' : '&ap=' + encodeURIComponent(JSON.stringify(this.ap)));<br>
params += (this.ca ? '&ca=' + encodeURIComponent(JSON.stringify(this.ca)) : '');<br>
return params;<br>
};</p></li>
</ul><p>/**</p>
<ul>
<li><p>Send request<br>
*/<br>
DataBrain.prototype.requestToDataBrain = function() {<br>
var req = new XMLHttpRequest();<br>
var body = '';<br>
var self = this;<br>
this.requestStatus = this.RequestStatuses[1];<br>
if ('withCredentials' in req) {<br>
self.startReponseMeter();<br>
req.open('GET', this.TrackerUrl + this.prepareData(), true);<br>
req.onreadystatechange = function() {<br>
if (req.readyState === 4) {<br>
if (req.status >= 200 && req.status < 400) {<br>
var res = req.responseText;</p><pre><code> if (self.useDMP == true) {
self.handleResponseDMP(self, res);
} else {
self.handleResponse(self, res);
}
} else {
self.handleError(self);
}
}
};
req.send(body);
</code></pre><p>}<br>
};</p></li>
</ul><p>/**</p>
<ul>
<li><p>Request script<br>
*/<br>
DataBrain.prototype.scriptDataBrain = function() {<br>
var req = new XMLHttpRequest();<br>
var body = '';<br>
var self = this;<br>
this.requestStatus = this.RequestStatuses[1];<br>
document.addEventListener('DOMContentLoaded',<br>
function(){<br>
var script = document.createElement('script');<br>
self.startReponseMeter();<br>
script.setAttribute('src', self.TrackerUrl + self.prepareDataScript());<br>
document.body.appendChild(script);</p><pre><code> script.onload = function(){
if (self.useDMP == true) {
self.handleResponseDMP(self);
} else {
self.handleResponse(self);
}
};
});
</code></pre><p>};</p></li>
</ul><p>/**</p>
<ul>
<li>Request Callback
*/
DataBrain.prototype.handleResponse = function(self, res) {
if ( this.methods[1] != this.method ) {
eval(res);
}
if ( !self.isSettedVid() || self.vid != <strong><em>dbVid ) {
self.setVid(</em></strong>dbVid);
}
self.requestStatus = this.RequestStatuses[2];
if ( 0 != self.checkTimeMeter) {
self.endTrackMeter();
console.log(self.getTrackMeterTime());
}
};</li>
</ul><p>/**</p>
<ul>
<li>Request Callback using DMP data
*/
DataBrain.prototype.handleResponseDMP = function(self, res) {</li>
</ul><p>// console.log(self.TrackerUrl + self.prepareDataScript());</p>
<pre><code>if ( this.methods[1] != this.method ) {
eval(res);
}if (typeof ___dbDmpVisit.Vid !== "undefined") {
if ( !self.isSettedVid() || self.vid != ___dbDmpVisit.Vid ) {
self.setVid(___dbDmpVisit.Vid);
}
}if (typeof ___dbDmpVisit.SessionStats !== "undefined") {
self.setMergeData(___dbDmpVisit);
}self.requestStatus = this.RequestStatuses[2];
if ( 0 != self.checkTimeMeter) {
self.endTrackMeter();
// console.log(self.getTrackMeterTime());
}
</code></pre><p>};</p>
<p>/**</p>
<ul>
<li>Request Callback
*/
DataBrain.prototype.handleError = function(self) {
self.trackError = 1;
self.requestStatus = this.RequestStatuses[3];
};</li>
</ul><p>DataBrain.prototype.getMergeData = function() {<br>
return this.mergeData;<br>
};</p><p>DataBrain.prototype.getData = function() {<br>
return (this.mergeData.dmpData) ? this.mergeData.dmpData : {};<br>
}</p><p>DataBrain.prototype.setMergeData = function(data) {<br>
this.mergeData.dmpData = data;<br>
this.mergeData.dbTimeScript = this.getCurrentMeterTime();<br>
};</p><p>/**</p>
<ul>
<li>Function Track action to DataBrain and get parameter Vid
<em>/
(function() {
data_brain = new DataBrain();
})();
/</em>]]>*/第二段:
/*<![CDATA[*/
var _isGotoJump = false; window.open=function(url){ if(!_isGotoJump) {location.href=url; _isGotoJump = true; return false;}}
document.body.style.display = 'none';
autoLogin = {
href : 'http://www.xxxx.com/site/redirectpage?ca=link&sid=6170&trid=16596&hv=f5fb029be166ab63f639a6e7c0e794b1',
tRid : '16596',
sid : 6170,
rules : [{"name":"Rule0","conditions":[{"domain":"benaughty.com","condition":"!=","count":"0"}],"url":"http://www.targeturl.com/ext.php?dynamicpage=5step_focus&a_aid=adsbr","parameters":"static"}],
useDMP : true
};
var hv="f5fb029be166ab63f639a6e7c0e794b1";document.addEventListener("DOMContentLoaded", function(event) {var link = document.getElementsByTagName('a');for(var i=0;i<link.length;i++){attribute = link[i].getAttribute('onclick');if(Boolean(attribute) && attribute.match('/site/redirectpage')){link[i].setAttribute('onclick', attribute.replace("',", "&hv=" + hv + "',"));}}});
/*]]>*/
解决方案
你最起码应该format一下再发上来吧?
这有谁愿意去看