forked from feiruo/userChromeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starClickMod40Up.uc.js
204 lines (186 loc) · 7.11 KB
/
starClickMod40Up.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
// ==UserScript==
// @name starClickMod.uc.js
// @description 多功能收藏按钮
// @author feiruo
// @compatibility Firefox 40
// @charset UTF-8
// @include chrome://browser/content/browser.xul
// @id [77DDE674]
// @startup window.starClick.init();
// @shutdown window.starClick.onDestroy(true);
// @reviewURL http://bbs.kafan.cn/thread-1657336-1-1.html
// @homepageURL https://github.com/feiruo/userChromeJS
// @note 参考star Click(http://g.mozest.com/viewthread.php?tid=41377)
// @note 为编辑面板增加更多功能
// @note 左键弹出书签添加编辑面板,中键打开书签侧栏,右键删除当前书签
// @version 1.8.5 兼容至53。
// @version 1.8.4 全面修复,仅支持40Up。设置放入about:config中,即时生效。
// @version 1.8.3 40Up。
// @version 1.8.2 building 部分功能可以自定义。
// @version 1.8.1 去除Holly,删掉多余的动作(修改五角星位置等)。
// @version 1.8 修正重启后可能按键失效的问题。
// @version 1.7 修复右键报错,Australis重整UI后失效问题,增加 中键 打开/隐藏 书签侧栏。
// @version 1.6 Australis 添加书签按钮移动至地址栏。
// @version 1.5 支持 Nightly Holly.
// @version 1.4 支持 firefox 24 以下版本.
// @version 1.3 修复了可能出现的文件夹列表不能自动展开和获取上次文件夹的问题.
// @version 1.2 修正因 firefox 26 添加了 bookmarks-menu-button 导致的判断出错.
// @version 1.1 修正因 Nightly Australis 没有删除 star-button 导致的判断出错.
// ==/UserScript==
location == "chrome://browser/content/browser.xul" && (function() {
if (window.starClick) {
window.starClick.onDestroy();
delete window.starClick;
}
var starClick = {
version: Services.appinfo.version.split(".")[0],
Default_PlacesCommandHook_bookmarkCurrentPage: PlacesCommandHook.bookmarkCurrentPage.toString(),
get prefs() {
delete this.prefs;
return this.prefs = Services.prefs.getBranch("userChromeJS.starClickMod.");
},
get StarBtn() {
if (this.version < 29)
return $('star-button');
else {
return $('bookmarks-menu-button');
// var NodeList = document.getAnonymousNodes($('bookmarks-menu-button'));
// var NodeList = document.getAnonymousNodes($('bookmarks-menu-button'));
// for (var i in NodeList) {
// if (!NodeList[i].className) continue;
// if (NodeList[i].className != "box-inherit toolbarbutton-menubutton-button") continue;
// return NodeList[i];
// }
}
},
init: function() {
this.AddListener(true);
this.Enable(true);
this.loadSetting();
this.prefs.addObserver('', this.PrefsObs, false);
},
onDestroy: function() {
this.AddListener(false);
this.Enable(false);
this.prefs.removeObserver('', this.PrefsObs, false);
},
PrefsObs: function(subject, topic, data) {
switch (topic) {
case 'nsPref:changed':
switch (data) {
case 'isAutoPopup':
case 'isLastFolder':
starClick.loadSetting(data);
break;
}
break;
}
},
loadSetting: function(type) {
if (!type || type === "isAutoPopup")
this.isAutoPopup = this.getPrefs(0, "isAutoPopup", true);
if (!type || type === "isLastFolder")
this.isLastFolder = this.getPrefs(0, "isLastFolder", true);
},
OpenPanel: function(isAlert) {
if (!isAlert) return;
setTimeout(function() {
gEditItemOverlay.toggleFolderTreeVisibility();
//gEditItemOverlay.toggleTagsSelector();
}, 50);
let folderTree = document.getElementById("editBMPanel_folderTreeRow");
folderTree.height = 300;
//let tagsSelector = document.getElementById("editBMPanel_tagsSelectorRow");
//tagsSelector.height = 75;
document.getAnonymousNodes($('editBMPanel_tagsSelector'))[1].lastChild.style.display = 'inline-block';
},
GetLastFolderId: function() {
var LAST_USED_ANNO = "bookmarkPropertiesDialog/folderLastUsed";
var annos = PlacesUtils.annotations;
var folderIds = annos.getItemsWithAnnotation(LAST_USED_ANNO);
var _recentFolders = [];
for (var i = 0; i < folderIds.length; i++) {
var lastUsed = annos.getItemAnnotation(folderIds[i], LAST_USED_ANNO);
_recentFolders.push({
folderId: folderIds[i],
lastUsed: lastUsed
});
}
_recentFolders.sort(function(a, b) {
if (b.lastUsed < a.lastUsed) return -1;
if (b.lastUsed > a.lastUsed) return 1;
return 0;
});
return _recentFolders.length > 0 ? _recentFolders[0].folderId : PlacesUtils.unfiledBookmarksFolderId;
},
AddListener: function(isAlert) {
this.StarBtn.removeEventListener("click", starClick.Click, false);
if (!this.StarBtn || !isAlert) return;
this.StarBtn.addEventListener("click", starClick.Click, false);
},
Enable: function(isAlert) {
eval('PlacesCommandHook.bookmarkCurrentPage =' + this.Default_PlacesCommandHook_bookmarkCurrentPage);
if (!isAlert) return;
var hook = this.hook.toString();
eval('PlacesCommandHook.bookmarkCurrentPage =' + hook);
},
hook: function PCH_bookmarkCurrentPage(aShowEditUI, aParent) {
var isParent = starClick.GetLastFolderId(starClick.isLastFolder);
this.bookmarkPage(gBrowser.selectedBrowser, isParent ? isParent : aParent, starClick.isAutoPopup);
starClick.OpenPanel(starClick.isAutoPopup);
},
Click: function(event) {
if (starClick.version > 29) {
var Btn;
var NodeList = document.getAnonymousNodes($('bookmarks-menu-button'));
for (var i in NodeList) {
if (!NodeList[i].className) continue;
if (NodeList[i].className != "box-inherit toolbarbutton-menubutton-button") continue;
Btn = NodeList[i];
}
if (event.originalTarget != Btn) return;
}
switch (event.button) {
case 0:
break;
case 1:
toggleSidebar('viewBookmarksSidebar');
event.stopPropagation();
break;
case 2:
var itemId = PlacesUtils.getMostRecentBookmarkForURI(gBrowser.selectedBrowser.currentURI);
if (itemId == -1) return;
event.preventDefault();
try {
Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService).removeItem(itemId);
} catch (ex) {
console.log(ex)
}
event.stopPropagation();
break;
}
},
getPrefs: function(type, name, val) {
switch (type) {
case 0:
if (!this.prefs.prefHasUserValue(name) || this.prefs.getPrefType(name) != Ci.nsIPrefBranch.PREF_BOOL)
this.prefs.setBoolPref(name, val ? val : false);
return this.prefs.getBoolPref(name);
break;
case 1:
if (!this.prefs.prefHasUserValue(name) || this.prefs.getPrefType(name) != Ci.nsIPrefBranch.PREF_INT)
this.prefs.setIntPref(name, val ? val : 0);
return this.prefs.getIntPref(name);
break;
case 2:
if (!this.prefs.prefHasUserValue(name) || this.prefs.getPrefType(name) != Ci.nsIPrefBranch.PREF_STRING)
this.prefs.setCharPref(name, val ? val : "");
return this.prefs.getCharPref(name);
break;
}
},
};
function $(id) document.getElementById(id);
starClick.init();
window.starClick = starClick;
})();