forked from feiruo/userChromeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarUrlicon.uc.js
156 lines (151 loc) · 10 KB
/
StarUrlicon.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
// ==UserScript==
// @name StarUrlicon.uc.js
// @author feiruo
// @description Australis 收藏按钮移动到地址栏
// @charset utf-8
// @include chrome://browser/content/browser.xul
// @homepage https://github.com/feiruo/userchromejs/
// @inspect window.StarUrlicon
// @startup window.StarUrlicon.init();
// @shutdown window.StarUrlicon.onDestroy();
// @homepageURL https://github.com/feiruo/userchromejs/
// @downloadURL https://github.com/feiruo/userChromeJS/blob/master/StarUrlicon.uc.js
// @note Australis收藏按钮移动到地址栏,参考黒仪大螃蟹的BMStar.uc.js(http://pan.baidu.com/share/link?uk=2467242534&shareid=545029)
// @version 1.2 2016.08.24 16:00 随Firefox版本更新;
// @version 1.1 左键添加书签,中键删除当前页面书签,右键 打开/隐藏 书签侧栏。
// ==/UserScript==
location == "chrome://browser/content/browser.xul" && (function(CSS) {
if (window.StarUrlicon) {
window.StarUrlicon.onDestroy();
delete window.StarUrlicon;
}
var StarUrlicon = {
Prefs: Services.prefs.getBranch("userChromeJS.StarUrlicon."),
StarBtn: $('bookmarks-menu-button'),
init: function() {
if (!this.StarBtn) return;
this.StarBtnOrg = this.StarBtn.parentNode;
$('urlbar-icons').appendChild(this.StarBtn);
this.LoadSetting();
this.Prefs.addObserver('', this.PrefsObs, false);
},
onDestroy: function() {
this.StarBtnOrg.appendChild(this.StarBtn);
this.AddStyle(false, 'Dropmarker', "#bookmarks-menu-button > dropmarker{visibility:collapse!important;}");
this.Prefs.removeObserver('', this.PrefsObs, false);
this.AddAssis(false, 'Global', CSS);
},
LoadSetting: function(type) {
if (!type || type === "Dropmarker")
this.AddStyle(this.GetPrefs(0, "Dropmarker", true), 'Dropmarker', "#bookmarks-menu-button > dropmarker{visibility:collapse!important;}");
if (!type || type === "Assistant")
this.AddAssis(this.GetPrefs(0, "Assistant", true));
if (!type || type === "CSS")
this.AddStyle(this.GetPrefs(0, "CSS", true), 'Global', CSS);
},
PrefsObs: function(subject, topic, data) {
switch (topic) {
case 'nsPref:changed':
switch (data) {
case 'Dropmarker':
case 'CSS':
case 'Assistant':
StarUrlicon.LoadSetting(data);
break;
}
break;
}
},
EventListener: function(event) {
event.preventDefault();
event.stopPropagation();
switch (event.button) {
case 0:
PlacesCommandHook.bookmarkCurrentPage(true);
break;
case 1:
var uri = gBrowser.selectedBrowser.currentURI;
var itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
var navBookmarksService = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
navBookmarksService.removeItem(itemId);
break;
case 2:
toggleSidebar('viewBookmarksSidebar');
break;
}
},
AddAssis: function(isAlert) {
this.StarBtn.removeEventListener("click", StarUrlicon.EventListener, false);
if (!isAlert) return;
this.StarBtn.addEventListener("click", StarUrlicon.EventListener, false);
},
AddStyle: function(isAlert, n, css = '', SHEET = 'AGENT_SHEET') {
this.CSSList || (this.CSSList = [])
if (typeof isAlert == 'string') {
css = n;
n = isAlert;
isAlert = true;
}
this.CSSList[n] = makeURI('data:text/css,' + encodeURIComponent(css));
var SSSS = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
try {
SSSS.unregisterSheet(this.CSSList[n], SSSS[SHEET]);
} catch (ex) {}
if (!isAlert) return;
SSSS.loadAndRegisterSheet(this.CSSList[n], SSSS[SHEET]);
},
GetPrefs: function(type, name, val) {
switch (type) { //https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Preferences
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);
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);
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);
case 3:
if (!this.Prefs.prefHasUserValue(name) || this.Prefs.getPrefType(name) != Ci.nsIPrefBranch.PREF_STRING) this.Prefs.setComplexValue(name, Ci.nsILocalFile, makeURI(val).QueryInterface(Ci.nsIFileURL).file);
return this.Prefs.getComplexValue(name, Ci.nsILocalFile);
case 4:
if (!this.Prefs.prefHasUserValue(name) || this.Prefs.getPrefType(name) != Ci.nsIPrefBranch.PREF_STRING) {
var aFile = Cc["@mozilla.org/pref-relativefile;1"].createInstance(Ci.nsIRelativeFilePref);
aFile.relativeToKey = "UChrm";
var path = Services.io.newFileURI(FileUtils.getDir("UChrm", '')).spec + val.replace(/^(\/\/|\\)/i, '').replace(/\\/ig, '/');
aFile.file = makeURI(path).QueryInterface(Ci.nsIFileURL).file;
this.Prefs.setComplexValue(name, Ci.nsIRelativeFilePref, aFile || this[name]);
}
return this.Prefs.getComplexValue(name, Ci.nsIRelativeFilePref).file;
default:
break;
}
}
};
function $(id) document.getElementById(id);
StarUrlicon.init();
window.StarUrlicon = StarUrlicon;
})('\
#bookmarks-menu-button {\
list-style-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAtCAYAAABxsjF3AAAAGXRFWHRTb2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i8wpK//WNIyfO3AspiwuROFA0jh9HXlcFpM+JJjbxk32CQ3wn4dGvv7QrY7LmHX724C+7hsdDqcVYgtwqCOazZKKJTfxkn+AInvCydcbFrMXpORKOiEoikcFbBYvA4LgQImpiEz/ZR9wriA+sKNXhr9fMqVmZx7sOsCVByUiQkSnAfwE48TIQfzi8wCMuZLLnP9QkFF1DMzKVSkowey8In04GYC4YydgdAlNY4ALipyn8HcQh+vKK9sRvVU1akqHv+hhcuNAXi6ctp174UVc70cTu7RvBmZezuEc6TGc0J+9PzcdWqd0X9x384Ul7ftF1jO3u4Tc7h+ZmJk51njx6YHEpuN2Rb04uc/4jwACnFx3FfyjlHQAAAABJRU5ErkJggg==") !important;\
-moz-image-region: rect(0, 15px, 15px, 0) !important;\
margin-bottom: 1px !important;\
}\
#bookmarks-menu-button:not([starred]):hover {\
-moz-image-region: rect(15px, 15px, 30px, 0) !important;\
}\
#bookmarks-menu-button[starred] {\
-moz-image-region: rect(30px, 15px, 45px, 0) !important;\
}\
#bookmarks-menu-button >toolbarbutton,#bookmarks-menu-button >toolbarbutton .toolbarbutton-icon {\
-moz-appearance: none!important;\
border: none!important;\
box-shadow: none!important;\
background: none!important;\
margin: 0!important;\
}\
#bookmarks-menu-button > dropmarker > image {\
list-style-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABASURBVDhPY6AKCI7P+g/CUC6cTwhDlVPBgIEH6E5CdiY+DFU+GgYggC6ArAgfhiofDADdScjOxIehygc0DBgYAC8oyiFzn8OSAAAAAElFTkSuQmCC") !important;\
-moz-image-region: rect(0px, 16px, 16px, 0px) !important;\
}\
'.replace(/\n|\t/g, ''));