Created
November 10, 2014 05:12
-
-
Save lepture/69fb0f3a7298587a15b8 to your computer and use it in GitHub Desktop.
This file contains 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
var protocol = document.location.protocol === 'https:' ? 'https:' : 'http:'; | |
var ds = document.createElement('script'); | |
ds.type = 'text/javascript'; | |
ds.async = true; | |
ds.src = protocol + '//static.duoshuo.com/embed.js'; | |
document.getElementsByTagName('head')[0].appendChild(ds); | |
module.exports = function(cb) { | |
if (!duoshuoQuery.sso || !duoshuo.sso.login) return; | |
ds.onload = function() { | |
if (DUOSHUO) { | |
load(cb); | |
} else { | |
setTimeout(function() { | |
load(cb); | |
}, 3000); | |
} | |
}; | |
}; | |
function load(cb) { | |
if (!DUOSHUO) return; | |
var v = DUOSHUO.visitor; | |
v.on('reset', function() { | |
if (!v.data) return; | |
if (!v.data.social_uid) return; | |
var name = 'weibo'; | |
/* TODO: add more services; | |
var names = ['weibo']; | |
for (var i = 0; i < names.length; i++) { | |
if (v.data.social_uid[names[i]]) { | |
name = names[i]; | |
break; | |
} | |
} | |
*/ | |
var base = protocol + duoshuoQuery.short_name + '.duoshuo.com/login/'; | |
var query = 'sso=1&redirect_uri=' + encodeURIComponent(duoshuoQuery.sso.login); | |
var ifr = document.createElement('iframe'); | |
ifr.style.display = 'none'; | |
ifr.src = base + name + '/?' + query; | |
var $ = DUOSHUO.jQuery; | |
ifr.onload = function() { | |
var data = $(ifr.contentDocument.body).text(); | |
data = $.parseJSON(data); | |
cb(data); | |
document.body.removeChild(ifr); | |
}; | |
document.body.appendChild(ifr); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment