User:Incongruence/chat.js/youtube.js

// Converts posted YouTube links to their title. // By Incongruence. mainRoom.model.chats.bind("afteradd", function(msg) { reg = "https?:\/\/(?:www\.)?youtube\.com[^ ]+v=([^&#\s]*)|https?:\/\/(?:www\.)?youtu\.be\/([^&#\?\s]*)";  if(msg.attributes.text.match(reg)){    id = msg.attributes.text.match(reg)[1];    x = new XMLHttpRequest;    x.open("GET", "https://gdata.youtube.com/feeds/api/videos/"+ id +"?v=2&alt=jsonc");    x.onreadystatechange = function {      cid = msg.cid;      data = JSON.parse(x.response);      $("#entry-" + cid).find("span.message")[0].innerHTML = " You Tube [" + data['data']['title'] + "]";    }    x.send;  } else { console.log("no match"); } });