Skip to content

Instantly share code, notes, and snippets.

@MichelleGlauser
Created July 17, 2013 00:24
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 MichelleGlauser/6016532 to your computer and use it in GitHub Desktop.
Save MichelleGlauser/6016532 to your computer and use it in GitHub Desktop.
Reply notification API calls with geo-cached-api.getsatisfaction.com
jQuery(document).ready(function () {
jQuery('#reply_notification a, #topic_notification a').click(function (e) {
e.preventDefault();
window.location.href = window.location.href;
});
var current_replies,
current_topics,
topics,
replies,
md,
companyName,
slug,
api_url;
// Check for new replies:
this_url = location.protocol + "//" + location.host + location.pathname;
if (jQuery('#about_topic_sidebar').size() > 0) {
regex = /\/topics\/(\w+)\??/
md = regex.exec(document.location.pathname);
if (md) {
companyName = md[0];
slug = md[1];
}
else {
companyName = '', slug = '';
}
api_url = 'https://geo-cached-api.getsatisfaction.com/topics/' + slug +
'.json';
}
else {
regex = /https?:\/\/(?:[^\/]+)\/(\w+){1}/
md = regex.exec(document.location.href);
if (md) {
companyName = md[1];
api_url = 'https://geo-cached-api.getsatisfaction.com/companies/' +
companyName + '/topics.json';
}
}
jQuery.ajax({
type: 'GET',
url: api_url,
dataType: 'jsonp',
success: function (results) {
if (results.reply_count) {
current_replies = results.reply_count;
}
else {
current_topics = results.total;
}
},
data: {},
async: false,
error: function (e, s, m) {}
});
window.setInterval(function () {
jQuery.ajax({
type: 'GET',
url: api_url,
dataType: 'jsonp',
success: function (results) {
replies = results.reply_count;
if (results.reply_count) {
replies = results.reply_count;
if (replies > current_replies) {
jQuery('#reply_notification').show();
jQuery('#topic_notification').hide();
}
}
else {
topics = results.total;
if (topics > current_topics) {
jQuery('#topic_notification').show();
jQuery('#reply_notification').hide();
}
}
},
data: {},
async: false,
error: function (e, s, m) {}
});
}, 90000 /*1.5m*/ );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment