diff --git a/StarUrlicon.uc.js b/StarUrlicon.uc.js new file mode 100644 index 0000000..a339a1f --- /dev/null +++ b/StarUrlicon.uc.js @@ -0,0 +1,55 @@ +// ==UserScript== +// @name StarUrlicon.uc.js +// @description Australis 收藏按钮移动到地址栏 +// @homepage https://github.com/feiruo/userchromejs/ +// @author feiruo +// @include chrome://browser/content/browser.xul +// @charset utf-8 +// @version 1.0 +// @note 参考黒仪大螃蟹的BMStar.uc.js(http://pan.baidu.com/share/link?uk=2467242534&shareid=545029) +// @note 收藏按钮移动到地址栏,左键添加书签并弹出编辑窗口,右键删除当前页面书签 +// @note 仅Australis 适用 +// ==/UserScript== +(function() { + var urlIcon = document.getElementById('urlbar-icons'); + var starbutton = document.getElementById('bookmarks-menu-button'); + if (!starbutton) return; + urlIcon.appendChild(starbutton); + var menupopup = starbutton.firstChild; + var cssStr = ('\ + #bookmarks-menu-button {\ + list-style-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAtCAYAAABxsjF3AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmF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YRwzIShp0RquXScwwBF/umAc2hWPNka9BGtborR56IRSE+5MDyt2hc9RI78eZ0toGxutvUwSrk+K1FjaVBi+ybyMemAYcBU5jhORSdAvwxj2pxDxcOvXz4J2Roe8nRXHv9K0xLG13QzQa1ITuhyAamfuIUxtHEQ/Uy61kiLNvvhPlHczgm2i+jWvxfwZeg77vovEdWob9Mg0fEQ71uFty70ZnGcvQF9MZufm97vs3c2GoY4fac5Knxm926jR0+5Ion/EUl+36whfd7ZGBSk+eob3MlwdEE/v/XnQr5tlmOlpU4AC32ww6nQqWROUoutsfS775yfW1HEuvs5q15cVF9p2rvTawmPXY3wyEo+LO8Ynx10IL8SEpLQ+UPVE1kiUP9vacU/F0q9Omoy1mLbjsJigpdoPNbga9jse25MBfotAszfwgMBeG+YU4jA32ycmU/AHrcucJNiFD+4pc4LALIAg6EEx60Gg02QHR0zzkswzoDRqIRJYgOBeBsYkA/SDCCMyfuz4cG+vvftZl5dVejx3MVgG0Wh2QK5fGPmewz3lcq9QcYFgQjcZhMaEJf/vV49+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;\ + }\ + '); + var style = document.createProcessingInstruction('xml-stylesheet', 'type="text/css" href="data:text/css;utf-8,' + encodeURIComponent(cssStr) + '"'); + document.insertBefore(style, document.documentElement); + + starbutton.addEventListener("click", function(e) { + if (e.button == 0) { + PlacesCommandHook.bookmarkCurrentPage(true); + } + if (e.button == 2) { + 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); + } + e.preventDefault(); + e.stopPropagation() + }, false); +})(); \ No newline at end of file