hotchpotch (owner)

Forks

Revisions

gist: 49917 Download_button fork
public
Public Clone URL: git://gist.github.com/49917.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// ==UserScript==
// @name with hatebu search
// @namespace http://b.hatena.ne.jp/
// @description google 検索の画面で、はてブ検索へのナビゲーションを出します
// @include http://www.google.co.jp/search*
// @include http://www.google.com/search*
// ==/UserScript==
 
location.href = "javascript:"+encodeURIComponent(uneval(function () {
(function (Global) {
    var td = $X('//table/tbody/tr/td[@class="nobr xsm"]');
    if (td.length) {
      var text = document.getElementsByName('q')[0].value;
 
      var tr = td[0].parentNode;
      var container = document.createElement('td');
      tr.appendChild(container);
      var img = document.createElement('img');
      img.src = 'http://b.hatena.ne.jp/images/search-mini.png';
      img.alt = 'はてな検索で "' + text + '" を検索';
      img.title = img.alt;
      container.appendChild(img);
      img.style.cursor = 'pointer';
      img.addEventListener('mousedown', function() {
        location.href = 'http://b.hatena.ne.jp/search?q=' + encodeURIComponent(text);
      }, false);
    }
   
    function $X (exp, context, type /* want type */) {
      if (typeof context == "function") {
        type = context;
        context = null;
      }
      if (!context) context = document;
      exp = (context.ownerDocument || context).createExpression(exp, function (prefix) {
        var o = document.createNSResolver(context)(prefix);
        if (o) return o;
        return (document.contentType == "application/xhtml+xml") ? "http://www.w3.org/1999/xhtml" : "";
      });
    
      switch (type) {
        case String: return exp.evaluate(context, XPathResult.STRING_TYPE, null).stringValue;
        case Number: return exp.evaluate(context, XPathResult.NUMBER_TYPE, null).numberValue;
        case Boolean: return exp.evaluate(context, XPathResult.BOOLEAN_TYPE, null).booleanValue;
        case Array:
          var result = exp.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
          for (var ret = [], i = 0, len = result.snapshotLength; i < len; i++) {
            ret.push(result.snapshotItem(i));
          }
          return ret;
        case undefined:
          var result = exp.evaluate(context, XPathResult.ANY_TYPE, null);
          switch (result.resultType) {
            case XPathResult.STRING_TYPE : return result.stringValue;
            case XPathResult.NUMBER_TYPE : return result.numberValue;
            case XPathResult.BOOLEAN_TYPE: return result.booleanValue;
            case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
              // not ensure the order.
              var ret = [], i = null;
              while ((i = result.iterateNext())) ret.push(i);
              return ret;
          }
          return null;
        default: throw(TypeError("$X: specified type is not valid type."));
      }
    }
})(this);
}))+"()";