ShowYouTubeCommentProfile

By henshiru Last update Aug 29, 2010 — Installed 712 times.

There are 8 previous versions of this script.

// ==UserScript==
// @name           ShowYouTubeCommentProfile
// @namespace      http://www.henshi.net/k/
// @description    insert commenters' age, location and gender after their name on YouTube.
// @include        http://youtube.com/*
// @include        http://*.youtube.com/*
// ==/UserScript==

(function(){
  var GENDER_COLOR_ENABLED = true;//replace 'true' with 'false' if you need to disable gender-coloring
  var auth_impl = function(){
    var impl = function(node){
      var username = function(){
        var attrs = node.attributes
        for(var i=0;i!=attrs.length;++i){
          var att = attrs[i];
          if(att.name == "data-author"){
            return att.value;
          }
        }
        return null;
      }();
      var author = function(){
        var nodes = node.getElementsByClassName("author");
        return nodes[0];
      }();
      var url = "http://gdata.youtube.com/feeds/api/users/"+username;
      var callback = function(r){
        var r = r.responseText;
        var age="",gender="",loc="";
        if(/<yt:age>(.*)<\/yt:age>/.test(r)){
          age = RegExp.$1;
        }
        if(/<yt:gender>(.*)<\/yt:gender>/.test(r)){
          gender= RegExp.$1;
        }
        if(/<yt:location>(.*)<\/yt:location>/.test(r)){
          if(/(.*,\s*)*(.*)$/.test(RegExp.$1)){
            loc = RegExp.$2;
          }
        }
        author.firstChild.nodeValue = username+"("+loc+":"+age+":"+gender+")";
        if(GENDER_COLOR_ENABLED && gender){
          switch(gender){
            case "m":
              author.style.color = "#0040a0";
              break;
            case "f":
              author.style.color = "#a00000";
              break;
          }
        }
      };
      GM_xmlhttpRequest({method: 'GET', url: url, onload: callback});
    }
    var auths = document.getElementsByClassName("comment");
    for(var i in auths){
      impl(auths[i]);
    }
  };
  auth_impl();
  GM_registerMenuCommand('ShowYouTubeCommentProfile - show profile manually', auth_impl);
})();