Posted By

mitry on 02/10/09


Tagged

Opera audio vkontakte userjs


Versions (?)

vkontakte userjs


 / Published in: JavaScript
 

URL: http://vkontakte.ru/audio

  1. // ==UserScript==
  2. // @name Download audio from http://vkontakte.ru/
  3. // @version 2.00
  4. // @date 2009-03-17 Tue 09:41
  5. // @author dMitry Alexandrov <[email protected]>
  6. // @include http://vkontakte.ru/audio*
  7. // @include http://vkontakte.ru/gsearch.php?*section=audio*
  8. // @include http://vkontakte.ru/gsearch.php?section=audio*
  9. // ==/UserScript==
  10.  
  11. function afterFunc() {
  12. for (var i=0,el,els=document.selectNodes('//img[@class="playimg"]');el=els[i++];) {
  13. var lnk=document.createElement("A");
  14. lnk.innerHTML = '\u0441\u043a\u0430\u0447\u0430\u0442\u044c \u00bb';
  15. lnk.href=el.getAttribute('onclick').replace(/.*operate\((\d+),(\d+),(\d+),'([0-9a-f]+)',(\d+)\).*/,'http://cs$2.vkontakte.ru/u$3/audio/$4.mp3');
  16. lnk.setAttribute('style', 'display: block !important; float: none !important; font: icon !important; margin: 15px 0 0 0 !important; padding: 0 !important; text-align: left !important;', false);
  17. (el.parentNode.nextSibling || el.parentNode).appendChild(lnk);
  18. }
  19. }
  20.  
  21. window.addEventListener('DOMContentLoaded', afterFunc, false);
  22.  
  23. window.opera.addEventListener('BeforeJavascriptURL', function (e) {
  24. if( e.source.match(/getPageContent\(\d+,\s*\d+\)/))
  25. e.source = e.source.replace(/getPageContent\(\s*(\d+)\s*,\s*(\d+)\s*\);?/,'getPageContent\($1,$2,afterFunc)');
  26. }, false
  27. );
  28.  
  29. /** Link to create M3U playlist */
  30. window.addEventListener('DOMContentLoaded', function(){
  31. var a=document.createElement('A');
  32. a.href='javascript:void(0);';
  33. a.innerHTML="playlist";
  34. a.title='Create m3u playlist';
  35. a.onclick=function(){
  36. var list="#EXTM3U\n";
  37. function getTitle(el){return el.innerHTML.replace(/(^\s+)|(\s+$)/gm,'')};
  38. function getSecs(el){
  39. if (el && el.firstChild) {
  40. var x=el.firstChild.nodeValue.split(':')
  41. return 60*parseInt(x[0],10) + parseInt(x[1],10);
  42. }else return 0;
  43. };
  44.  
  45. for (var i=0,el,els=document.selectNodes('//a[@href]');el=els[i++];) {
  46. if (/\.mp3$/i.test(el.href)) {
  47. var file=el.href;
  48. var td=el.parentNode; //alert(td.tagName);
  49. var title=getTitle(td.firstChild);
  50. var duration=getSecs(td.selectSingleNode('./div[@class="duration"]'));
  51. list+="#EXTINF:"+duration+","+title+"\n"+file+"\n";
  52. }
  53. }
  54. var w=window.open("about:blank","VKPlayList",'width=450,height=450,top=5,left=70,scrollbars=yes,status=no');
  55. w.document.open();
  56. w.document.write('<pre>'+list+'</pre>');
  57. w.document.close();
  58. return false;
  59. };
  60. (document.getElementById('searchContent')||document.getElementById("searchAudio")||document.getElementById('audioSearch')).appendChild(a);
  61. }, false);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: kurokikaze on February 11, 2009

Полезно :)

Posted By: legolas_kaka on February 24, 2009

good

You need to login to post a comment.