(javascript) Zamiana linków youtube na kod javascript pobieranie tytułu itp
Przejdź do nawigacji
Przejdź do wyszukiwania
<source lang="javascript">
function find_and_replace_youtube_links(c){ var d=/https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&|&+%\w]*(?:['"][^<>]*>|<\/a>))[?=&|&+%\w-]*/ig; var cosik = c.replace(d,'$1'); return c.replace(d,replace_calback) }
function replace_calback(a,b,c) { return 'play('+b+')'+getYouTubeTitle(b); }
function getYouTubeTitle(id) { var temp = $.ajax({ url: "http://gdata.youtube.com/feeds/api/videos/"+id+"?v=2&alt=json", async: false }).responseText;
var data = jQuery.parseJSON(temp); var title = data.entry.title.$t; return title; }
var test; test='DUPA HAH DUPA http://www.youtube.com/watch?v=ZPkE2hHneP4&feature=g-high-xit dupa dupa'; test=find_and_replace_youtube_links(test); document.write(test); </source>