forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindSelectionInFindbar.uc.js
More file actions
117 lines (103 loc) · 3.84 KB
/
findSelectionInFindbar.uc.js
File metadata and controls
117 lines (103 loc) · 3.84 KB
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
// ==UserScript==
// @name findSelectionInFindbar.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description FindBarの選択テキスト上でマウスホイールによる選択テキスでの検索を可能にする。SearchWP-2.4.2.12.04.25.01がある場合は選択せずとも日本語のトークンを自動判定する
// @include main
// @include chrome://global/content/viewSource.xul
// @include chrome://global/content/viewPartialSource.xul
// @compatibility Firefox 12-15
// @author Alice0775
// @version 2012/05/01 21:30 delete this.xxx;
// @version 2012/05/01 20:00
// ==/UserScript==
var findSelectionInFindbar = {
// addHistoryFindbarFx3.0.uc.js
get _findField2(){
delete this._findField2;
return this._findField2 = document.getElementById("find-field2");
},
// addHistoryFindbarFx3.0.uc.js
get inputbox2(){
delete this.inputbox2;
return this.inputbox2 = document.getAnonymousElementByAttribute(this._findField2,
"anonid",
"textbox-input-box");
},
get _findField() {
return this._findField2 || gFindBar._findField;
},
init: function() {
if (!gFindBar)
return;
window.addEventListener("unload", this, false);
setTimeout((function(){
var target = this._findField;
target.addEventListener("DOMMouseScroll", this, false);
}).bind(this), 1000)
},
uninit: function() {
window.removeEventListener("unload", this, false);
var target = this._findField;
target.removeEventListener("DOMMouseScroll", this, false);
},
handleEvent: function(event) {
switch(event.type) {
case "DOMMouseScroll":
this.onDOMMouseScroll(event);
break;
case "unload":
this.uninit();
break;
}
},
_findFast: function(aWord, aFindBackwards, aMatchCase) {
var fastFind = window.getBrowser().fastFind;
fastFind.caseSensitive = aMatchCase;
var result = Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND;
if (fastFind.searchString != aWord) {
result = fastFind.find(aWord, false);
}
else {
result = fastFind.findAgain(aFindBackwards, false);
}
// a
if(typeof ucjsFind != 'undefined') ucjsFind._dispSelectionCenter(result);
gFindBar._updateStatusUI(result, aFindBackwards);
},
onDOMMouseScroll: function(event) {
if ( event.rangeParent.nodeType != 3 ) {
return;
}
var term;
var offset = event.rangeOffset;
var a = this._findField.selectionStart;
var b = this._findField.selectionEnd;
//userChrome_js.debug(a);
if ( (offset < a || offset >= b) &&
("gSearchWP" in this.getWin && "Tokenizer" in this.getWin.gSearchWP && "getByOffset" in this.getWin.gSearchWP.Tokenizer)) {
// gSearchWP
var match = this.getWin.gSearchWP.Tokenizer.getByOffset( this._findField.value, offset );
if ( match ) {
term = match.value;
this._findField.selectionStart = match.index;
this._findField.selectionEnd = match.index + term.length;
}
} else {
term = this._findField.value.substring( a, b );
}
if ( term ) {
var findBackwards = event.detail < 0 ? true : false;
var matchCase = event.altKey || event.ctrlKey;
this._findFast( term, findBackwards, matchCase);
}
},
get getWin() {
var mediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
if(mediator.getMostRecentWindow("navigator:browser"))
return mediator.getMostRecentWindow("navigator:browser");
else if (mediator.getMostRecentWindow("mail:3pane"))
return mediator.getMostRecentWindow("mail:3pane");
}
}
findSelectionInFindbar.init();