site > http://www.bittorrent.com/dna/resources/downloads/bittorrent-dna-javascript
download > download
script >
/* btdna.js - DNA support for HTML and JavaScript */
/* Copyright 2007-2008, BitTorrent, Inc. All rights reserved. */
/* $Rev: 12704 $ */
/* $LastChangedDate: 2008-07-08 12:51:44 -0700 (Tue, 08 Jul 2008) $ */
(function ()
{
/* constants */
var plid = '@bittorrent.com/BitTorrentDNA'; // not used at present
var mimeType = 'application/vnd.bittorrent-dna';
var control = 'npbtdna.BitTorrentDNA';
/* element types checked for class="btdna" */
var _btdna_tag_names = {'a': 1, 'embed': 1, 'object': 1, 'img': 1, 'iframe': 1};
/* forward declarations for local closures */
var _btdna_node;
var _btdna_init;
var _btdna_disabled;
/* state */
var _btdna_options = null;
var _btdna_startTime = null;
var _btdna_controlOptions = null;
var _btdna_controlStartTime = null;
/* TODO: randomize last quad in 127.0.0.? on Win32 and Linux to work around small browser connection queues */
/* this is a workaround so we can run our unit test using Rhino */
if (encodeURIComponent('=') == '%3d')
{
var brokenEncodeURIComponent = encodeURIComponent;
encodeURIComponent = function (s) {
return (('' + brokenEncodeURIComponent(s))
.replace(/%[0-9a-f][0-9a-f]/g,
(function (m)
{
return ('' + m).toUpperCase();
})));
};
}
btdna = function (spec)
{
var btdna_control = spec && spec.btdna_control;
if (arguments.length > 1)
{
var a = [];
for (var i = 0; i < arguments.length; i ++)
{
a[a.length] = arguments[i];
}
spec = a;
}
if ((typeof(spec) != 'undefined')
&&
(spec != null)
&&
((spec.nodeType == 1)
||
(spec.nodeType == 9)
||
(spec.nodeType == 11)))
{
return _btdna_node(spec);
}
_btdna_init(btdna_control);
if (spec == null)
{
spec = {};
}
if (typeof(spec) == typeof(''))
{
spec = [ spec ];
}
if ((typeof(spec) == typeof([]))
&&
(typeof(spec.length) == typeof(0)))
{
spec = { 'url': spec };
}
var copy = {};
var keys = [];
for (var k in spec)
{
keys[keys.length] = k;
}
keys = keys.sort();
for (var j = 0; j < keys.length; j ++)
{
var k = keys[j];
var kl = k.toLowerCase();
if (typeof(copy[kl]) == 'undefined')
{
copy[kl] = spec[k];
}
else
{
if ((typeof(copy[kl]) != typeof([]))
||
(typeof(copy[kl].length) != typeof(0)))
{
copy[kl] = [ copy[kl] ];
}
var v = spec[k];
if ((typeof(v) != typeof([]))
||
(typeof(v.length) != typeof(0)))
{
v = [ v ];
}
for (var i = 0; i < v.length; i ++)
{
copy[kl][copy[kl].length] = v[i];
}
}
}
if (! copy.url)
{
copy.url = [ '' ];
}
if (typeof(copy.url) == typeof(''))
{
copy.url = [ copy.url ];
}
spec = { 'url': {} };
for (var i = 0; i < copy.url.length; i ++)
{
var url = copy.url[i];
spec.url[url] = true;
var oldspec = btdna_control ? _btdna_controlOptions[url] : _btdna_options[url];
if (oldspec)
{
for (var k in oldspec)
{
if ((typeof(oldspec[k]) == typeof([]))
&&
(typeof(oldspec[k].length) == typeof(0)))
{
var l = 0;
if (typeof(spec[k]) == 'undefined')
{
spec[k] = [];
}
else if ((typeof(spec[k]) != typeof([]))
||
(typeof(spec[k].length) != typeof(0)))
{
if (typeof(spec[k]) == typeof({}))
{
for (var j in spec[k])
{
if (('' + parseInt('' + j)) == j)
{
if (l <= parseInt('' + j))
{
l = parseInt('' + j) + 1;
}
}
}
}
else
{
spec[k] = [ spec[k] ];
}
}
l = (typeof(spec[k].length) == typeof(0)) ? spec[k].length : l;
for (var j = 0; j < oldspec[k]; j ++)
{
spec[k][l] = oldspec[k][j];
l += 1;
}
}
else if (typeof(oldspec[k]) == typeof({}))
{
if (typeof(spec[k]) == 'undefined')
{
spec[k] = {};
}
else if ((typeof(spec[k]) == typeof([]))
&&
(typeof(spec[k].length) == typeof(0)))
{
var nspec = {};
for (var j = 0; j < spec[k].length; j ++)
{
nspec['' + j] = spec[k][j];
}
spec[k] = nspec;
}
else if (typeof(spec[k]) != typeof({}))
{
spec[k] = { '0': spec[k] };
}
for (var k2 in oldspec[k])
{
spec[k][k2] = oldspec[k][k2];
}
}
else
{
spec[k] = oldspec[k];
}
}
}
}
for (var k in copy)
{
if (k != 'url')
{
spec[k] = copy[k];
}
}
for (var k in spec.url)
{
if (spec.url[k] == true)
{
if (btdna_control)
{
_btdna_controlOptions[k] = spec;
}
else
{
_btdna_options[k] = spec;
}
}
}
copy = {};
for (var k in spec)
{
copy[k] = spec[k];
}
for (var k in (btdna_control ? _btdna_controlOptions[''] : _btdna_options['']))
{
if ((k == 'qos')
&&
(typeof(copy['duration']) != 'undefined'))
{
continue;
}
if (typeof(copy[k]) == 'undefined')
{
copy[k] = (btdna_control ? _btdna_controlOptions[''] : _btdna_options[''])[k];
}
}
var prefix = 'http://127.0.0.1:' + copy.port + '/proxy';
var urls = [];
for (var k in spec.url)
{
if (spec.url[k] == true)
{
urls[urls.length] = encodeURIComponent(k).split(encodeURIComponent('/')).join('/').split('%3A').join('%3a');
}
}
urls = urls.sort();
if ((typeof(copy.port) == 'undefined') || (urls.length && urls[0] && (decodeURIComponent(urls[0]).toLowerCase().indexOf('http:') != 0)))
{
return decodeURIComponent(urls[0]);
}
var extraparams = [];
for (var k in copy)
{
var v = copy[k];
if (! ({ port: true, qos: true, url: true, version: true, btdna_control: true })[k])
{
if ((typeof(v) != typeof([]))
||
(typeof(v.length) != typeof(1)))
{
v = [ v ];
}
var nv = [];
for (var iv = 0; iv < v.length; iv ++)
{
nv[nv.length] = v[iv];
}
v = nv.sort();
for (var iv = 0; iv < v.length; iv ++)
{
var vv = v[iv];
if ((typeof(vv) == typeof(''))
||
(typeof(vv) == typeof(1))
||
(typeof(vv) == typeof(1.0)))
{
extraparams[extraparams.length] = '&' + encodeURIComponent(k) + '=' + encodeURIComponent(vv);
}
}
}
}
extraparams = extraparams.sort().join('');
if ((urls.length > 1) || extraparams || (typeof(copy.qos) == 'undefined') ||
((typeof(copy.qos) == typeof([]))
&&
(typeof(copy.qos.length) == typeof(0))))
{
for (var i = 0; i < urls.length; i ++)
{
urls[i] = urls[i].replace(/%((25)*(26|3F))/g, '%25$1').split('&').join('%26').split('?').join('%3F');
}
if (typeof(copy.qos) == 'undefined')
{
copy.qos = [];
}
else if ((typeof(copy.qos) != typeof([]))
||
(typeof(copy.qos.length) != typeof(0)))
{
copy.qos = [ copy.qos ];
}
for (var j = 0; j < copy.qos.length; j ++)
{
copy.qos[j] = encodeURIComponent('' + copy.qos[j]);
}
copy.qos = copy.qos.sort();
var prefixForQoS = copy.qos.length ? ('qos=' + copy.qos.join('&qos=') + '&') : '';
return prefix + '?' + prefixForQoS + 'url=' + urls.join('&url=') + extraparams;
}
return prefix + '/' + encodeURIComponent('' + copy.qos) + '/' + urls.join('');
};
_btdna_init = function (btdna_control)
{
if (btdna_control)
{
if (_btdna_controlOptions && _btdna_controlOptions['']) return;
if (_btdna_disabled(btdna_control)) return;
_btdna_controlOptions = { '': { 'qos': 0 } };
}
else
{
if (_btdna_options && _btdna_options['']) return;
if (_btdna_disabled(btdna_control)) return;
_btdna_options = { '': { 'qos': 0 } };
}
var now = new Date;
if (((btdna_control ? _btdna_controlStartTime : _btdna_startTime) == null)
||
((btdna_control ? _btdna_controlStartTime : _btdna_startTime) > now))
{
if (btdna_control) _btdna_controlStartTime = now;
else _btdna_startTime = now;
}
// FIXME: really this should not be a busy-wait -- but rewriting
// later has higher cost due to reflowing, rerendering, etc., and
// can cause jarring resets.
while ((typeof((btdna_control ? _btdna_controlOptions[''] : _btdna_options['']).port) == 'undefined')
&&
(((new Date) - (btdna_control ? _btdna_controlStartTime : _btdna_startTime)) < 1.000e3))
{
var e;
try
{
var foundMimeType = false;
for (var iimt = 0; iimt < window.navigator.mimeTypes.length; iimt++)
{
if (window.navigator.mimeTypes[iimt].type.toLowerCase() == mimeType)
{
foundMimeType = true;
break;
}
}
if (! foundMimeType) throw('No plugin for ' + mimeType);
if (! window.navigator.mimeTypes[mimeType]) throw('No plugin for ' + mimeType);
var span = document.createElement('span');
var holder = document.body ? document.body : document.documentElement;
holder.insertBefore(span, holder.firstChild);
try
{
span.innerHTML = ('<' + 'embed type="' + mimeType + '" width="0" height="0">' +
'<' + '/embed>');
var npbtdna = span.firstChild;
while (((btdna_control ? npbtdna.ControlPort : npbtdna.Port) == null)
&&
self.opera
&&
(((new Date) - now) < 1.000e3))
{
}
if ((btdna_control ? npbtdna.ControlPort : npbtdna.Port) == null) throw('Port number not defined');
(btdna_control ? _btdna_controlOptions[''] : _btdna_options['']).port = (btdna_control ? npbtdna.ControlPort : npbtdna.Port);
(btdna_control ? _btdna_controlOptions[''] : _btdna_options['']).version = npbtdna.Version;
} finally {
span.parentNode.removeChild(span);
span = null;
}
}
catch(e)
{
var ee;
try
{
var npbtdna = new ActiveXObject(control);
if ((btdna_control ? npbtdna.ControlPort : npbtdna.Port) == null) throw('Port number not defined');
(btdna_control ? _btdna_controlOptions[''] : _btdna_options['']).port = (btdna_control ? npbtdna.ControlPort : npbtdna.Port);
(btdna_control ? _btdna_controlOptions[''] : _btdna_options['']).version = npbtdna.Version;
}
catch(ee)
{
}
}
}
};
_btdna_disabled = function (btdna_control)
{
var eeua;
try
{
// The plugin fails on at least some Vista Safari
// installations.
if (('' + navigator.userAgent).match(/(Windows NT 6\.0).*(AppleWebKit)\//))
{
return true;
}
}
catch (eeua)
{
}
return false;
};
btdna_reset = function (spec)
{
var btdna_control = spec && spec.btdna_control;
if (btdna(spec)) return;
if ( ( '' + navigator.userAgent ).match( /Windows NT 6/ ) )
{
if ( ( '' + navigator.userAgent ).match( /Firefox/ ) )
{
// temporarily workaround for Vista + Firefox problems
location.reload(true);
return;
}
}
if (btdna_control)
{
_btdna_controlOptions = null;
_btdna_controlStartTime = null;
}
else
{
_btdna_options = null;
_btdna_startTime = null;
}
};
btdna_poll = function (spec)
{
var btdna_control = spec && spec.btdna_control;
if (_btdna_disabled(btdna_control))
{
return false;
}
if ( typeof( ActiveXObject ) != 'undefined' )
{
var e;
try
{
var npbtdna = new ActiveXObject( control );
if (btdna_control ? ntbtdna.ControlPort : npbtdna.Port) return true;
}
catch (e)
{
}
}
var e;
try
{
navigator.plugins.refresh(false);
var foundMimeType = false;
for (var iimt = 0; iimt < window.navigator.mimeTypes.length; iimt++)
{
if (window.navigator.mimeTypes[iimt].type.toLowerCase() == mimeType)
{
foundMimeType = true;
break;
}
}
if (! foundMimeType) throw('No plugin for ' + mimeType);
if (! window.navigator.mimeTypes[mimeType]) throw('No plugin for ' + mimeType);
var span = document.createElement('span');
var holder = document.body ? document.body : document.documentElement;
holder.insertBefore(span, holder.firstChild);
try
{
span.innerHTML = ('<' + 'embed type="' + mimeType + '" width="0" height="0">' +
'<' + '/embed>');
var npbtdna = span.firstChild;
while (((btdna_control ? npbtdna.ControlPort : npbtdna.Port) == null)
&&
self.opera
&&
(((new Date) - now) < 1.000e3))
{
}
if ((btdna_control ? npbtdna.ControlPort : npbtdna.Port) == null) throw('Port number not defined');
if ((btdna_control ? npbtdna.ControlPort : npbtdna.Port)) return true;
} finally {
span.parentNode.removeChild(span);
span = null;
}
}
catch (e)
{
}
if (btdna(spec))
{
return true;
}
return false;
};
btdna_port = function (spec) {
var port = void (null);
if (btdna(spec)) port = (btdna(spec)).replace(/^http:\/\/127\.0\.0\.1:([^\/]*)\/.*/,'$1');
return port;
};
btdna_supported = function(spec) {
var btdna_control = spec && spec.btdna_control;
if (_btdna_disabled(btdna_control)) return false;
if ( ( '' + navigator.platform ) == 'Win32' ) {
if ( ( '' + navigator.userAgent ).match( /KHTML|AppleWebKit/ ) ) {
// Windows + Konqueror/Safari is not yet supported
return false;
}
if ( ( '' + navigator.userAgent ).match( /MSIE|Firefox/ ) ) {
// only Windows + MSIE/Firefox is officially supported
return true;
}
}
return false;
}
btdna_version = function (spec) {
var btdna_control = spec && spec.btdna_control;
var version = void (null);
if (btdna(spec)) version = (btdna_control ? _btdna_controlOptions[''] : _btdna_options['']).version;
return version;
};
btdna_js_revision = function () {
var e;
try
{
return (('$Rev: 12704 $'.split('$'))[1].split(' '))[1];
}
catch (e)
{
}
return void(null);
};
var _param_pat = '<param[ \\t\\n\\r](([^\\"\\\'>\/]*|\\"[^\\"]*\\"|\\\'[^\\\']*\\\')[ \\t\\n\\r])*(name[ \\t\\n\\r]*=[ \\t\\n\\r]*([\\"\\\']?)movie\\4[ \\t\\n\\r](([^\\"\\\'>\/]*|\\"[^\\"]*\\"|\\\'[^\\\']*\\\')[ \\t\\n\\r])*value[ \\t\\n\\r]*=[ \\t\\n\\r]*(\\\'([^\\\']+)\\\'|\\"([^\\"]+)\\"|[^ \\t\\n\\r>\/\\"\\\']+)|value[ \\t\\n\\r]*=[ \\t\\n\\r]*(\\\'([^\\\']+)\\\'|\\"([^\\"]+)\\"|[^ \\t\\n\\r>\/\\"\\\']+)[ \\t\\n\\r](([^\\"\\\'>\/]*|\\"[^\\"]*\\"|\\\'[^\\\']*\\\')[ \\t\\n\\r])*name[ \\t\\n\\r]*=[ \\t\\n\\r]*(\\"movie\\"|\\\'movie\\\'|movie[ \\t\\n\\r>\/]))';
var _param_gi_re = new RegExp(_param_pat, 'gi');
var _param_i_re = new RegExp(_param_pat, 'i');
_btdna_node = function (spec)
{
for (var tagName in _btdna_tag_names)
{
var nodes = spec.getElementsByTagName(tagName);
var fixNodes = [];
for (var i = 0; i < nodes.length; i ++)
{
var e;
try
{
var node = nodes[i];
if ((! node.namespaceURI)
||
(node.namespaceURI == 'http://www.w3.org/1999/xhtml'))
{
var className = node.className ? node.className : node.getAttribute('class');
className = className ? className : '';
className = '' + className;
var newClassName = className.replace(/(^|[ \t\n\r])btdna([ \t\n\r]|$)/gi, '$1$2');
if (className != newClassName)
{
fixNodes[fixNodes.length] = node;
var ee;
try
{
node.setAttribute('class', newClassName);
}
catch (ee)
{
}
node.className = newClassName;
}
}
}
catch (e)
{
}
}
for (var i = 0; i < fixNodes.length; i ++)
{
var e;
try
{
var node = fixNodes[i];
if (tagName == 'a')
{
node.href = btdna(node.href);
}
else if ((tagName == 'embed')
||
(tagName == 'img')
||
(tagName == 'iframe'))
{
node.src = btdna(node.src);
if (tagName == 'iframe')
{
node.location = btdna(node.location);
}
}
else if ((tagName == 'object')
&&
node.getAttribute('classid')
&&
(node.getAttribute('classid').toLowerCase().split('-').join('')
==
'clsid:d27cdb6eae6d11cf96b8444553540000'))
{
node.innerHTML = node.innerHTML.replace(
_param_gi_re,
function (s)
{
s = '' + s;
m = s.match(_param_i_re);
var movie = m[12] || m[11] || m[10] || m[9] || m[8] || m[7];
var omovie = movie;
movie = movie.split('"').join('"').split(''').join("'").split('>').join('>').split('<').join('<').split('&').join('&').replace(
/�*([1-9][0-9]*);/g,
(function (m)
{
return encodeURIComponent(String.fromCharCode(parseInt(m[1])));
})).replace(
/&#[xX]0*([1-9a-fA-F][0-9a-fA-F]*);/g,
(function (m)
{
return encodeURIComponent(String.fromCharCode(parseInt(m[1], 16)));
}));
movie = btdna(movie);
movie = movie.split('&').join('&').split('<').join('<').split('>').join('>').split('"').join('"').split("'").join(''');
return s.split(omovie).join(movie);
});
}
}
catch (e)
{
}
}
}
return spec;
};
var _btdna_test = function ()
{
var old_btdna_options = _btdna_options;
var e;
try
{
var testno = 0;
var assert_equal_eval = function (a, b)
{
var _eval_a = eval(a);
var _eval_b = eval(b);
if (_eval_a != _eval_b)
{
throw("assertion failure in test " + testno + ": " + a + " (" + _eval_a + ") != " + b + " (" + _eval_b + ")");
}
testno ++;
};
fakedom = {
nodeType: 1,
getElementsByTagName: function (tn)
{
if (tn == 'object') return [ this ];
return [];
},
innerHTML: '<param name="movie" value="http://my/swf/url" />',
getAttribute: function (an)
{
if (an == 'classid')
{
return 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
}
}
};
/* test 0 */ _btdna_options = { '': { 'qos': 0 } }; assert_equal_eval("btdna()", "''");
assert_equal_eval("btdna('http://my/own/url')", "'http://my/own/url'");
assert_equal_eval("btdna('http://127.0.0.1:0/proxy/0/')", "'http://127.0.0.1:0/proxy/0/'");
assert_equal_eval("btdna('http://127.0.0.1:0/proxy/0/http%3a//my/own/url')", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna('http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url')", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna(['http://127.0.0.1:0/proxy/0/','http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'])", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
fakedom.className = 'btdna'; assert_equal_eval("btdna(fakedom).innerHTML", "'<param name=\"movie\" value=\"http://my/swf/url\" />'");
fakedom.className = 'btdna'; assert_equal_eval("btdna(fakedom).className", "''");
_btdna_options = { '': { 'qos': 0, 'port': 0 } }; assert_equal_eval("btdna()", "'http://127.0.0.1:0/proxy/0/'");
assert_equal_eval("btdna({qos:1})", "'http://127.0.0.1:0/proxy/1/'");
assert_equal_eval("btdna()", "'http://127.0.0.1:0/proxy/1/'");
assert_equal_eval("btdna({qos:0})", "'http://127.0.0.1:0/proxy/0/'");
assert_equal_eval("btdna()", "'http://127.0.0.1:0/proxy/0/'");
assert_equal_eval("btdna('http://my/own/url')", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna('http://127.0.0.1:0/proxy/0/')", "'http://127.0.0.1:0/proxy/0/http%3a//127.0.0.1%3a0/proxy/0/'");
assert_equal_eval("btdna('http://127.0.0.1:0/proxy/0/http%3a//my/own/url')", "'http://127.0.0.1:0/proxy/0/http%3a//127.0.0.1%3a0/proxy/0/http%253a//my/own/url'");
assert_equal_eval("btdna('http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url')", "'http://127.0.0.1:0/proxy/0/http%3a//127.0.0.1%3a0/proxy%3Fqos%3D0%26url%3Dhttp%253a//another/url/for/the/same/thing%26url%3Dhttp%253a//my/other/url'");
assert_equal_eval("btdna(['http://127.0.0.1:0/proxy/0/','http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'])", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//127.0.0.1%3a0/proxy%253Fqos%3D0%2526url%3Dhttp%253a//another/url/for/the/same/thing%2526url%3Dhttp%253a//my/other/url&url=http%3a//127.0.0.1%3a0/proxy/0/'");
assert_equal_eval("btdna(['http://my/own/url'])", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna({url:'http://my/own/url'})", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna({url:'http://my/own/stream',service:'STREAMING'})", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//my/own/stream&service=STREAMING'");
assert_equal_eval("btdna({url:['http://my/own/url']})", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna({url:'http://my/own/url',qos:1})", "'http://127.0.0.1:0/proxy/1/http%3a//my/own/url'");
assert_equal_eval("btdna({url:['http://my/own/url'],qos:1})", "'http://127.0.0.1:0/proxy/1/http%3a//my/own/url'");
assert_equal_eval("btdna('http://my/own/url')", "'http://127.0.0.1:0/proxy/1/http%3a//my/own/url'");
assert_equal_eval("btdna(['http://my/own/url'])", "'http://127.0.0.1:0/proxy/1/http%3a//my/own/url'");
assert_equal_eval("btdna({url:'http://my/own/url'})", "'http://127.0.0.1:0/proxy/1/http%3a//my/own/url'");
assert_equal_eval("btdna({url:['http://my/own/url']})", "'http://127.0.0.1:0/proxy/1/http%3a//my/own/url'");
assert_equal_eval("btdna({url:'http://my/own/url',qos:0})", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna({url:['http://my/own/url'],qos:0})", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna('http://my/own/url')", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna(['http://my/own/url'])", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna({url:'http://my/own/url'})", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna({url:['http://my/own/url']})", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna('http://my/other/url','http://another/url/for/the/same/thing')", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna(['http://my/other/url','http://another/url/for/the/same/thing'])", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna({url:['http://my/other/url','http://another/url/for/the/same/thing']})", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna({url:'http://my/other/url',qos:1})", "'http://127.0.0.1:0/proxy?qos=1&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna({url:['http://my/other/url','http://another/url/for/the/same/thing']})", "'http://127.0.0.1:0/proxy?qos=1&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna({url:'http://another/url/for/the/same/thing',qos:0})", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna({url:['http://my/other/url','http://another/url/for/the/same/thing']})", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url'");
assert_equal_eval("btdna({url:['http://my/own/url']})", "'http://127.0.0.1:0/proxy/0/http%3a//my/own/url'");
assert_equal_eval("btdna({url:['http://my/own/url','http://another/url/for/the/same/thing']})", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url&url=http%3a//my/own/url'");
fakedom.className = 'btdna'; assert_equal_eval("btdna(fakedom).innerHTML", "'<param name=\"movie\" value=\"http://127.0.0.1:0/proxy/0/http%3a//my/swf/url\" />'");
fakedom.className = 'btdna'; assert_equal_eval("btdna(fakedom).className", "''");
assert_equal_eval("btdna({url:'http://with/duration/',duration:'330'})", "'http://127.0.0.1:0/proxy?url=http%3a//with/duration/&duration=330'");
assert_equal_eval("btdna({URL:'http://with/duration/',Duration:'330'})", "'http://127.0.0.1:0/proxy?url=http%3a//with/duration/&duration=330'");
assert_equal_eval("btdna({url:'http://my/own/url',Url:'http://another/url/for/the/same/thing'})", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url&url=http%3a//my/own/url'");
assert_equal_eval("btdna({Url:'http://my/own/url',url:'http://another/url/for/the/same/thing'})", "'http://127.0.0.1:0/proxy?qos=0&url=http%3a//another/url/for/the/same/thing&url=http%3a//my/other/url&url=http%3a//my/own/url'");
assert_equal_eval("btdna({url:'http://yet/another/url',qos:1,QoS:2})", "'http://127.0.0.1:0/proxy?qos=1&qos=2&url=http%3a//yet/another/url'");
assert_equal_eval("btdna({url:'http://yet/another/url',qos:[2,1]})", "'http://127.0.0.1:0/proxy?qos=1&qos=2&url=http%3a//yet/another/url'");
assert_equal_eval("btdna({url:'http://yet/another/url',qos:[2,1],QoS:3})", "'http://127.0.0.1:0/proxy?qos=1&qos=2&qos=3&url=http%3a//yet/another/url'");
assert_equal_eval("btdna({URL:'http://with/duration/',duration:220,Duration:'330'})", "'http://127.0.0.1:0/proxy?url=http%3a//with/duration/&duration=220&duration=330'");
assert_equal_eval("btdna({URL:'http://with/duration/',duration:[220,'330']})", "'http://127.0.0.1:0/proxy?url=http%3a//with/duration/&duration=220&duration=330'");
assert_equal_eval("btdna({URL:'http://with/duration/',duration:[330,220]})", "'http://127.0.0.1:0/proxy?url=http%3a//with/duration/&duration=220&duration=330'");
} catch(e) {
_btdna_options = old_btdna_options;
throw(e);
}
_btdna_options = old_btdna_options;
};
var eet
try
{
_btdna_test();
}
catch (eet)
{
if (typeof(WScript) != 'undefined')
{
WScript.StdErr.WriteLine('' + eet);
WScript.Quit(1);
}
throw(eet);
}
var _btdna_watcher;
if ((typeof(setInterval) != 'undefined')
&&
(typeof(clearInterval) != 'undefined'))
{
_btdna_watcher = setInterval('btdna(document.body?document.body:document.documentElement);', 0.200e3);
if (typeof(addEventListener) != 'undefined')
{
addEventListener('load', function () { clearInterval(_btdna_watcher); btdna(document.body?document.body:document.documentElement); }, true);
}
else if (typeof(attachEvent) != 'undefined')
{
if ((typeof(document.readyState) != 'undefined')
&&
(typeof(document.attachEvent) != 'undefined'))
{
document.attachEvent('onreadystatechange', function () { if (document.readyState == 'complete') clearInterval(_btdna_watcher); btdna(document.body?document.body:document.documentElement); });
}
attachEvent('onload', function () { clearInterval(_btdna_watcher); btdna(document.body?document.body:document.documentElement); });
}
else
{
setTimeout('clearInterval(' + _btdna_watcher + ');btdna(document.body?document.body:document.documentElement);', 10.000e3);
}
}
var _btdna_document_write_probe = function () {
var eedwt;
try
{
var foundMimeType = false;
for (var iimt = 0; iimt < window.navigator.mimeTypes.length; iimt++)
{
if (window.navigator.mimeTypes[iimt].type.toLowerCase() == mimeType)
{
foundMimeType = true;
break;
}
}
if (! foundMimeType) throw('No plugin for ' + mimeType);
if (! window.navigator.mimeTypes[mimeType]) throw('No plugin for ' + mimeType);
var nonce = 'btdna' + Math.random().toString().substr(2);
try
{
var eedw;
try
{
document.write('<' + 'embed id="' + nonce + '" type="' + mimeType + '" width="0" height="0">' +
'<' + '/embed>');
}
catch (eedw)
{
}
} finally {
var eedwd;
try
{
var alternative_embedding = document.getElementById(nonce);
if (alternative_embedding) alternative_embedding.parentNode.removeChild(alternative_embedding);
alternative_embedding = null;
}
catch (eedwd)
{
}
}
}
catch (eedwt)
{
}
};
_btdna_document_write_probe();
})();DNA-javascript
No comments:
Post a Comment
Thanks friend !!!