Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CreateBadge(btext, post_id)
- {
- // Function for inserting a badge
- var post_path = "post_"+post_id;
- $j("div#"+post_path+" div.user_badge div.name").append("<div style='background-color:#269469; padding:2px; color:white;'>"+btext+"</div>");
- }
- function DefineBadge(tags, post_id)
- {
- // Function define badge by tags
- if (tags.toLowerCase().indexOf("badge_gurudeveloper") >= 0)
- {
- CreateBadge("The Best Dev!", post_id);
- }
- }
- // Get current url
- var s_url=window.location.pathname;
- var s_urlparts = s_url.split('/');
- var s_section = s_urlparts[1];
- // Run if we in the "entries" section
- if (s_section=='entries')
- {
- // Get topic id
- var s_topicID = s_urlparts[2].split('-')[0];
- // Use new awesome API
- var s_zurl = "/api/v2/topics/"+s_topicID+"/comments.json";
- new Ajax.Request(s_zurl,
- {
- method:'GET',asynchronous: true,onSuccess: function(transport)
- {
- var obj = transport.responseText.evalJSON();
- $j.each(obj.topic_comments, function () {
- var post_id=this.id;
- var user_id = this.user_id;
- //Get user data
- //Call server. Use old API =);
- var s_zurl_u = "/users/"+user_id+".json";
- new Ajax.Request(s_zurl_u,
- {
- method:'GET',asynchronous: false,onSuccess: function(transport)
- {
- var obj = transport.responseText.evalJSON();
- tags = obj['current_tags'];
- DefineBadge(tags, post_id);
- }
- });
- });
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement