TwitchTV embedding (live and archive)

This commit is contained in:
Zixaphir 2013-08-05 14:05:29 -07:00
parent c44014b19e
commit d5553cf5fd
3 changed files with 81 additions and 27 deletions

View File

@ -4328,6 +4328,9 @@
len = snapshot.snapshotLength;
while (++i < len) {
node = snapshot.snapshotItem(i);
if (node.parentElement.nodeName === "A") {
continue;
}
data = node.data;
if (Linkify.regString.test(data)) {
Linkify.regString.lastIndex = 0;
@ -4360,7 +4363,7 @@
index = match.index;
link = match[0];
len2 = index + link.length;
if (len - len2 === 0) {
if (len === len2) {
break;
}
range = document.createRange();
@ -4393,10 +4396,7 @@
}
}
if (range.collapsed) {
if (node.nodeName === 'WBR') {
node = node.previousSibling;
}
range.setEnd(node, node.length);
range.setEndAfter(node);
}
return Linkify.makeLink(range, post);
},
@ -4637,6 +4637,27 @@
}
}
},
TwitchTV: {
regExp: /.*(?:twitch.tv\/)([^#\&\?]*).*/,
style: "border: none; width: 640px; height: 360px;",
el: function() {
var channel, chapter, result, _;
if (result = /(\w+)\/(?:[a-z]\/)?(\d+)/i.exec(this.dataset.uid)) {
_ = result[0], channel = result[1], chapter = result[2];
return $.el('object', {
data: 'http://www.twitch.tv/widgets/archive_embed_player.swf',
innerHTML: "<param name='allowFullScreen' value='true' />\n<param name='flashvars' value='channel=" + channel + "&start_volume=25&auto_play=false" + (chapter ? "&chapter_id=" + chapter : "") + "' />"
});
} else {
channel = (/(\w+)/.exec(this.dataset.uid))[0];
return $.el('object', {
data: "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + channel,
innerHTML: "<param name=\"allowFullScreen\" value=\"true\" />\n<param name=\"movie\" value=\"http://www.twitch.tv/widgets/live_embed_player.swf\" />\n<param name=\"flashvars\" value=\"hostname=www.twitch.tv&channel=" + channel + "&auto_play=true&start_volume=25\" />"
});
}
}
},
Vocaroo: {
regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/,
style: 'border: 0; width: 150px; height: 45px;',

View File

@ -4333,6 +4333,9 @@
len = snapshot.snapshotLength;
while (++i < len) {
node = snapshot.snapshotItem(i);
if (node.parentElement.nodeName === "A") {
continue;
}
data = node.data;
if (Linkify.regString.test(data)) {
Linkify.regString.lastIndex = 0;
@ -4365,7 +4368,7 @@
index = match.index;
link = match[0];
len2 = index + link.length;
if (len - len2 === 0) {
if (len === len2) {
break;
}
range = document.createRange();
@ -4398,10 +4401,7 @@
}
}
if (range.collapsed) {
if (node.nodeName === 'WBR') {
node = node.previousSibling;
}
range.setEnd(node, node.length);
range.setEndAfter(node);
}
return Linkify.makeLink(range, post);
},
@ -4642,6 +4642,27 @@
}
}
},
TwitchTV: {
regExp: /.*(?:twitch.tv\/)([^#\&\?]*).*/,
style: "border: none; width: 640px; height: 360px;",
el: function() {
var channel, chapter, result, _;
if (result = /(\w+)\/(?:[a-z]\/)?(\d+)/i.exec(this.dataset.uid)) {
_ = result[0], channel = result[1], chapter = result[2];
return $.el('object', {
data: 'http://www.twitch.tv/widgets/archive_embed_player.swf',
innerHTML: "<param name='allowFullScreen' value='true' />\n<param name='flashvars' value='channel=" + channel + "&start_volume=25&auto_play=false" + (chapter ? "&chapter_id=" + chapter : "") + "' />"
});
} else {
channel = (/(\w+)/.exec(this.dataset.uid))[0];
return $.el('object', {
data: "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + channel,
innerHTML: "<param name=\"allowFullScreen\" value=\"true\" />\n<param name=\"movie\" value=\"http://www.twitch.tv/widgets/live_embed_player.swf\" />\n<param name=\"flashvars\" value=\"hostname=www.twitch.tv&channel=" + channel + "&auto_play=true&start_volume=25\" />"
});
}
}
},
Vocaroo: {
regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/,
style: 'border: 0; width: 150px; height: 45px;',

View File

@ -44,6 +44,9 @@ Linkify =
while ++i < len
node = snapshot.snapshotItem i
continue if node.parentElement.nodeName is "A"
data = node.data
if Linkify.regString.test data
@ -69,7 +72,7 @@ Linkify =
link = match[0]
len2 = index + link.length
break if len - len2 is 0
break if len is len2
range = document.createRange();
range.setStart node, index
@ -99,9 +102,7 @@ Linkify =
range.setEnd node, result.index
if range.collapsed
if node.nodeName is 'WBR'
node = node.previousSibling
range.setEnd node, node.length
range.setEndAfter node
Linkify.makeLink range, post
@ -297,19 +298,30 @@ Linkify =
api: (uid) -> "//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/#{uid}"
text: -> JSON.parse(@responseText).title
# WIP
#
# TwitchTV:
# regExp: /twitch\.tv\/(\w+)\/(?:b\/)?(\d+)/i
# style: "border: none; width: 640px; height: 360px;"
# el: ->
# [_, channel, archive] = @result
# el = $.el 'object',
# data: 'http://www.twitch.tv/widgets/archive_embed_player.swf'
# innerHTML: """
#<param name='allowFullScreen' value='true' />
#<param name='flashvars' value='channel=#{channel}&start_volume=25&auto_play=false&archive_id=#{archive}' />
#"""
TwitchTV:
regExp: /.*(?:twitch.tv\/)([^#\&\?]*).*/
style: "border: none; width: 640px; height: 360px;"
el: ->
if result = /(\w+)\/(?:[a-z]\/)?(\d+)/i.exec @dataset.uid
[_, channel, chapter] = result
$.el 'object',
data: 'http://www.twitch.tv/widgets/archive_embed_player.swf'
innerHTML: """
<param name='allowFullScreen' value='true' />
<param name='flashvars' value='channel=#{channel}&start_volume=25&auto_play=false#{if chapter then "&chapter_id=" + chapter else ""}' />
"""
else
channel = (/(\w+)/.exec @dataset.uid)[0]
$.el 'object',
data: "http://www.twitch.tv/widgets/live_embed_player.swf?channel=#{channel}"
innerHTML: """
<param name="allowFullScreen" value="true" />
<param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" />
<param name="flashvars" value="hostname=www.twitch.tv&channel=#{channel}&auto_play=true&start_volume=25" />
"""
Vocaroo:
regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/