Last active
December 25, 2015 20:09
-
-
Save ryanvalentin/7033341 to your computer and use it in GitHub Desktop.
Get identifier from Blogger and output as 'disqus_identifier'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="disqus_thread" onresize="setHeight()"></div> | |
<script type="text/javascript"> | |
// Blog variables | |
var blog; | |
var msg = new gadgets.MiniMessage(__MODULE_ID__); | |
var prefs = new gadgets.Prefs(); | |
// Disqus variables | |
var disqus_shortname = prefs.getString("shortname"); | |
var disqus_url; | |
var disqus_title; | |
var disqus_identifier; | |
window.onload = function () { | |
if (!disqus_shortname) { | |
msg.createDismissibleMessage("Invalid disqus shortname entered"); | |
} | |
else | |
{ | |
msg.createDismissibleMessage("v28 - shortname - " + disqus_shortname); | |
blog = new google.Blog(function() { | |
blog.getCurrentPostJson(getPostData); | |
}, window.name); | |
/*** Comment Counts ****/ | |
// Find all anchor tags with #comments | |
//var anchors = document.getElementByTagName('a').href | |
// find comment feed link under | |
// Render comment counts regardless of the page | |
(function () { | |
var s = document.createElement('script'); s.async = true; | |
s.type = 'text/javascript'; | |
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js'; | |
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); | |
}()); | |
} | |
} | |
// Gets the current blog post data | |
function getPostData(data) { | |
var entry = data.data.entry; | |
var ident = entry.id.$t.split("post-"); | |
disqus_url = entry.link[4].href; | |
disqus_identifier = ident[1]; | |
disqus_title = entry.title.$t; | |
// This means we're on a post page, show comments | |
if (blog.getCurrentCommentsFeedUrl() != null) { | |
if (disqus_url != undefined && disqus_identifier != undefined) { | |
(function() { | |
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; | |
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; | |
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); | |
})(); | |
} | |
else | |
{ | |
document.getElementById('disqus_thread').innerHTML = 'Unable to load comments due to blog configuration error.'; | |
} | |
} | |
else // We're on the index page | |
{ | |
} | |
} | |
</script> | |
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> | |
<a href="http://disqus.com" class="dsq-brlink" style="display:none;">comments powered by <span class="logo-disqus">Disqus</span></a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment