Skip to content

Instantly share code, notes, and snippets.

@metaphox
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save metaphox/fdd9096535de50c137c0 to your computer and use it in GitHub Desktop.

Select an option

Save metaphox/fdd9096535de50c137c0 to your computer and use it in GitHub Desktop.
(function(){
var colors = [
"#F0F0F0", "#AAAAAA", "#888888", "#333333",
"#B00B1E", "#003366", "#00BB33", "#00FF00"
];
$('#zh-question-answer-wrap .voters a').each(function(){
var self = $(this);
$.get("http://www.zhihu.com/node/MemberProfileCardV2?params=" +
encodeURIComponent('{"url_token":"' +
self.attr('data-tip').split("$")[2] + '"}'
)
).success(function(data){
var j = data.indexOf('<span class="key">关注者') - 8;
var i = data.slice(0, j).lastIndexOf('class="value">') + 14;
var nFollowText = data.slice(i, j);
var heavy = false;
var lvl = 0;
if(nFollowText.toLowerCase().indexOf('k') > 0){
heavy = true;
}
lvl = parseInt(nFollowText).toString().length;
// 10.9k => '2'
// 42 => 2
if(lvl > 4) lvl = 4;
if(heavy) lvl += 4;
var color = colors[lvl-1];
self.css('color', color);
}).error(function(){
self.css('color', '#993300');
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment