2 jiuguilaotou2 jiuguilaotou2 于 2014.10.02 22:35 提问

网页里的一段超级复杂的javascript代码,不知道做什么用的,问了几个高手都无法解答

第一段:
<br> /*&lt;![CDATA[*/<br> var DataBrainConfig = {&#39;SiteId&#39;:&#39;5960&#39;,&#39;ConfigurationId&#39;:&#39;1&#39;,&#39;AutoIntegration&#39;:true,&#39;checkTimeMeter&#39;:1,&#39;useDMP&#39;:true,&#39;timeRequestLimit&#39;:500,&#39;dmpPartnerKey&#39;:&#39;6SysO2MEZq69sDxIvJm58g2&#39;,&#39;customAttributes&#39;:[{&#39;Name&#39;:&#39;vertical&#39;,&#39;Value&#39;:&#39;dating&#39;}]};var data_brain = false;<br> var JSON; if (!JSON) { JSON = {}; }</p> <p>if (typeof JSON.stringify !== &#39;function&#39;) {<br> JSON.stringify = function (value, replacer, space) {<br> var i; gap = &#39;&#39;; indent = &#39;&#39;; if (typeof space === &#39;number&#39;) { for (i = 0; i &lt; space; i += 1) { indent += &#39; &#39;; } } else if (typeof space === &#39;string&#39;) { indent = space; }<br> rep = replacer; if (replacer &amp;&amp; typeof replacer !== &#39;function&#39; &amp;&amp; (typeof replacer !== &#39;object&#39; || typeof replacer.length !== &#39;number&#39;)) { throw new Error(&#39;JSON.stringify&#39;); }<br> return str(&#39;&#39;, { &#39;&#39;: value });<br> };<br> }</p> <p>/**<br> *</p> <ul> <li>@constructor */ function DataBrain() { this.TrackerUrl = &#39;<a href="http://tracker.databrain.com">http://tracker.databrain.com</a>&#39;; 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 = [&#39;start&#39;, &#39;progress&#39;, &#39;finished&#39;, &#39;error&#39;]; this.requestStatus = this.RequestStatuses[0]; this.methods = [&#39;ajax&#39;, &#39;script&#39;]; this.method = this.methods[1]; this.ap = {}; this.timeRequestLimit = 300; this.useDMP = false; this.mergeData = {}; this.dmpPartnerKey = &#39;&#39;; 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(&#39;vid=&#39;)+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+&#39;=&#39;+escape(cookieValue) + &#39;;expires=&#39;+expire.toGMTString() + &#39;;path=/&#39;; };</li> </ul> <p>/**</p> <ul> <li>Set Vid To Cookie */ DataBrain.prototype.setVid = function(vid) { this.SetCookie(&#39;vid&#39;, vid, 365); };</li> </ul> <p>/**</p> <ul> <li>Check Vid</li> <li>@returns {boolean} */ DataBrain.prototype.isSettedVid = function() { var result = false; if ( 0 &lt; 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 = &#39;siteid=&#39; + this.siteid + &#39;&amp;cfid=&#39; + this.cfid + &#39;&amp;at=&#39; + this.AT_LOADPAGE;</p> <p>if (this.useDMP != true) {<br> params = &#39;/track.ashx?&#39; + params;<br> } else {<br> params = &#39;/bridge.ashx?&#39; + params + &#39;&amp;partnerKey=&#39; + this.dmpPartnerKey;<br> }</p> <p>params += (this.ap == {} ? &#39;&#39; : &#39;&amp;ap=&#39; + escape(JSON.stringify(this.ap)));<br> params += (this.ca ? &#39;&amp;ca=&#39; + escape(JSON.stringify(this.ca)) : &#39;&#39;);<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 = &#39;siteid=&#39; + this.siteid + &#39;&amp;cfid=&#39; + this.cfid + &#39;&amp;at=&#39; + this.AT_LOADPAGE;</p> <p>if (this.useDMP != true) {<br> params = &#39;/track.ashx?&#39; + params;<br> } else {<br> params = &#39;/bridge.ashx?&#39; + params + &#39;&amp;partnerKey=&#39; + this.dmpPartnerKey;<br> }</p> <p>params += (this.ap == {} ? &#39;&#39; : &#39;&amp;ap=&#39; + encodeURIComponent(JSON.stringify(this.ap)));<br> params += (this.ca ? &#39;&amp;ca=&#39; + encodeURIComponent(JSON.stringify(this.ca)) : &#39;&#39;);<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 = &#39;&#39;;<br> var self = this;<br> this.requestStatus = this.RequestStatuses[1];<br> if (&#39;withCredentials&#39; in req) {<br> self.startReponseMeter();<br> req.open(&#39;GET&#39;, this.TrackerUrl + this.prepareData(), true);<br> req.onreadystatechange = function() {<br> if (req.readyState === 4) {<br> if (req.status &gt;= 200 &amp;&amp; req.status &lt; 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 = &#39;&#39;;<br> var self = this;<br> this.requestStatus = this.RequestStatuses[1];<br> document.addEventListener(&#39;DOMContentLoaded&#39;,<br> function(){<br> var script = document.createElement(&#39;script&#39;);<br> self.startReponseMeter();<br> script.setAttribute(&#39;src&#39;, 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 !== &quot;undefined&quot;) { if ( !self.isSettedVid() || self.vid != ___dbDmpVisit.Vid ) { self.setVid(___dbDmpVisit.Vid); } } if (typeof ___dbDmpVisit.SessionStats !== &quot;undefined&quot;) { 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>]]&gt;*/

第二段:

/*<![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 + "',"));}}}); /*]]>*/

1个回答

u012899102
u012899102   2014.10.10 17:11

你最起码应该format一下再发上来吧?
这有谁愿意去看

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!