(javascript) Zamiana linków youtube na kod javascript pobieranie tytułu itp: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
m (Zastępowanie tekstu - "</source>" na "</pre>") |
m (Zastępowanie tekstu - "<source lang="javascript">" na "<pre>") |
||
Linia 1: | Linia 1: | ||
< | <pre> | ||
function find_and_replace_youtube_links(c){ | 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 d=/https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&|&+%\w]*(?:['"][^<>]*>|<\/a>))[?=&|&+%\w-]*/ig; |
Aktualna wersja na dzień 00:55, 16 lut 2018
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);