WikiPedia でタレントの写真を表示

Wikipedia でタレントを検索したら、Yahoo! タレントプロフィールから写真を貼り付ける greasemoney スクリプト。ただし誤爆多し。
http://ja.wikipedia.org/wiki/%E6%9C%A8%E6%9D%91%E3%82%AB%E3%82%A8%E3%83%A9
とか。なんでやねん。(アルゴリズム改良中)

// ==UserScript==
// -*- mode:JScript; Encoding:utf8n -*-
// @name           wikipedia.yahooTalentImage
// @namespace      http://d.hatena.ne.jp/p-arai/
// @description    Add pop-up on reference to footnote
// @include        http://ja.wikipedia.org/wiki/*
//
// @author         p-arai
// @version        2009.02.17
// ---------------------------------------------------------
// This script is a derived version of wikipedia.googleimage
// http://www.kagami.org/diary/2007-09-16-1.html
// ---------------------------------------------------------

(function () {
  var debug = false;

  var baseurl = 'http://search.yahoo.co.jp/search?p=';
  var word = document.title.replace(/\s+-\s+Wikipedia/, "");
  var searchurl = baseurl + word + "+%E3%83%97%E3%83%AD%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB+talent.yahoo.co.jp";
  var img = document.createElement('img');
  img.alt = 'Yahoo: ' + word;

  var a = document.createElement('a');
  a.appendChild(img);
  a.href = searchurl;
  
  var div = document.createElement('div');
  div.appendChild(a);

  if (debug){
    var debugArea = document.createElement('textarea');
    div.appendChild(debugArea);
  }

  var h1 = document.getElementsByTagName('h1')[0];
  h1.parentNode.insertBefore(div, h1.nextSibling);

  var profileURL;

  GM_xmlhttpRequest({
  method: 'GET',
  url: searchurl,
  headers: { 'User-agent': 'Mozilla/4.0 (compatible)' },
  onload: function(responseDetails) {
    var responseText = responseDetails.responseText.replace(/<\/b><b>/ig, "");
    if (debug) debugArea.value = responseText;
    reProfileURL = new RegExp('talent.yahoo.co.jp/talent/.+?\.html', "i");
    reProfileTitle = new RegExp(word + '.*?の<b>プロフィール', "i");
    reImgL = new RegExp('http://i.yimg.jp/images/talent/large/.+?jpg', "i");
    reImgM = new RegExp('http://i.yimg.jp/images/talent/medium/.+?jpg', "i");
    if (responseText.match(reImgM)) {
    if (debug) window.alert("reImgM found.");
      // alert(responseText.match(reImgM));
      img.src = RegExp.lastMatch.replace(/medium/, "large");
    } else if (responseText.match(reProfileTitle) &&
               responseText.match(reProfileURL)) {
      responseText.match(reProfileURL);
      if (debug) window.alert("rePofile found.");
      profileURL = 'http://' + RegExp.lastMatch;
      if (debug) alert("profileURL=" + profileURL);
      GM_xmlhttpRequest({
      method: 'GET',
      url: profileURL,
      headers: { 'User-agent': 'Mozilla/4.0 (compatible)' },
      onload: function(responseDetails) {
        if (debug) alert(responseDetails.responseText.match(reImgL));
        if (responseDetails.responseText.match(reImgL)) {
          img.src = RegExp.lastMatch;
        }
      }
      });
    } else { // no image
      if (debug) alert("no image");
    }
  }
  });
})();