forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enableKeywordsSearchInSearchBar.uc.js
134 lines (125 loc) · 4.82 KB
/
enableKeywordsSearchInSearchBar.uc.js
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
// ==UserScript==
// @name enableKeywordsSearchInSearchBar.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Enable Keywords Search In SearchBar
// @include main
// @compatibility Firefox 2.0 3.0 3.1
// @author Alice0775
// @Note Keywords Searchを検索バーから行えるようにする
// @Note conqueryModoki2がある場合は, 親フォルダにKeywordsを付加していれば, Keywords 串刺し検索が出来る
// @Note サーチバーを表示していないとダメ
// @version 2012/12/08 22:30 Bug 788290 Bug 788293 Remove E4X
// ==/UserScript==
// @version 2009/08/02 Tab Mix Plusはもはや対応しない
// @version 2009/06/13 Tab Mix Plus0.3.7.4pre.090516
// @version 2009/05/08 00:30 キワードサーチのurlがjavascriptの場合はカレントタブに開くように
// @version 2009/02/18 14:30 Full Screen でも動作するように
// @version 2008/09/26 11:00 For checked in Bug 337345
// @version 2008/07/26 15:30 NoScript 1.7.7をインストールしている場合に対応
// @version 2008/07/26 conqueryModoki2がある場合はKeywords 串刺し検索を追加
// @version 2008/07/04 Tab Mix Plusにも
// @version 2008/07/02
(function(){
window.kusizasi = function(name, param){
const nsIBSS = Components.interfaces.nsIBrowserSearchService;
const searchService =Components.classes["@mozilla.org/browser/search-service;1"].getService(nsIBSS);
var popup = document.getElementById("context-conqueryModoki-popup");
if (!conqueryModoki || !popup)
return;
var walker = document.createTreeWalker(popup, NodeFilter.SHOW_ELEMENT, null, true);
var target;
while ((target = walker.nextNode())){
if (target.localName.toLowerCase() != "menu" )
continue;
if (target.getAttribute("label") == name.replace(/^{/,'')){
var result = document.evaluate("*/*[@class = 'menuitem-iconic searchbar-engine-menuitem']",target,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
//alert(result.snapshotLength);
var searchBar = conqueryModoki.searchBar();
if (searchBar)
searchBar.value = param;
var anewTab = true;
for(var i=0; i<result.snapshotLength; i++){
try{
setTimeout(function(self, aEngine,selected,anewTab){
self.loadSearch(aEngine, selected, anewTab, false, false) //検索実行
setTimeout(function(){conqueryModoki._dispatchEvent();},0);
},100, conqueryModoki, result.snapshotItem(i).engine, param, anewTab);
}catch(e){}
}
conqueryModoki.clearSearchBar();
}
}
}
if (gURLBar && "handleCommand" in gURLBar){
var func = gURLBar.handleCommand.toString();
//Hack Noscript [noscriptBM.js]
func = func.replace(
'var url = getShortcutOrURI(shortcut, {});',
'$& \
if (!url){ \
this.handleRevert(); \
return; \
}'
);
eval("gURLBar.handleCommand = " + func);
} else {
var func = handleURLBarCommand.toString();
func = func.replace(
'canonizeUrl(aTriggeringEvent, postData);',
'$& \
if(!gURLBar.value){ \
/* Revert the contents of the location bar */ \
handleURLBarRevert(); \
return; \
}'
);
//Hack Noscript
func = func.replace(
'var url = getShortcutOrURI(shortcut, {});',
'$& \
if (!url){ \
handleURLBarRevert(); \
return; \
}'
);
eval("handleURLBarCommand = " + func);
}
var func = getShortcutOrURI.toString();
func = func.replace(
'if (engine) {',
'if (engine && !!param.replace(/^\s+/,\'\').replace(/\s+$/,\'\')) { \
if(engine.name.match(/^{/) && !engine.name.match(/}/)){ \
if ("conqueryModoki" in window) \
kusizasi(engine.name, param); \
return ""; \
}'
);
eval("getShortcutOrURI = " + func);
var searchBar = document.getElementById("searchbar");
if (!searchBar)
return
{ //素Fx
searchBar.doSearch__keyworks = searchBar.doSearch;
searchBar.doSearch = function(aData, aWhere){
var shortcutURL = null;
var aPostDataRef = {};
var offset = aData.indexOf(" ");
if (offset > 0) {
shortcutURL = getShortcutOrURI(aData, aPostDataRef)
if (!shortcutURL)
return;
}
if (shortcutURL && shortcutURL != aData){
//remove keyword
this._textbox.value = aData.substr(offset + 1);
//do keyword search
if (/^javascript:/.test(shortcutURL))
aWhere = "current";
openUILinkIn(shortcutURL, aWhere, null, aPostDataRef.value);
} else {
//do normal search
this.doSearch__keyworks(aData, aWhere)
}
}
}
})();