Hello all!
I’m trying to understand how a javascript works. My purpose is to make a little youtube utility in java.
In every page source you can find the following variable : “gXSRF_token”; Thanks to some JS, this fields gets populated with a session identifier (looks like random at first sight, but post requests needs a very accurate one…). Now, I’ve been trying to understand what happens !
[CODE]
<script type=”text/javascript”>
function urchinTracker (a) { }
function urchinTrackerDefer (a) { }
function _hbLink (a,b) { return false; }
[B]var gXSRF_token = ”[/B];
var gXSRF_field_name = ”;
var gXSRF_ql_pair = ”;
var onLoadFunctionList = onLoadFunctionList || [];
gXSRF_token = ‘L9SMusiZqK9_RKKaKK7Pef1mXal8MTIzNTEzNTMyOQ==’;
gXSRF_field_name = ‘session_token’;
onLoadFunctionList.push(function() { [B]populate_session_token()[/B] });
gXSRF_ql_pair = ‘session_token=bNU9Mjtxxw03_zwossLLfkg25UV8OA==’;
The html headers refer to 2 js pages:
[url]http://s.ytimg.com/yt/js/base_all_with_bidi-vfl78390.js
[url]http://s.ytimg.com/yt/js/channel_all-vfl74155.js
The populate function is defined in the first one and goes as follows:
[CODE]function populate_session_token()
{
for(var form_pos=0;form_pos<document.forms.length;form_pos++)
{
var skip=false;
for(var exclude_pos=0;
exclude_pos<session_excluded_forms.length;
exclude_pos++)
{
if(document.forms[form_pos].name
==session_excluded_forms[exclude_pos])
{
skip=true;
}
}
var aform=document.forms[form_pos];
if((aform.method.toLowerCase()==’post’)&&(skip==false))
{
var found=false;
for(var elem_pos=0;elem_pos<aform.elements.length;
elem_pos++)
{
var form_field=aform.elements[elem_pos];
if(form_field.name==gXSRF_field_name)
{
found=true;
}
}
if(!found)
{
dynamic_append_session_token(aform);
}
}
}
}
Can’t understand how the “gXSRF_token” variable gets populated there ?
Maybe you can understand this better than I can 🙂
Thanks for your time!