stuppid_bot

Untitled

Apr 3rd, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var lite = isLite();
  2. localStorage.lite = lite ? '1' : '0';
  3. var helper = lite ? 'chromelite' : 'chrome';
  4.  
  5. // default preferences
  6. var default_preferences = {
  7.   version: 0,
  8.   enable: 1,
  9.   lmFileHosting: 1,
  10.   lmMediaHosting: 1,
  11.   moduleYoutube: 1,
  12.   moduleDailymotion: 1,
  13.   moduleVimeo: 1,
  14.   moduleVkontakte: 1,
  15.   moduleOdnoklassniki: 1,
  16.   moduleShowDownloadInfo: 1,
  17.   ytHideFLV: 0,
  18.   ytHideMP4: 0,
  19.   ytHideWebM: 1,
  20.   ytHide3GP: 1,
  21.   ytHide3D: 1,
  22.   vkShowBitrate: 0
  23. };
  24.  
  25. var pref_names = {
  26.   youtube: 'moduleYoutube',
  27.   dailymotion: 'moduleDailymotion',
  28.   vimeo: 'moduleVimeo',
  29.   vk: 'moduleVkontakte',
  30.   odnoklassniki: 'moduleOdnoklassniki'
  31. };
  32.  
  33. // localStorage == widget.preferences
  34. for (var k in default_preferences)
  35. {
  36.   if (!(k in localStorage))
  37.     localStorage[k] = default_preferences[k]; // set default preference
  38. }
  39.  
  40. // modules[tab.id] = moduleName
  41. var modules = {};
  42. chrome.tabs.onRemoved.addListener(function(tabId){
  43.   if (tabId in modules)
  44.     delete modules[tabId];
  45. });
  46.  
  47. // routes[action] = handler
  48. // handler - function(request, sender) {
  49. //  ... code ...
  50. //  return response;
  51. // }
  52. var routes = {
  53.   initModule: function (request, sender, callback)
  54.   {
  55.     var response = {};
  56.     var moduleName = request.moduleName;
  57.  
  58.     if (sender.tab)
  59.     {
  60.       modules[sender.tab.id] = moduleName;
  61.  
  62.       response.lite = lite;
  63.       response.moduleEnable = localStorage.enable == '1';
  64.       response.moduleShowDownloadInfo = localStorage.moduleShowDownloadInfo == '1';
  65.  
  66.       var info = chrome.app.getDetails();
  67.       response.version = info.version;
  68.  
  69.       if (moduleName == 'lm')
  70.       {
  71.         response.moduleEnable &= localStorage.lmFileHosting == '1'
  72.           || localStorage.lmMediaHosting == '1';
  73.  
  74.         response.lmMediaHosting = localStorage.lmMediaHosting;
  75.         response.lmFileHosting = localStorage.lmFileHosting;
  76.       }
  77.       else if(moduleName != 'savefrom')
  78.       {
  79.         response.moduleEnable &= localStorage[pref_names[moduleName]] == '1';
  80.  
  81.         response.ytHideFLV = localStorage.ytHideFLV;
  82.         response.ytHideMP4 = localStorage.ytHideMP4;
  83.         response.ytHideWebM = localStorage.ytHideWebM;
  84.         response.ytHide3GP = localStorage.ytHide3GP;
  85.         response.ytHide3D = localStorage.ytHide3D;
  86.  
  87.         if(moduleName == 'vk')
  88.         {
  89.           response.vkShowBitrate = localStorage.vkShowBitrate;
  90.         }
  91.       }
  92.     }
  93.  
  94.     callback(response);
  95.   },
  96.  
  97.  
  98.   hideDownloadInfo: function(request, sender){
  99.     localStorage.moduleShowDownloadInfo = '0';
  100.   },
  101.  
  102.  
  103.   getVimeoLinks: function (request, sender, callback)
  104.   {
  105.     function callback_links(links, title)
  106.     {
  107.       var response = {
  108.         action: request.action,
  109.         extVideoId: request.extVideoId,
  110.         links: links,
  111.         title: title
  112.       };
  113.  
  114.       callback(response);
  115.     }
  116.  
  117.     getVimeoLinks(request.extVideoId, callback_links);
  118.   },
  119.  
  120.  
  121.   getVKLinks: function (request, sender, callback)
  122.   {
  123.     function callback_links(vid, links, title)
  124.     {
  125.       var response = {
  126.         action: request.action,
  127.         extVideoId: vid ? vid : request.extVideoId,
  128.         links: links,
  129.         title: title
  130.       };
  131.  
  132.       callback(response);
  133.     }
  134.  
  135.     getVKLinks(request.extVideoId, callback_links);
  136.   },
  137.  
  138.  
  139.   getYoutubeLinks: function (request, sender, callback)
  140.   {
  141.     function callback_links(links, title, subtitles)
  142.     {
  143.       var response = {
  144.         action: request.action,
  145.         extVideoId: request.extVideoId,
  146.         links: links,
  147.         title: title,
  148.         subtitles: subtitles
  149.       };
  150.  
  151.       callback(response);
  152.     }
  153.  
  154.     getYoutubeLinks(sender.tab.url, request.extVideoId, request.checkSubtitles, callback_links);
  155.   },
  156.  
  157.  
  158.   getOdnoklassnikiLinks: function (request, sender, callback)
  159.   {
  160.     function callback_links(links)
  161.     {
  162.       var response = {
  163.         action: request.action,
  164.         extVideoId: request.extVideoId,
  165.         links: links,
  166.         title: request.title
  167.       };
  168.  
  169.       callback(response);
  170.     }
  171.  
  172.     getOdnoklassnikiLinks(request.extVideoId, callback_links);
  173.   },
  174.  
  175.  
  176.   getOdnoklassnikiAudioLinks: function (request, sender, callback)
  177.   {
  178.     function callback_links(data)
  179.     {
  180.       var response = {
  181.         action: request.action,
  182.         trackId: request.trackId,
  183.         jsessionId: request.jsessionId,
  184.         data: data
  185.       };
  186.  
  187.       callback(response);
  188.     }
  189.  
  190.     getOdnoklassnikiAudioLinks(sender.tab.url, request.trackId, request.jsessionId, callback_links);
  191.   },
  192.  
  193.  
  194.   getFileSize: function (request, sender, callback)
  195.   {
  196.     getFileSize(request.url, callback);
  197.   }
  198. };
  199.  
  200.  
  201. // content scripts dispatcher
  202. chrome.extension.onRequest.addListener(function(request, sender, callback){
  203.   //console.log('dispatcher', request, sender, callback);
  204.   routes[request.action](request, sender, callback);
  205. });
  206.  
  207.  
  208. // is lite version
  209. function isLite()
  210. {
  211.   var info = chrome.app.getDetails();
  212.   if(info && info.name && info.name.search(/\s+lite/i) > -1)
  213.     return true;
  214.  
  215.   return false;
  216. }
  217.  
  218.  
  219. // actions from menu
  220. function enableExtension()
  221. {
  222.   localStorage.enable = (localStorage.enable == '0') ? '1' : '0';
  223.   setButtonParams();
  224. }
  225.  
  226.  
  227. function downloadFromCurrentPage()
  228. {
  229.   chrome.tabs.getSelected(null, function(tab)
  230.   {
  231.     var url = 'http://savefrom.net/?url=' + encodeURIComponent(tab.url) +
  232.       '&utm_source=' + helper + '&utm_medium=extensions&utm_campaign=bookmarklet';
  233.  
  234.     chrome.tabs.create({url: url, selected: true});
  235.   });
  236. }
  237.  
  238.  
  239. // tab actions
  240.  
  241. var tabActions = ['updateLinks', 'downloadPlaylist', 'downloadMP3Files'];
  242.  
  243. function tabAction(request, tab)
  244. {
  245.   if (tab)
  246.   {
  247.     chrome.tabs.sendRequest(tab.id, request);
  248.   }
  249.   else
  250.   {
  251.     chrome.tabs.getSelected(null, function(tab){
  252.       chrome.tabs.sendRequest(tab.id, request);
  253.     });
  254.   }
  255. }
  256.  
  257. function createAction(name, tab)
  258. {
  259.   return function(){
  260.     tabAction({action: name}, tab);
  261.   };
  262. }
  263.  
  264. for (var i = 0; i < tabActions.length; i++)
  265. {
  266.   var actionName = tabActions[i];
  267.   window[actionName] = createAction(actionName);
  268. }
  269.  
  270.  
  271. // ---------
  272.  
  273. setButtonParams();
  274.  
  275. if(localStorage.enable != '0')
  276.   checkVersion();
  277.  
  278. function setButtonParams()
  279. {
  280.   var icon = {path: 'images/icon_18.png'};
  281.   var title = {title: chrome.i18n.getMessage("titleDefault")};
  282.  
  283.   if(localStorage.enable == '0')
  284.   {
  285.     title.title = chrome.i18n.getMessage("titleDesabled");
  286.     icon.path = 'images/icon_disabled_18.png';
  287.   }
  288.  
  289.   chrome.browserAction.setIcon(icon);
  290.   chrome.browserAction.setTitle(title);
  291. }
  292.  
  293.  
  294. function fixPref(pref)
  295. {
  296.   for(i = 0; i < pref.length; i++)
  297.   {
  298.     if(localStorage[pref[i].name] != pref[i].check)
  299.       localStorage[pref[i].name] = pref[i].def;
  300.   }
  301. }
  302.  
  303.  
  304. function checkVersion()
  305. {
  306.   var url = '';
  307.   var info = chrome.app.getDetails();
  308.  
  309.   if(!localStorage.version || localStorage.version == '0')
  310.   {
  311.     // first run
  312.     url = 'http://savefrom.net/user.php?helper=' + helper + ';firstrun';
  313.   }
  314.   else if(localStorage.version != info.version)
  315.   {
  316.     // update
  317.     //url = 'http://savefrom.net/user.php?helper=' + helper + ';update';
  318.   }
  319.  
  320.   if(url)
  321.   {
  322.     localStorage.version = info.version;
  323.     chrome.tabs.create({url: url, selected: true});
  324.   }
  325. }
  326.  
  327.  
  328. function sendRequest(url, callback, method, referer, post, cookie, header)
  329. {
  330.   var req = new XMLHttpRequest();
  331.   if (!req)
  332.     return;
  333.  
  334.   method = method ? method : ((post) ? 'POST' : 'GET');
  335.  
  336.   req.open(method, url, true);
  337.  
  338.   if(referer)
  339.     req.setRequestHeader('Referer', referer);
  340.  
  341.   if(cookie)
  342.     req.setRequestHeader('Cookie', cookie);
  343.  
  344.   if(post)
  345.   {
  346.     req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  347.     req.setRequestHeader("Content-Length", post.length);
  348.   }
  349.  
  350.   if(header)
  351.   {
  352.     for(var i = 0; i < header.length; i++)
  353.     {
  354.       req.setRequestHeader(header[i][0], header[i][1]);
  355.     }
  356.   }
  357.  
  358.   req.onreadystatechange = function ()
  359.   {
  360.     if (req.readyState != 4)
  361.       return;
  362.  
  363.     callback(req);
  364.   };
  365.  
  366.   if (req.readyState == 4)
  367.   {
  368.     return;
  369.   }
  370.  
  371.   if(post)
  372.     req.send(post);
  373.   else
  374.     req.send();
  375. }
  376.  
  377.  
  378. function getFileSize(url, callback, referer, cookie, header)
  379. {
  380.   sendRequest(url, function(req){
  381.     var response = {
  382.       fileSize: 0,
  383.       fileType: ''
  384.     };
  385.  
  386.     if (req.status == 200)
  387.     {
  388.       var s = req.getResponseHeader('Content-Length');
  389.       if(s)
  390.       {
  391.         s = parseInt(s);
  392.         if(!isNaN(s))
  393.           response.fileSize = s;
  394.       }
  395.  
  396.       var t = req.getResponseHeader('Content-Type');
  397.       if(t)
  398.         response.fileType = t;
  399.     }
  400.  
  401.     callback(response);
  402.  
  403.   }, 'HEAD', referer, null, cookie, header);
  404. }
  405.  
  406.  
  407. function getVimeoLinks(videoId, callback)
  408. {
  409.   var links = [], title = '';
  410.  
  411.   sendRequest('http://vimeo.com/moogaloop/load/clip:' + videoId + '/', function(r){
  412.     try
  413.     {
  414.       if(r.status == 200 && r.responseXML)
  415.       {
  416.         var sig = r.responseXML.querySelector('request_signature');
  417.         if(sig && sig.firstChild.nodeValue)
  418.         {
  419.           if(sig)
  420.           {
  421.             var url = 'http://vimeo.com/moogaloop/play/clip:' +
  422.               videoId + '/' + sig.firstChild.nodeValue + '/';
  423.  
  424.             var sigExp = r.responseXML.querySelector('request_signature_expires');
  425.             if(sigExp && sigExp.firstChild.nodeValue)
  426.               url += sigExp.firstChild.nodeValue + '/';
  427.  
  428.             var t = r.responseXML.querySelector('video caption');
  429.             if(t && t.firstChild.nodeValue)
  430.               title = t.firstChild.nodeValue;
  431.  
  432.             links.push({
  433.               url: url + '?q=sd',
  434.               name: 'SD',
  435.               type: 'mp4',
  436.               ext: 'MP4'
  437.             });
  438.  
  439.             var hd = r.responseXML.querySelector('isHD');
  440.             if(hd && hd.firstChild.nodeValue == '1')
  441.             {
  442.               links.push({
  443.                 url: url + '?q=hd',
  444.                 name: 'HD',
  445.                 type: 'mp4',
  446.                 ext: 'MP4'
  447.               });
  448.             }
  449.           }
  450.         }
  451.       }
  452.     }
  453.     finally
  454.     {
  455.       if(links.length)
  456.         callback(links, title);
  457.       else
  458.         getVimeoNoEmbedLinks(videoId, callback);
  459.     }
  460.   });
  461. }
  462.  
  463.  
  464. function getVimeoNoEmbedLinks(videoId, callback)
  465. {
  466.   var links = [], title = '';
  467.  
  468.   sendRequest('http://vimeo.com/' + videoId, function(r){
  469.     try
  470.     {
  471.       if(r.status == 200 && r.responseText)
  472.       {
  473.         var re = new RegExp('clip' + videoId + '_\\d+\\s*=\\s*(\\{[\\s\\S]+?\\})\\s*;', 'i');
  474.  
  475.         var config = r.responseText.match(re);
  476.         if(config && config.length > 1)
  477.         {
  478.           config = config[1].replace(/(\{|,)\s*(\w+)\s*:/ig, '$1"$2":').
  479.             replace(/(:\s+)\'/g, '$1"').replace(/\'([,\]\}])/g, '"$1');
  480.           config = JSON.parse(config);
  481.           config = config.config;
  482.  
  483.           if(config && config.request && config.video &&
  484.             config.request.signature && config.request.timestamp)
  485.           {
  486.             var data = {
  487.               'clip_id': videoId,
  488.               'sig': config.request.signature,
  489.               'time': config.request.timestamp,
  490.               'type': 'moogaloop_local',
  491.               'quality': 'sd',
  492.               'codecs': 'H264,VP8,VP6'
  493.             };
  494.  
  495.             var title = config.video.title ? config.video.title : '';
  496.  
  497.             links.push({
  498.               url: 'http://player.vimeo.com/play_redirect?' + getQueryString(data),
  499.               name: 'SD',
  500.               type: 'mp4',
  501.               ext: 'MP4'
  502.             });
  503.  
  504.             if(config.video.hd == 1)
  505.             {
  506.               data.quality = 'hd';
  507.               links.push({
  508.                 url: 'http://player.vimeo.com/play_redirect?' + getQueryString(data),
  509.                 name: 'HD',
  510.                 type: 'mp4',
  511.                 ext: 'MP4'
  512.               });
  513.             }
  514.  
  515.             if(config.video.files && config.video.files.h264)
  516.             {
  517.               var files = config.video.files.h264;
  518.               if(files.length > 0)
  519.               {
  520.                 for(var i = 0; i < files.length; i++)
  521.                 {
  522.                   if(files[i] != 'sd' && files[i] != 'hd')
  523.                   {
  524.                     data.quality = files[i];
  525.                     links.push({
  526.                       url: 'http://player.vimeo.com/play_redirect?' + getQueryString(data),
  527.                       name: (files[i].length <= 3) ? files[i].toUpperCase() : ucfirst(files[i].toLowerCase()),
  528.                       type: 'mp4',
  529.                       ext: 'MP4'
  530.                     });
  531.                   }
  532.                 }
  533.               }
  534.             }
  535.           }
  536.         }
  537.       }
  538.     }
  539.     finally
  540.     {
  541.       callback(links, title);
  542.     }
  543.   });
  544. }
  545.  
  546.  
  547. function getVKLinks(videoId, callback)
  548. {
  549.   var links = {}, title = '';
  550.  
  551.   var vid = videoId;
  552.   if(vid.search(/^video-?\d+_\d+/i) == -1)
  553.   {
  554.     var oid = '', id = '';
  555.     var m = vid.match(/(?:^|&)oid=(-?\d+)/i);
  556.     if(m && m.length > 1)
  557.       oid = m[1];
  558.  
  559.     m = vid.match(/(?:^|&)id=(-?\d+)/i);
  560.     if(m && m.length > 1)
  561.       id = m[1];
  562.  
  563.     vid = '';
  564.     if(oid && id)
  565.       vid = 'video' + oid + '_' + id;
  566.   }
  567.  
  568.   if(!vid)
  569.   {
  570.     callback(vid, links, title);
  571.     return;
  572.   }
  573.  
  574.   var url = 'http://vk.com/' + vid;
  575.  
  576.   sendRequest(url, function(r){
  577.     try
  578.     {
  579.       if(r.status == 200 && r.responseText)
  580.       {
  581.         var json = r.responseText.match(/var vars\s*=\s*(\{[^\}]+\})/i);
  582.         if(json)
  583.         {
  584.           try
  585.           {
  586.             json = json[1];
  587.  
  588.             if(json.search(/^\{\s*\\\"/) > -1)
  589.               json = json.replace(/\\\"/g, '"');
  590.  
  591.             json = JSON.parse(json);
  592.             if(json)
  593.             {
  594.               links = json;
  595.             }
  596.           }
  597.           catch(err){}
  598.         }
  599.       }
  600.     }
  601.     finally
  602.     {
  603.       callback(vid, links, title);
  604.     }
  605.   });
  606. }
  607.  
  608.  
  609. function getYoutubeLinks(eurl, videoId, checkSubtitles, callback) {
  610.   var links = {}, title = '';
  611.   eurl = encodeURIComponent(eurl);
  612.   var url = 'http://www.youtube.com/get_video_info?video_id=' + videoId +
  613.     '&asv=3&eurl=' + eurl + '&el=embedded';
  614.  
  615.   var cookies = 'VISITOR_INFO1_LIVE=; PREF=; GEO=; use_hitbox=';
  616.  
  617.   sendRequest(url, function(r){
  618.     try
  619.     {
  620.       if(r.status == 200 && r.responseText)
  621.       {
  622.         var fmtMap = r.responseText.match(
  623.           /(?:^|&)(?:fmt_url_map|url_encoded_fmt_stream_map)=([^\s\&\"]+)/i);
  624.  
  625.         if(fmtMap && fmtMap.length > 1)
  626.         {
  627.           title = r.responseText.match(/(?:^|&)title=([^\s\&\"]+)/i);
  628.           var titleParam = '';
  629.           if(title)
  630.           {
  631.             title = title[1].replace(/\+/g, '%20');
  632.             title = decodeURIComponent(title).
  633.               replace(/[\x2F\x5C\x3A\x7C]/g, '-').
  634.               replace(/[\x2A\x3F]/g, '').
  635.               replace(/\x22/g, '\'').
  636.               replace(/\x3C/g, '(').
  637.               replace(/\x3E/g, ')').
  638.               replace(/(?:^\s+)|(?:\s+$)/g, '');
  639.  
  640.             titleParam = '&title=' + encodeURIComponent(title);
  641.           }
  642.  
  643.           var l = {};
  644.  
  645.           fmtMap = fmtMap[1];
  646.  
  647.           if(fmtMap.search(/url(=|%3d)http/i) > -1)
  648.           {
  649.             if(fmtMap.search(/url%3dhttp/i) > -1)
  650.               fmtMap = decodeURIComponent(fmtMap);
  651.  
  652.             fmtMap = fmtMap.split(',');
  653.             for(var i = 0; i < fmtMap.length; ++i)
  654.             {
  655.               var query = parseQuery(fmtMap[i]);
  656.               if(query.url)
  657.               {
  658.                 query.url = decodeURIComponent(query.url);
  659.                 if(query.url.search(/(\?|&)sig(nature)?=/i) == -1)
  660.                 {
  661.                   if(query.sig)
  662.                     query.url += '&signature=' + query.sig;
  663.                   else if(query.signature)
  664.                     query.url += '&signature=' + query.signature;
  665.                 }
  666.  
  667.                 if(query.url.search(/(\?|&)itag=/i) == -1)
  668.                 {
  669.                   if(query.itag)
  670.                     query.url += '&itag=' + query.itag;
  671.                 }
  672.  
  673.                 var fmt = query.url.match(/(?:\?|&)itag=(\d+)/i);
  674.                 if(fmt && fmt.length > 1)
  675.                 {
  676.                   fmt = fmt[1];
  677.  
  678.                   query.url = query.url.replace(/(\?|&)sig=/i, '$1signature=').
  679.                     replace(/\\u0026/ig, '&').replace(/\\\//g, '/');
  680.  
  681.                   l[fmt] = query.url;
  682.  
  683.                   if(titleParam)
  684.                     l[fmt] += titleParam;
  685.                 }
  686.               }
  687.             }
  688.           }
  689.           else
  690.           {
  691.             fmtMap = decodeURIComponent(fmtMap);
  692.             fmtMap = fmtMap.replace(/\\u0026/ig, '&').replace(/\\\//g, '/');
  693.             fmtMap = fmtMap.replace(/,(\d+)\|/g, "\n$1|");
  694.             fmtMap = fmtMap.split('\n');
  695.  
  696.             for(var i = 0; i < fmtMap.length; i++)
  697.             {
  698.               var t = fmtMap[i].split('|');
  699.               if(t && t.length >= 2)
  700.               {
  701.                 l[t[0]] = t[1];
  702.                 if(titleParam)
  703.                   l[t[0]] += titleParam;
  704.               }
  705.             }
  706.           }
  707.  
  708.           if(l)
  709.             links = l;
  710.         }
  711.       }
  712.     }
  713.     finally
  714.     {
  715.       if(checkSubtitles)
  716.       {
  717.         checkYoutubeSubtitles(videoId, function(subtitles){
  718.           callback(links, title, subtitles);
  719.         });
  720.       }
  721.       else
  722.         callback(links, title, null);
  723.     }
  724.   }, '', url, '', cookies);
  725. }
  726.  
  727.  
  728. function checkYoutubeSubtitles(videoId, callback)
  729. {
  730.   var url = 'http://video.google.com/timedtext?hl=en&v=' + videoId +
  731.     '&type=list&tlangs=1';
  732.  
  733.   sendRequest(url, function(r){
  734.     var result = false;
  735.     if(r.status == 200 && r.responseXML)
  736.     {
  737.       if(r.responseXML.querySelector('target, track'))
  738.         result = true;
  739.     }
  740.  
  741.     callback(result);
  742.   });
  743. }
  744.  
  745.  
  746. function getOdnoklassnikiLinks(extVideoId, callback)
  747. {
  748.   if(!extVideoId)
  749.   {
  750.     callback(null);
  751.     return;
  752.   }
  753.  
  754.   var url = 'http://in.video.mail.ru/cgi-bin/video/oklite?eid=' + extVideoId;
  755.  
  756.   sendRequest(url, function(r){
  757.     if(r.status == 200 && r.responseText)
  758.     {
  759.       var u = 'http://www.okcontent.video.mail.ru/media/';
  760.  
  761.       var host = r.responseText.match(/\$vcontentHost=([^\s\"'\<\>]+)/i);
  762.       if(host && host.length > 1)
  763.         u = 'http://' + host[1] + '/media/';
  764.  
  765.       u += extVideoId;
  766.  
  767.       var links = [];
  768.       links.push({
  769.         url: u + '-v.mp4',
  770.         title: 'SD',
  771.         ext: 'FLV'
  772.       });
  773.  
  774.       if(r.responseText.search(/\$HDexist=1/i) > -1)
  775.       {
  776.         links.push({
  777.           url: u + '-hv.mp4',
  778.           title: 'HD',
  779.           ext: 'MP4'
  780.         });
  781.       }
  782.  
  783.       if(links)
  784.       {
  785.         callback(links);
  786.         return;
  787.       }
  788.     }
  789.  
  790.     callback(null);
  791.   }, '', url);
  792. }
  793.  
  794.  
  795. function getOdnoklassnikiAudioLinks(pageUrl, trackId, jsessionId, callback)
  796. {
  797.   if(!trackId || !jsessionId)
  798.   {
  799.     callback(null);
  800.     return;
  801.   }
  802.  
  803.   var url = 'http://wmf1.odnoklassniki.ru/play;jsessionid=' + jsessionId +
  804.     '?tid=' + trackId + '&';
  805.  
  806.   sendRequest(url, function(r){
  807.     var data = null;
  808.     if(r.status == 200 && r.responseText)
  809.     {
  810.       data = JSON.parse(r.responseText);
  811.     }
  812.  
  813.     callback(data);
  814.   }, '', url);
  815. }
  816.  
  817.  
  818. function parseQuery(query)
  819. {
  820.   var k = {};
  821.   var re = /[?&]?([^=]+)(?:=([^&]*))?/g;
  822.   while(m = re.exec(query))
  823.   {
  824.     if(m[1] && m[2])
  825.       k[m[1]] = m[2];
  826.     else if(m[1])
  827.       k[m[1]] = '';
  828.   };
  829.  
  830.   return k;
  831. }
  832.  
  833.  
  834. function getQueryString(query, key_prefix, key_suffix)
  835. {
  836.   if(!query || typeof(query) != 'object')
  837.     return '';
  838.  
  839.   if(key_prefix === undefined)
  840.     key_prefix = '';
  841.  
  842.   if(key_suffix === undefined)
  843.     key_suffix = '';
  844.  
  845.   var str = '';
  846.   for(key in query)
  847.   {
  848.     if(str.length)
  849.       str += '&';
  850.  
  851.     if(query[key] instanceof Object)
  852.     {
  853.       if(!key_prefix)
  854.         key_prefix = '';
  855.  
  856.       if(!key_suffix)
  857.         key_suffix = '';
  858.  
  859.       str += getQueryString(query[key], key_prefix + key + "[", "]" + key_suffix);
  860.     }
  861.     else
  862.       str += key_prefix + escape(key) + key_suffix + '=' + escape(query[key]);
  863.   }
  864.  
  865.   return str;
  866. }
  867.  
  868.  
  869. function ucfirst(str)
  870. {
  871.   if(str.length)
  872.     str = str.charAt(0).toUpperCase() + str.slice(1);
  873.  
  874.   return str;
  875. }
  876.  
  877.  
  878. fixPref([
  879.   {name: 'button', check: '0', def: '1'},
  880.   {name: 'moduleVimeo', check: '0', def: '1'},
  881.   {name: 'ytHideFLV', check: '1', def: '0'},
  882.   {name: 'ytHideMP4', check: '1', def: '0'},
  883.   {name: 'ytHideWebM', check: '0', def: '1'},
  884.   {name: 'ytHide3GP', check: '0', def: '1'},
  885.   {name: 'ytHide3D', check: '0', def: '1'},
  886.   {name: 'vkShowBitrate', check: '1', def: '0'}
  887. ]);
Advertisement
Add Comment
Please, Sign In to add comment