Skip to content

Instantly share code, notes, and snippets.

@mehdimehdi
Created July 6, 2011 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehdimehdi/1068555 to your computer and use it in GitHub Desktop.
Save mehdimehdi/1068555 to your computer and use it in GitHub Desktop.
blogger comment
/* blogger comment integration */
function onBlogSpotComment(data) {
if (data && data.feed && data.feed.entry.length > 0) {
//Get the datetime
var datetime = data.feed.entry[0].published.$t.split("T");
var date = datetime[0];
var time = datetime[1];
var dateSplitted = date.split("-");
var timeSplitted = time.split(":");
var minSecondSplitted = timeSplitted[2].split(".");
var d = new Date(dateSplitted[0], dateSplitted[1]-1, dateSplitted[2], timeSplitted[0], timeSplitted[1], minSecondSplitted[0], 0);
var now = new Date();
var diff = (now.getTime() - d.getTime())/1000;
//verify that the comment happened in the past 5 seconds
if (diff < 5) {
//var _ptq = _ptq || [];
//_ptq.push(["comment",data.feed.entry[0].id.$t]);
_ptq.push(["comment","2"]);
}
}
}
var commentURL;
var links = document.getElementsByTagName("link");
for (var i=0; i < links.length; i++) {
var href = links[i].href;
//look for the comment feed
if (href.match(/^http:\/\/\w+.blogspot.com\/feeds\/\d+\/comments\/default$/)) {
commentURL = href;
break;
}
}
//if the commentURL was found
if (commentURL) {
//go an get the last comment
var i=document.createElement("script");
i.src=unescape(commentURL+"?alt=json-in-script&callback=onBlogSpotComment&max-results=1");
i.async=true;
i.charset="UTF-8";
document.getElementsByTagName("head")[0].appendChild(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment