Vì một lý do nào đó bạn cần chèn video của youtube vào khung comment của blogger, ví dụ như giải thích một cái gì đó liên quan đến bài viết bằng video thông qua khung bình luận của blogger, nhưng thực tế khung comment mặt định của blogger không cung cấp cho ta tính năng này, Vậy làm thế nào để thực hiện điều đó? Hôm nay, xin chia sẽ cho bạn một cách để chèn video vào khung bình luận của blogger bằng các sử dụng javascript. Tùy vào nội dung trên blog của bạn, bạn có thể sử dụng nó với mục đích khác nhau. Vì vậy, nếu bạn thấy rằng việc sử dụng video trên khung bình luận của bạn là thực sự hữu ích và bạn muốn có tính năng này trên blog của mình, bạn chỉ cần làm theo các bước đơn giản dưới đây.
Chèn video của youtube vào khung comment của Blogger
Để cài đặt, trước tiên đăng nhập vào Blogger
Vào Mẫu (Template) >> Chỉnh sửa HTML (Edit HTML)
Tiếp theo, tìm thẻ đóng </body>, sao chép (copy) và dán (paste) đoạn mã dưới đây ngay trên thẻ đóng </body>
<script src="https://googledrive.com/host/0BwL0KbT-xOaTTHdfZlhjNEdhQUk/video-comments-youtube.js"></script>
và bên dưới là Full đoạn code JS nếu link website đó die
// Thá»§ thuáºt BLogger
// http://blog.bomkhung.info
var oetag = 1;
var oetagname = "youtube";
var oelazy = 1;
function oe_loadscript(filename) {
var scr=document.createElement('script');
scr.setAttribute("type","text/javascript");
scr.setAttribute("src",filename);
document.getElementsByTagName("head")[0].appendChild(scr);
}
function oe_jumptohash() {
window.scrollTo(0, $("#"+window.location.hash.replace(/^#/, "")).offset().top);
}
var oe_tid;
var oe_elems = {};
function oembed_callback(response) {
var resp = response;
revurl = resp.url.split("").reverse().join("");
html = oe_elems[response.callID].html();
ee = $(resp.html);
w = parseInt(ee.attr("width"));
h = parseInt(ee.attr("height"));
if(oelazy==1) {
src = ee.attr("src");
src += ((src.indexOf("?")==-1) ? "?" : "&") + "autoplay=1";
ee.attr("src", src);
ee.attr("style", "vertical-align:top;");
htm = $("<div/>").append(ee).html();
htm = $('<div/>').text(htm).html().replace(/"/g,'"');
resp.html = '<a href="'+resp.url+'" class="youtube-lazy-link" style="width: '+w+'px; height: '+h+'px; background: #000 url('+resp.thumbnail_url+') center center no-repeat;" onclick="$(this).replaceWith(\''+htm+'\');return false;"><div style="width:'+(w-4)+'px;height:'+(h-4)+'px;" class="youtube-lazy-link-div"></div><div class="youtube-lazy-link-info"><b>'+resp.title+(resp.playlist ? '</b> [playlist]' : '</b>')+'<br /><small>by '+resp.author_name+'</small></div></a>';
}
htmlx = html.replace(new RegExp("\\[" + oetagname + "="+resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+"\\]"), " " + resp.url + " ");
htmlx = htmlx.replace(new RegExp("\\[" + oetagname + "="+resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+" \\]"), " " + resp.url + " ");
htmlx = htmlx.replace(new RegExp('"'+resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+'"', "g"), '"'+revurl+'"'); // trick to preserve href="url"
htmlx = htmlx.replace(new RegExp(resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")), '<div style="height:'+h+'px;" class="oembed youtube">'+resp.html+'</div>')
htmlx = htmlx.replace(new RegExp('"'+revurl.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+'"', "g"), '"'+resp.url+'"'); // trick to preserve href="url"
if(html != htmlx) {
oe_elems[response.callID].html(htmlx);
if(window.location.hash.replace(/^#/, "").length > 0) {
if(oe_tid) window.clearTimeout(oe_tid);
oe_tid = window.setTimeout("oe_jumptohash()", 1000);
}
}
}
function oembed_yt(url, width, callID) {
src = "http://oembed-js.appspot.com/?url=" + encodeURIComponent(url) + "&callback=oembed_callback&callID=" + encodeURIComponent(callID);
if(width) src = src + "&maxwidth=" + width + "&maxheight=" + width;
oe_loadscript(src);
}
$(document).ready(function() {
det=$('<div class="youtube-lazy-link-div" />');
$("body").append(det);
if(det.css("position")=="absolute") {
if(oelazy != 0) oelazy=1;
}
else oelazy = 0;
det.remove();
window.setTimeout(function() {
var callID=0;
$(".comment-content,.comment-body,.comment-body-author").each(function() {
html = " " + $(this).html() + " ";
if(oetag)
matches = html.match(new RegExp("\\["+oetagname+"=(https?:\\/\\/[^\\s<\\/]*youtu\\.*be[^\\]]+)", "g"));
else
matches = html.match(/([>\s^]|\[\w+=)(https?:\/\/[^\s<\/]*youtu\.*be[^\s<\]]+)/g);
if(matches && matches.length) {
for(var i=0;i<matches.length;i++) {
url = matches[i].match(/https?:\/\/[^\s<\/]*youtu\.*be[^\s<\]]+/);
oe_elems[callID] = $(this);
oembed_yt(url, $(this).width(), callID++);
}
}
});
}, 500);
});
Cuối cùng, Lưu mẫu của bạn lại và sử dụng Cách sử dụng: Mỗi khi bạn muốn nhúng video của youtube vào khung bình luận của blogspot chỉ cần thêm mã dưới đây vào khung bình luận và thay địa-chỉ-video-của-youtube thành url của youtube
[youtube=địa-chỉ-video-của-youtube]Hy vọng với mẹo nhỏ này bạn đả có thể chèn video vào khung nhận xét của blogger, và sử dụng nó đúng với mục đích của bạn. Chúc thành công! và cuối cùng mình thêm đoạn code có thể play nhạc toàn bộ các trang nhạc của chúng ta hiện nay ^^
[img][/img]
<b:if cond='data:blog.pageType == "item"'>
<script type='text/javascript'>
//<![CDATA[
function replaceText(){if(!document.getElementById){return;}
bodyText = document.getElementById("multimedia");
theText = bodyText.innerHTML;
theText = theText.replace(/\[img\].*?'.*?\[\/img\]/gi, "");
theText = theText.replace(/\[nct\].*?'.*?\[\/nct\]/gi, "");
theText = theText.replace(/\[img\]/gi, "<div style='clear:both'></div><img style='float:left;margin:10px 0;border:1px solid #DDD;max-width:590px;background:#FFF;padding:4px' src='");
theText = theText.replace(/\[\/img\]/gi, "'/><div style='clear:both'></div>");
theText = theText.replace(/&feature=/gi, "?rel=0' '");
theText = theText.replace(/\[\/youtube\]/gi, "?rel=0' frameborder='0' allowfullscreen></iframe>");
theText = theText.replace(/\[nct\]http:\/\/www.nhaccuatui.com\/nghe\?L=/gi, "<div style='overflow:hidden'><embed style='margin-top:-250px;width:300px;height:400px' src='http://www.nhaccuatui.com/l/");
theText = theText.replace(/\[nct\]http:\/\/www.nhaccuatui.com\/nghe\?M=/gi, "<div style='overflow:hidden'><embed style='margin-top:-350px;width:300px;height:400px' src='http://www.nhaccuatui.com/m/");
theText = theText.replace(/\[\/nct\]/gi, "' quality='high' wmode='transparent' type='application/x-shockwave-flash'></embed></div>");
bodyText.innerHTML = theText;
}replaceText();
//]]>
</script>
</b:if>
Chèn cả youtube, ảnh, mp3 vào mới hay :D
Trả lờiXóaCó chèn ảnh với nhạc của tui đó. B mới cập nhật thêm :D còn mp3 bờm chưa mò ra duy ạ ^^
XóaCác bạn không cần thêm [youtube=địa-chỉ-video-của-youtube]
Trả lờiXóavào khi chèn link youtube nữa nhé cứ vứt link vào là hiện thôi ^^ vì mình chèn đoạn code sau vào rồi :D
<!-- cmt youtube -->
<script src='https://googledrive.com/host/0BwL0KbT-xOaTTHdfZlhjNEdhQUk/video-comments-youtube.js'></script>