// ==UserScript==
// @name           Yahoo with Google
// @namespace      http://www.akiyan.com/
// @description    Yahoo with Google
// @include        http://www.google.co.jp/search*
// @include        http://www.google.com/search*
// ==/UserScript==

(function(){
  if (window.parent != window.self) {
    return;
  }
  var $ = function(id){ return document.getElementById(id); };
  var $c = function(a) { return document.createElement(a) };
  var $t = function(t) { return document.getElementsByTagName(t) };
  var $s = function(e, s) { e.setAttribute('style', s); };
  
  var inputs = $t('input');
  var keyword = '';
  for (var i = 0; i < inputs.length; i++) {
    if (inputs[i] && inputs[i].name && inputs[i].name == 'q') {
      var keyword = inputs[i].value;
      break;
    }
  }
  if (keyword.length == 0) {
    return;
  }
  var body = $t('body')[0];
  body.style.marginRight = "37%";

  var url = 'http://search.yahoo.co.jp/search?ei=UTF-8&fr=sfp&p=' + encodeURIComponent(keyword) + '&meta=vc%3D';
  var d = $c('div');
  $s(d, 'position:absolute;top:2px;right:4px;width:35%;float:right;height:95%');
  var a = $c('a');
  a.href = url;
  a.innerHTML = 'Yahoo Search';
  d.appendChild(a);
  body.appendChild(d);
  
  var iframe = $c('iframe');
  iframe.src = url;
  iframe.border = 0;
  $s(iframe, 'margin-top:4px;width:100%;border:1px solid #ccc');
  iframe.style.height = body.offsetHeight + "px";
  d.appendChild(iframe);
})();