Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Created July 2, 2009 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherenkov/139796 to your computer and use it in GitHub Desktop.
Save cherenkov/139796 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name stylishEditButton.uc.js
// @namespace http://d.hatena.ne.jp/Cherenkov/
// @description http://d.hatena.ne.jp/Cherenkov/20090703/p1
// @include chrome://browser/content/browser.xul
// ==/UserScript==
(function(){
function contextEdit(event) {
var item = document.evaluate('//*[@class="style-menu-item"]', stylishPopup, null, 7, null);
var btn = document.evaluate('//*[@class="stylishEditBtn"]', stylishPopup, null, 7, null);
if(item.snapshotLength == btn.snapshotLength)
return false;
if(event.type == "popupshowing") {
var style = Components.classes["@userstyles.org/style;1"]
.getService(Components.interfaces.stylishStyle)
.findForUrl(stylishCommon.cleanURI(content.document.location.href), false, 0, {});
for(var i = 0; i < item.snapshotLength; i++) {
var editBtn = document.createElement("menuitem");
editBtn.setAttribute("class", "stylishEditBtn");
editBtn.setAttribute("id", style[i].id);
editBtn.setAttribute("label", "edit " + style[i].name);
editBtn.addEventListener("command", function() {
stylishCommon.openEditForId(this.id);
}, false);
item.snapshotItem(i).parentNode.insertBefore(editBtn, item.snapshotItem(i).nextSibling);
}
} else {
for(var i = 0; i<btn.snapshotLength; i++)
btn.snapshotItem(i).parentNode.removeChild(btn.snapshotItem(i));
}
}
var stylishPopup = document.getElementById("stylish-popup");
stylishPopup.addEventListener("popupshowing", contextEdit, false);
stylishPopup.addEventListener("popuphiding", contextEdit, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment