gist: 2234 Download_button fork
public
Public Clone URL: git://gist.github.com/2234.git
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// ==UserScript==
// @name My command for Minibuffer
// @namespace Minibuffer.My.Command
// @description my user.js of the 俺, for the 俺, by the 俺
// @include *
// ==/UserScript==
 
(function () {
   var Search = function() { this.initialize.apply(this, arguments); };
   Search.prototype = {
     initialize: function() {
       var self = this;
 
       var divEl = document.createElement('div');
       var inputEl = document.createElement('input');
       var labelEl = document.createElement('label');
 
       inputEl.id = 'searchWord';
       labelEl.setAttribute('for', inputEl.id);
 
       divEl.setAttribute('style', [
                            '-moz-border-radius: 10px 10px 10px 10px;',
                            'background-color: #333;',
                            'bottom: 0;',
                            'left: 0;',
                            'margin: .3em;',
                            'padding: .6em;',
                            'opacity: 0.8;',
                            'paddign: 0 6px;',
                            'position: fixed;',
                            'text-align: center;',
                            'width: 320px;',
                            'font-size: 9pt;',
                            'z-index: 999;'
                          ].join(' '));
 
       inputEl.setAttribute('style', [
                              'background-color: #222;',
                              'border-bottom: 1px solid #cfccc6;',
                              'border-left: 1px solid #696660;',
                              'border-right: 1px solid #cfccc6;',
                              'border-top: 1px solid #696660;',
                              'color: #fafafa;',
                              'font-family: Monaco, monospace;',
                              'font-size: 9pt;',
                              'width: 80%;'
                            ].join(' '));
       labelEl.setAttribute('style', [
                              'color: #fafafa;',
                              'font-weight: bold;',
                              'font-size: 9pt;',
                              'margin-right: .3em;'
                            ].join(' '));
 
       divEl.appendChild(labelEl);
       divEl.appendChild(inputEl);
       document.body.appendChild(divEl);
 
       var post = function() {
         if ( inputEl.value != '' ) {
           inputEl.disabled = true;
           self.post(inputEl.value, function() {
                       self.endCall.call(self, inputEl.value);
                     });
         }
       };
 
       inputEl.addEventListener('keypress', function(e) {
                                  if ( e.keyCode == 27 ) {
                                    self.endCall.call(self);
                                    e.preventDefault();
                                    e.stopPropagation();
                                  }
                                  if ( e.keyCode == 13 ) {
                                    post();
                                    e.preventDefault();
                                    e.stopPropagation();
                                  }
                                }, false);
 
       this.title = labelEl;
       this.form = inputEl;
       this.content = divEl;
     },
     set: function() {
       this.content.style.display = 'block';
       this.form.focus();
       this.title.innerHTML = this.label;
     },
     endCall: function(mes) {
       this.content.style.display = 'none';
       this.form.disabled = false;
     },
     post: function(s, callback) {
 
       switch ( this.type ) {
       case 2:
         stdin = [ this.url + s.replace(/\s+/, '+') ];
         break;
       case 3:
         stdin = [ this.url + s ];
         break;
       default:
         stdin = [ this.url + encodeURIComponent(s) ];
         break;
       }
 
       window.Minibuffer.execute('open', stdin);
       callback();
     }
   };
 
   if ( typeof window.Minibuffer != 'undefined' ) {
     // Google
     var mySearch;
     window.Minibuffer.addCommand({
                                    name: 'My::GoogleSearch',
                                    command: function() {
                                      if ( !mySearch ) mySearch = new Search();
                                      mySearch.label = 'Google';
                                      mySearch.type = 1;
                                      mySearch.url = 'http://google.com/search?q=';
                                      mySearch.set();
                                    }
                                  });
     window.Minibuffer.addShortcutkey({
                                        key: 'M G',
                                        command: function() { window.Minibuffer.execute('My::GoogleSearch'); }
                                      });
 
     // CPAN
     window.Minibuffer.addCommand({
                                    name: 'My::CPANSearch',
                                    command: function() {
                                      if ( !mySearch ) mySearch = new Search();
                                      mySearch.label = 'CPAN';
                                      mySearch.type = 1;
                                      mySearch.url = 'http://search.cpan.org/search?mode=all&query=';
                                      mySearch.set();
                                    }
                                  });
     window.Minibuffer.addShortcutkey({
                                        key: 'M C',
                                        command: function() { window.Minibuffer.execute('My::CPANSearch'); }
                                      });
 
     // Yahoo!辞書
     window.Minibuffer.addCommand({
                                    name: 'My::DictionarySearch',
                                    command: function() {
                                      if ( !mySearch ) mySearch = new Search();
                                      mySearch.label = 'Y! Dict.';
                                      mySearch.type = 1;
                                      mySearch.url = 'http://dic.yahoo.co.jp/dsearch?enc=UTF-8&dtype=2&stype=0&p=';
                                      mySearch.set();
                                    }
                                  });
     window.Minibuffer.addShortcutkey({
                                        key: 'M D',
                                        command: function() { window.Minibuffer.execute('My::DictionarySearch'); }
                                      });
 
     // ニコニコ動画
     window.Minibuffer.addCommand({
                                    name: 'My::NicoVideoSearch',
                                    command: function() {
                                      if ( !mySearch ) mySearch = new Search();
                                      mySearch.label = 'NicoVideo',
                                      mySearch.type = 2;
                                      mySearch.url = 'http://www.nicovideo.jp/search/';
                                      mySearch.set();
                                    }
                                  });
     window.Minibuffer.addShortcutkey({
                                        key: 'M N',
                                        command: function() { window.Minibuffer.execute('My::NicoVideoSearch'); }
                                      });
 
     // Amazon.co.jp
     window.Minibuffer.addCommand({
                                    name: 'My::AmazonSearch',
                                    command: function() {
                                      if ( !mySearch ) mySearch = new Search();
                                      mySearch.label = 'Amazon';
                                      mySearch.type = 3;
                                      mySearch.url = 'http://www.amazon.co.jp/s/?__mk_ja_JP=%83J%83%5E%83J%83i&url=search-alias%3Daps&field-keywords=';
                                      mySearch.set();
                                    }
                                  });
     window.Minibuffer.addShortcutkey({
                                        key: 'M A',
                                        command: function() { window.Minibuffer.execute('My::AmazonSearch'); }
                                      });
 
     // Subscribe current url
     window.Minibuffer.addCommand({
                                    name: 'My::Subscribe',
                                    command: function(stdin) {
                                      return stdin.map(function(url) { return "javascript:location.href='http://reader.livedoor.com/subscribe/" + url + "'"; } );
                                    }
                                  });
     window.Minibuffer.addShortcutkey({
                                        key: 'M a',
                                        command: function() {
                                          window.Minibuffer.execute('location | My::Subscribe | open');
                                        }
                                      });
   }
 }) ();

Owner

xcezx

Revisions