forked from codecat/Chatzilla-Plugins
/
init.js
57 lines (47 loc) · 1.91 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* http://github.com/AngeloG/Chatzilla-Plugins
* Copyright (c) Angelo Geels, 2011
*/
plugin.id = "inline-youtube";
plugin.init = function(glob)
{
plugin.version = "1.1";
plugin.description = "Inline YouTube player for YouTube links.";
return "OK";
}
plugin.enable = function()
{
client.munger.addRule("inline-youtube", /(http(s|):\/\/([a-z]{2,}\.|)(youtube.com\/watch\?v=|youtu.be\/)([A-Za-z0-9\-\_]{11}))/, function(matchText, containerTag, eventData){
if(!("dontLogURLs" in eventData)){
var videoID = matchText.match(/([A-Za-z0-9\-\_]{11})/)[1];
var newIframe = document.createElementNS(XHTML_NS, "html:iframe");
newIframe.setAttribute("src", "http://www.youtube.com/embed/" + videoID);
newIframe.setAttribute("width", "560");
newIframe.setAttribute("height", "349");
newIframe.setAttribute("frameborder", "0");
newIframe.setAttribute("allowfullscreen", "1");
var newYouTubeLink = document.createElementNS(XHTML_NS, "html:a");
newYouTubeLink.setAttribute("href", matchText);
newYouTubeLink.appendChild(document.createTextNode(matchText));
containerTag.appendChild(document.createElementNS(XHTML_NS, "html:br"));
containerTag.appendChild(document.createTextNode("YouTube video: "));
containerTag.appendChild(newYouTubeLink);
containerTag.appendChild(document.createElementNS(XHTML_NS, "html:br"));
containerTag.appendChild(newIframe);
containerTag.appendChild(document.createElementNS(XHTML_NS, "html:br"));
}else{
//insertLink function doesn't work properly.
//TODO: Find a way to do this better
var newLink = document.createElementNS(XHTML_NS, "html:a");
newLink.setAttribute("href", matchText);
newLink.setAttribute("location", "_blank");
newLink.appendChild(document.createTextNode(matchText));
containerTag.appendChild(newLink);
}
}, 10, 10);
return true;
}
plugin.disable = function()
{
client.munger.delRule("inline-youtube");
return true;
}