forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoCloseHistoryFolder_Fx37.uc.js
231 lines (211 loc) · 8.81 KB
/
AutoCloseHistoryFolder_Fx37.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// ==UserScript==
// @name acHistoryFolder_Fx37
// @namespace http://www.sephiroth-j.de/mozilla/
// @description Autoclose History Folders
// @include chrome://browser/content/history/history-panel.xul
// @compatibility Firefox 3.7
// @author original Ronny Perinke
// @version original Autoclose Bookmark History Folders 0.5.5
// @modiffied Alice0775
// @version 2008/11/28 Firefox3.1b3pre tboの初期化に時間が掛かるようでsetTimeoutするようにした
// @Note http://space.geocities.yahoo.co.jp/gl/alice0775
// @Note I got permission to open this script to the public from Mr.Sephiroth on July 28,2007.
// ==/UserScript==
// @version 2007/07/16
/* ***** BEGIN LICENSE BLOCK *****
* Author: Ronny Perinke http://www.sephiroth-j.de
*
* License: This extension is subject to MPL 1.1/GPL 2.0/LGPL 2.1
* You may obtain a copy of the License at http://www.mozilla.org/MPL/ and http://www.gnu.org/copyleft/gpl.html
* other rules:
* 1) If you use any of this code please include references or credit in your code to myself, and include my homepage URL
* 2) You MUST contact me, the author before you use this code (I like to know that it's been usefull).
* 3) I would greatly appreciate a link back to me or credit somewhere on your site (makes me feel good, not required).
* 4) If improvments are made to the code, please inform me so that I can use it (if applicable, not required).
* 5) Translators: please contact me and send me a copy of the language files and/or the new xpi with the new language.
* I'd like to include them in the official xpi on my server. You will list you in the contributors list.
*
* ***** END LICENSE BLOCK ***** */
var acHistoryFolder = {
_Prefs: {
ScrollToRow : true, //次回サイドバーオープン時に現在開いているフォルダをトップにもってくる
SelectLast : true //次回サイドバーオープン時に現在開いているフォルダを開いてフォーカスする
},
get _BTree() {
return document.getElementById("historyTree");
},
init: function(){
if (!this._BTree)
return;
this._BTree.addEventListener('click', function(event){acHistoryFolder.onClick(event);},false);
this.loadPrefs();
this.addToolbar();
var viewtype = document.getElementById("viewButton").getAttribute('selectedsort');
if (this._BTree.result && this._Prefs.SelectLast){
setTimeout(function(self){
var lastRowToSelect = self.getPref("ac-HistoryTreeFolder.lastBookmarkFolder."+viewtype,"int",0);
var tbo = self._BTree.treeBoxObject;
if (tbo && tbo.view.rowCount >= lastRowToSelect){
if(viewtype == "byday" || viewtype == "bydayandsite")
tbo.scrollToRow(lastRowToSelect);
tbo.view.selection.select(lastRowToSelect);
tbo.ensureRowIsVisible(lastRowToSelect);
}
}, 100, this);
}
},
uninit: function(){
this._BTree.removeEventListener('click', function(event){acHistoryFolder.onClick(event);},false);
},
loadPrefs: function(){
this._Prefs.SelectLast = this.getPref("ac-HistoryTreeFolder.ReselectLastFolder","bool",this._Prefs.SelectLast);
this._Prefs.ScrollToRow = this.getPref("ac-HistoryTreeFolder.ScrollToLastFolder","bool",this._Prefs.ScrollToRow);
},
addToolbar: function(){
const kXULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var toolbar = document.getElementById("acHistoryFolder-toolbar");
if (toolbar){
return;
}
var toolbox = document.createElementNS(kXULNS, "toolbox");
toolbar = document.createElementNS(kXULNS, "toolbar");
toolbar.setAttribute("id", "acHistoryFolder-toolbar");
var closeAllButton = document.createElementNS(kXULNS, "toolbarbutton");
closeAllButton.setAttribute("label", "\u6298\u7573");//折畳
closeAllButton.setAttribute("oncommand", "acHistoryFolder.closeAll();");
var openAllButton = document.createElementNS(kXULNS, "toolbarbutton");
openAllButton.setAttribute("label", "\u5c55\u958b");//展開
openAllButton.setAttribute("oncommand", "acHistoryFolder.openAll();");
toolbar.appendChild(closeAllButton);
toolbar.appendChild(openAllButton);
toolbox.appendChild(toolbar);
this._BTree.parentNode.insertBefore(toolbox, this._BTree);
var viewbutton = document.getElementById("viewButton");
if (viewbutton){
viewbutton.addEventListener("command", acHistoryFolder.updateTBButtons, false);
var enabled = (viewbutton.getAttribute("selectedsort") == "day" || viewbutton.getAttribute("selectedsort") == "dayandsite");
closeAllButton.disabled = !enabled;
openAllButton.disabled = !enabled;
}
},
updateTBButtons: function(aEvent){
var enabled = (aEvent.target.id == "byday" || aEvent.target.id == "bydayandsite");
var toolbar = document.getElementById("acHistoryFolder-toolbar");
toolbar.firstChild.disabled = !enabled;
toolbar.lastChild.disabled = !enabled;
},
onClick: function(aEvent){
var parents = new Array();
var tbo = this._BTree.treeBoxObject;
var aView = tbo.view;
if (aEvent.button != 0){
return;
}
var row = {}, col = {}, obj = {};
tbo.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
if (row.value == -1)
return;
if(!aView.isContainer(row.value))
return;
if (this._BTree.currentIndex != row.value){
return;
}
aView.selection.select(this._BTree.currentIndex);
for (var i = this._BTree.currentIndex; i != -1; i = aView.getParentIndex(i)){
parents.push(i);
}
parents.reverse();
for (var i = aView.rowCount - 1; i >= 0; i--){
if (i == parents[parents.length - 1]){
parents.pop();
}else{
if (aView.isContainer(i) && aView.isContainerOpen(i)){
aView.toggleOpenState(i);
}
}
}
tbo.ensureRowIsVisible(this._BTree.currentIndex);
var viewtype = document.getElementById("viewButton").getAttribute('selectedsort');
if (this._Prefs.SelectLast)
this.setPref("ac-HistoryTreeFolder.lastBookmarkFolder."+viewtype ,"int",this._BTree.currentIndex);
aEvent.preventDefault();
},
closeAll: function(){
var aView = this._BTree.treeBoxObject.view;
try{
var viewtype = document.getElementById("viewButton").getAttribute('selectedsort');
this._PrefsIFace.clearUserPref("ac-HistoryTreeFolder.lastBookmarkFolder."+viewtype);
}catch(e){}
if (aView){
for (var i = aView.rowCount-1; i>=0; i--){
if (aView.isContainer(i) && aView.isContainerOpen(i)) aView.toggleOpenState(i);
}
}
},
openAll: function(){
var aView = this._BTree.treeBoxObject.view;
try{
var viewtype = document.getElementById("viewButton").getAttribute('selectedsort');
this._PrefsIFace.clearUserPref("ac-HistoryTreeFolder.lastBookmarkFolder."+viewtype);
}catch(e){}
if (aView){
var oldrows = -1;
var rows = aView.rowCount;
do{
for (var i = rows-1; i>=0; i--){
if (aView.isContainer(i) && !aView.isContainerOpen(i)) aView.toggleOpenState(i);
}
oldrows = rows;
rows = aView.rowCount;
}
while(rows != oldrows);
}
},
clearPref: function(aPrefString){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch2);
xpPref.clearUserPref(aPrefString);
},
getPref: function(aPrefString, aPrefType, aDefault){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch2);
try{
switch (aPrefType){
case 'complex':
return xpPref.getComplexValue(aPrefString, Components.interfaces.nsILocalFile); break;
case 'str':
return xpPref.getCharPref(aPrefString).toString(); break;
case 'int':
return xpPref.getIntPref(aPrefString); break;
case 'bool':
default:
return xpPref.getBoolPref(aPrefString); break;
}
}catch(e){
}
return aDefault;
},
setPref: function(aPrefString, aPrefType, aValue){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch2);
try{
switch (aPrefType){
case 'complex':
return xpPref.setComplexValue(aPrefString, Components.interfaces.nsILocalFile, aValue); break;
case 'str':
return xpPref.setCharPref(aPrefString, aValue); break;
case 'int':
aValue = parseInt(aValue);
return xpPref.setIntPref(aPrefString, aValue); break;
case 'bool':
default:
return xpPref.setBoolPref(aPrefString, aValue); break;
}
}catch(e){
}
return null;
}
}
acHistoryFolder.init();
document.addEventListener('unload', acHistoryFolder.uninit, false);