Skip to content

Instantly share code, notes, and snippets.

@Griever
Created February 1, 2012 09:34
Show Gist options
  • Save Griever/1716153 to your computer and use it in GitHub Desktop.
Save Griever/1716153 to your computer and use it in GitHub Desktop.
ブックマーク登録メニューにスターボタンのようなアイコンを付ける
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
/*
CSS だけでできたヽ(´ー`)ノ…できてなかった><
*/
#context-bookmarkpage,
/*#context-bookmarkframe,
#context-bookmarklink,*/
#menu_bookmarkThisPage {
-moz-binding: url("chrome://global/content/bindings/menu.xml#menuitem-iconic") !important;
}
:-moz-any(
#context-bookmarkpage,
/* #context-bookmarkframe,
#context-bookmarklink,*/
#menu_bookmarkThisPage) .menu-iconic-icon
{
background: transparent no-repeat center center -moz-element(#star-button) !important;
}
// ==UserScript==
// @name BookmarksIconic.uc.js
// @description ブックマーク登録メニューにスターボタンのようなアイコンを付ける
// @namespace http://d.hatena.ne.jp/Griever/
// @author Griever
// @license MIT License
// @compatibility Firefox 10
// @charset UTF-8
// @include main
// @version 0.0.1
// ==/UserScript==
(function(css){
({
init: function() {
$('bookmarksMenuPopup').addEventListener("popupshowing", this, false);
$('contentAreaContextMenu').addEventListener("popupshowing", this, false);
window.addEventListener("unload", this, false);
this.style = addStyle(css);
},
uninit: function() {
$('bookmarksMenuPopup').removeEventListener("popupshowing", this, false);
$('contentAreaContextMenu').removeEventListener("popupshowing", this, false);
window.removeEventListener("unload", this, false);
},
destroy: function() {
this.uninit();
if (this.style) this.style.parentNode.removeChild(this.style);
},
handleEvent: function(event) {
switch(event.type){
case "popupshowing":
if (event.target != event.currentTarget) return;
if (event.target.id === "bookmarksMenuPopup") {
$('menu_bookmarkThisPage').setAttribute("starred", this.hasBookmarks(gBrowser.currentURI));
}
else if (event.target.id === "contentAreaContextMenu") {
$('context-bookmarkpage').setAttribute("starred", this.hasBookmarks(gContextMenu.browser.currentURI));
$('context-bookmarklink').setAttribute("starred", gContextMenu.onLink ? this.hasBookmarks(gContextMenu.linkURL) : "false");
}
break;
case "unload":
this.uninit();
break;
}
},
hasBookmarks: function(aURI) {
var uri = typeof aURI == "string" ? makeURI(aURI) : aURI;
return PlacesUtils.getMostRecentBookmarkForURI(uri) != -1;
}
}).init();
function $(id) { return document.getElementById(id); }
function addStyle(css) {
var pi = document.createProcessingInstruction(
'xml-stylesheet',
'type="text/css" href="data:text/css;utf-8,' + encodeURIComponent(css) + '"'
);
return document.insertBefore(pi, document.documentElement);
}
})(<![CDATA[
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
#menu_bookmarkThisPage[starred],
#context-bookmarkpage[starred],
#context-bookmarklink[starred] {
-moz-binding: url("chrome://global/content/bindings/menu.xml#menuitem-iconic") !important;
list-style-image: url("chrome://browser/skin/places/bookmark.png") !important;
-moz-image-region: rect(0px, 16px, 16px, 0px) !important;
}
#menu_bookmarkThisPage[starred="true"],
#context-bookmarkpage[starred="true"],
#context-bookmarklink[starred="true"] {
list-style-image: url("chrome://browser/skin/places/editBookmark.png") !important;
}
]]>.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment