这是一个名为Bloggertube的Blogger模板 它最初编码嵌入youtube视频和抓取网址图像并发布图像缩略图
我也修改过使用Dailymotion
但我是Javascript的新手,而且我试图弄清楚如何让它们同时工作,以及将来添加更多网站
function createVideoThumb 指的是缩略图创建
function createVideoThumb2 是指玩家的嵌入代码
博客文章sintax是:
(youtube link)endofvid
[starttext] (发表文字) [ENDTEXT]
Youtube代码:
function createVideoThumb(pID){
var div = document.getElementById(pID);
var summ = summary_noimg;
if (div.innerHTML.indexOf("http://www.youtube.com/watch?v=")!=-1){
var vidid = div.innerHTML.substring(div.innerHTML.indexOf("http://www.youtube.com/watch?v=")+31,div.innerHTML.indexOf("endofvid"));
}else {var vidid =""};
var postlink = div.innerHTML.substring(div.innerHTML.indexOf("[postlink]")+10,div.innerHTML.indexOf("[/postlink]"));
if (vidid ==""){var imgvid ='<a href="'+ postlink + '"><img class="thumbnail" src="http://i195.photobucket.com/albums/z105/dantearaujo/novideo.png" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></a>';
}else{
var imgvid ='<a href="'+ postlink + '"><img class=thumbnail src="http://img.youtube.com/vi/'+vidid+'/mqdefault.jpg" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></a>';
};
var summary = imgvid ;
div.innerHTML = summary;
}
function createVideoThumb2(pID){
var div = document.getElementById(pID);
var imgtag = "";
var summ = summary_noimg;
if (div.innerHTML.indexOf("http://www.youtube.com/watch?v=")!=-1){
var vidid = div.innerHTML.substring(div.innerHTML.indexOf("http://www.youtube.com/watch?v=")+31,div.innerHTML.indexOf("endofvid"));
}else {var vidid =""};
var textinside = div.innerHTML.substring(div.innerHTML.indexOf("[starttext]")+11,div.innerHTML.indexOf("[endtext]"));
var postlink = div.innerHTML.substring(div.innerHTML.indexOf("[postlink]")+10,div.innerHTML.indexOf("[/postlink]"));
var embedvid = "";
if (vidid!="") {
embedvid = '<object width="654" height="393"><param name="movie" value="http://www.youtube.com/v/'+ vidid + '&hl=en&fs=1&rel=0&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ vidid + '&hl=en&fs=1&rel=0&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="654" height="393"></embed></object>'
}
var summary = embedvid + '<div class="content">' + textinside + '</div>';
div.innerHTML = summary;
}
Dailymotion代码
function createVideoThumb(pID){
var div = document.getElementById(pID);
var summ = summary_noimg;
if (div.innerHTML.indexOf("http://www.dailymotion.com/video/")!=-1){
var vidid = div.innerHTML.substring(div.innerHTML.indexOf("http://www.dailymotion.com/video/")+33,div.innerHTML.indexOf("endofvid"));
}else {var vidid =""};
var postlink = div.innerHTML.substring(div.innerHTML.indexOf("[postlink]")+10,div.innerHTML.indexOf("[/postlink]"));
if (vidid ==""){var imgvid ='<a href="'+ postlink + '"><img class="thumbnail" src="http://i195.photobucket.com/albums/z105/dantearaujo/novideo.png" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></a>';
}else{
var imgvid ='<a href="'+ postlink + '"><img class=thumbnail src=" http://www.dailymotion.com/thumbnail/video/'+vidid+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></a>';
};
var summary = imgvid ;
div.innerHTML = summary;
}
function createVideoThumb2(pID){
var div = document.getElementById(pID);
var imgtag = "";
var summ = summary_noimg;
if (div.innerHTML.indexOf("http://www.dailymotion.com/video/")!=-1){
var vidid = div.innerHTML.substring(div.innerHTML.indexOf("http://www.dailymotion.com/video/")+33,div.innerHTML.indexOf("endofvid"));
}else {var vidid =""};
var textinside = div.innerHTML.substring(div.innerHTML.indexOf("[starttext]")+11,div.innerHTML.indexOf("[endtext]"));
var postlink = div.innerHTML.substring(div.innerHTML.indexOf("[postlink]")+10,div.innerHTML.indexOf("[/postlink]"));
var embedvid = "";
if (vidid!="") {
embedvid = '<iframe frameborder="0" width="654" height="393" src="//www.dailymotion.com/embed/video/'+ vidid +'" allowfullscreen></iframe>'
}
var summary = embedvid + '<div class="content">' + textinside + '</div>';
div.innerHTML = summary;
}
答案 0 :(得分:0)
我想我明白你的问题所在。解决方案是只有2个函数:createVideoThumb和createVideoThumb2。在函数的开头,检查内部html包含的内容。例如:
function createVideoThumb2(pID){
// Dailymotion
if (div.innerHTML.indexOf("http://www.dailymotion.com/video/")!=-1){
// Set specific local vars here
}
// Youtube
else if(div.innerHTML.indexOf("http://www.youtube.com/watch?v=")!=-1) {
// Set specific local vars here
}
// .... More providers
// Use specific local vars in the code below (I didnt edit anything below)
var div = document.getElementById(pID);
var imgtag = "";
var summ = summary_noimg;
if (div.innerHTML.indexOf("http://www.dailymotion.com/video/")!=-1){
var vidid = div.innerHTML.substring(div.innerHTML.indexOf("http://www.dailymotion.com/video/")+33,div.innerHTML.indexOf("endofvid"));
}else {var vidid =""};
var textinside = div.innerHTML.substring(div.innerHTML.indexOf("[starttext]")+11,div.innerHTML.indexOf("[endtext]"));
var postlink = div.innerHTML.substring(div.innerHTML.indexOf("[postlink]")+10,div.innerHTML.indexOf("[/postlink]"));
var embedvid = "";
if (vidid!="") {
embedvid = '<iframe frameborder="0" width="654" height="393" src="//www.dailymotion.com/embed/video/'+ vidid +'" allowfullscreen></iframe>'
}
var summary = embedvid + '<div class="content">' + textinside + '</div>';
div.innerHTML = summary;
}
您可以对这两个函数执行此操作,然后在函数的其余部分使用变量。 Vars应该像iframeWidth,iframeHeight,......等等,无论你需要为每个提供商定制什么。