mahtanoronraЦитата: не пашет кнопочка что на 38 1 1
[more=Исправленная версия]
Код: /*Initialization Code*/
//Добавление в меню расширений дополнительных пунктов
(function(){
var iconURL = null;
let { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AddonManager.jsm");
try {
Cu.import("resource://gre/modules/XPIProvider.jsm");
}
catch(e) {
Cu.import("resource://gre/modules/addons/XPIProvider.jsm");
}
const usoRegx = /^https?:\/\/userscripts.org\/scripts\/source\/\d+.\w+.js$/;
window.AMD_Helper = {
init: function(){
addEventListener("DOMContentLoaded", this, false, document);
this.addHomePageForScriptish();
},
handleEvent: function(event){
switch(event.type){
case "DOMContentLoaded":
var doc = event.target;
var win = doc.defaultView;
if (["about:addons","chrome://mozapps/content/extensions/extensions.xul"].indexOf(doc.URL) == -1)
return;
this.addPopupMenu(doc);
win.AMD_Helper = AMD_Helper;
this.win = win;
var observer = new MutationObserver(function(e) {
e = e[e.length-1];
if(e.attributeName == "loading") {
var doc = e.target.ownerDocument;
}
});
observer.observe(doc.getElementById("detail-view"), {attributes: true});
break;
case "popupshowing":
this.getAddon(this.win.document.popupNode.value,
this.setItemsAttributes,
event);
break;
}
},
addHomePageForScriptish: function(){
if(!window.Scriptish_config) return;
Scriptish_config.scripts.forEach(function(script){
if(!script.homepageURL && script.updateURL){
if(usoRegx.test(script.updateURL)){
script.homepageURL = script.updateURL.replace(/source/, "show").replace(/.\w+.js$/, "");
}
}
});
},
//Создаем меню
addPopupMenu: function(doc){
var mainicon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAB3RJTUUH1wcREBAg9OD7NAAAAAlwSFlzAAAewQAAHsEBw2lUUwAAAARnQU1BAACxjwv8YQUAAAH6SURBVHjaxVNBaxNBFP4mGRNp06bSaGu9qXhRLOSQX6Dg0d48SMWC4Mmbv8AfYA7Sgp6UgteCF29CKahBsKKWglgam4rRxGxiks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P8AAADwAAAA/wAAAP8AAAD/AAAA/wAAAP8AAADwAAAAAAAAAIQAAAD/AAAAjQAAAAAAAAB1AAAA/wAAAP8AAAD/AAAA8AAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA8AAAAIoAAAD/AAAAigAAAAAAAABpAAAAAAAAAAAAAAB7AAAA/wAAAIcAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAAigAAAAAAAAB7AAAA8AAAAAAAAACEAAAA/wAAAIcAAAAAAAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAAhwAAAAAAAACBAAAA/wAAAPAAAACKAAAA/wAAAIcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACEAAAA/wAAAP8AAAD/AAAA/wAAAIcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAIQAAAAAAAAAAAAAAAAAAAAAAB8AAAAfAAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAAxAAAAIgAAAAWAAAAJEAAAEDAAD+BwAA+A8AAA==";
var ins = doc.getElementById("menuitem_uninstallItem");
if(!ins) return;
ins = ins.nextSibling;
var popup = ins.parentNode;
var menuitem = $C("menuseparator", {
id: "AMD-separator-1"
});
popup.insertBefore(menuitem, ins);
menuitem = $C("menuitem", {
id: "AMD-browse-dir",
class: "menuitem-iconic",
image: mainicon,
label: "Место установки",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.browseDir);"
});
popup.insertBefore(menuitem, ins);
menuitem = $C("menuitem", {
id: "AMD-browse-Folder",
class: "menuitem-iconic",
image: mainicon1,
label: "Папка установки",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.Folder);"
});
popup.insertBefore(menuitem, ins);
menuitem = $C("menuitem", {
id: "AMD-browse-goHome",
label: "Домашняя страница",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.goHome);"
});
popup.insertBefore(menuitem, ins);
menuitem = $C("menuitem", {
id: "AMD-browse-goAMO",
label: "Страница на AMO",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.goAMO);"
});
popup.insertBefore(menuitem, ins);
menuitem = $C("menuitem", {
id: "AMD-browse-support",
label: "Страница поддержки",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.support);"
});
popup.insertBefore(menuitem, ins);
var menu = $C("menu", {
id: "AMD-menu",
class: "menu-iconic",
image: mainicon2,
label: "Копировать",
});
popup.insertBefore(menu, ins);
var menuPopup = $C("menupopup", {
id: "AMD-menupopup",
});
menu.appendChild(menuPopup);
menuitem = $C("menuitem", {
id: "AMD-copy-name",
label: "Копировать имя",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.copyName);"
});
menuPopup.appendChild(menuitem);
menuitem = $C("menuitem", {
id: "AMD-copy-version",
label: "Копировать версию",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.copyVersion);"
});
menuPopup.appendChild(menuitem);
menuitem = $C("menuitem", {
id: "AMD-copy-NameVersion",
label: "Копировать имя и версию",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.copyNameVersion);"
});
menuPopup.appendChild(menuitem);
menuitem = $C("menuitem", {
id: "AMD-copy-id",
label: "Копировать id",
oncommand: "AMD_Helper.getAddon(AMD_Helper.getPopupNode(this).value, AMD_Helper.copyID);"
});
menuPopup.appendChild(menuitem);
menuitem = $C("menuitem", {
id: "AMD-go-uso",
class: "greasemonkey",
hidden: true,
label: "Страница на Userscripts.org",
oncommand: "openURL(this.tooltipText);"
});
popup.appendChild(menuitem);
menuitem = $C("menuitem", {
id: "AMD-find-uso",
class: "greasemonkey",
hidden: true,
label: "Поиск по Userscripts.org",
oncommand: "openURL(this.getAttribute('find-on-uso'));"
});
popup.appendChild(menuitem);
addEventListener("popupshowing", this, true, popup);
},
//Указываем где и когда показывать элементы меню
setItemsAttributes: function(aAddon, event){
var popup = event.target;
var doc = popup.ownerDocument;
var isExtension = (aAddon.type == "extension");
var isTheme = (aAddon.type == "theme");
var isPlugin = (aAddon.type == "plugin");
var isUserStyle = (aAddon.type == "userstyle");
var isScriptish = (aAddon.type == "userscript");
var isUserScript = (aAddon.type == "user-script") || // Greasemonkey
(aAddon.type == "userscript") || // Scriptish
(aAddon.type == "greasemonkey-user-script"); // Greasemonkey 1.7+
var isCustomButton = (aAddon.type == "custombuttons");
var isService = (aAddon.type == "service");
var browseDirItem = doc.getElementById("AMD-browse-dir");
browseDirItem.hidden = isUserStyle || isUserScript || isCustomButton || isService;
var browseFolderItem = doc.getElementById("AMD-browse-Folder");
browseFolderItem.hidden = isUserStyle || isUserScript || isCustomButton || isPlugin || isService;
var copyNameItem = doc.getElementById("AMD-copy-name");
copyNameItem.tooltipText = aAddon.name;
copyNameItem.className = isUserScript
? isScriptish
? ""
: "greasemonkey"
: "";
var copyNameVersionItem = doc.getElementById("AMD-copy-NameVersion");
copyNameVersionItem.hidden = isUserStyle || isCustomButton || isService;
copyNameVersionItem.tooltipText = aAddon.name + " " + aAddon.version;
copyNameVersionItem.className = isUserScript
? isScriptish
? ""
: "greasemonkey"
: "";
var copyIDItem = doc.getElementById("AMD-copy-id");
copyIDItem.tooltipText = "ID: " + aAddon.id;
copyIDItem.className = isUserScript
? isScriptish
? ""
: "greasemonkey"
: "";
var copyVersionItem = doc.getElementById("AMD-copy-version");
copyVersionItem.tooltipText = aAddon.version;
copyVersionItem.hidden = isUserStyle || isCustomButton || isService;
copyVersionItem.className = isUserScript
? isScriptish
? ""
: "greasemonkey"
: "";
var opengoAMOItem = doc.getElementById("AMD-browse-goAMO");
opengoAMOItem.hidden = isUserStyle || isUserScript || isCustomButton || isPlugin || isService;
var amoURL = aAddon.reviewURL
? aAddon.reviewURL.replace(/\/reviews\//, "/")
: null;
opengoAMOItem.tooltipText = amoURL;
opengoAMOItem.hidden = !amoURL || /addons.mozilla.org/.test(aAddon.homepageURL);
var opengoHomeItem = doc.getElementById("AMD-browse-goHome");
opengoHomeItem.hidden = isUserScript || isCustomButton || isPlugin;
if (aAddon.homepageURL) {
opengoHomeItem.tooltipText = aAddon.homepageURL;
} else if (aAddon.reviewURL) {
opengoHomeItem.tooltipText = amoURL;
}
opengoHomeItem.hidden = !(aAddon.homepageURL || aAddon.reviewURL);
var opensupportItem = doc.getElementById("AMD-browse-support");
opensupportItem.hidden = isUserStyle || isUserScript || isCustomButton || isPlugin || isService;
opensupportItem.tooltipText = aAddon.supportURL;
opensupportItem.hidden = !aAddon.supportURL;
if(isUserScript && !isScriptish){
var usoURL = "";
if (aAddon._script) {
var usDownloadURL = aAddon._script._downloadURL;
var usUpdateURL = aAddon._script._updateURL;
if (usoRegx.test(usDownloadURL)) {
usoURL = usDownloadURL;
} else if (usoRegx.test(usUpdateURL)) {
usoURL = usUpdateURL;
}
}
var usoItem = doc.getElementById("AMD-go-uso");
usoItem.disabled = !usoRegx.test(usoURL);
usoItem.className = isUserScript ? usoItem.disabled ? "" : "greasemonkey" : "";
usoItem.tooltipText = usoURL.replace(/source/, "show")
.replace(/.\w+.js$/, "");
var fusoItem = doc.getElementById("AMD-find-uso");
fusoItem.disabled = usoRegx.test(usoURL);
fusoItem.className = isUserScript ? fusoItem.disabled ? "" : "greasemonkey" : "";
fusoItem.setAttribute("find-on-uso",
"http://userscripts.org/scripts/search?q=" +
encodeURIComponent(aAddon.name));
}
},
getPopupNode: function (aNode) {
var doc = aNode.ownerDocument;
return "triggerNode" in aNode.parentNode ? aNode.parentNode.triggerNode : doc.popupNode;
},
getAddon: function (aId, aCallback, aEvent) {
var self = this;
if (this.win.gDetailView._addon) {
aCallback.apply(this, [this.win.gDetailView._addon, aEvent]);
return;
}
AddonManager.getAllAddons(function(aAddons) {
for (var i = 0; i < aAddons.length; i++) {
if (aAddons[i].id == aId) {
aCallback.apply(self, [aAddons[i], aEvent]);
return;
}
}
});
},
//Домашняя страница
goHome: function (aAddon) {
var url = aAddon.homepageURL;
if (!url) {
if (aAddon.reviewURL) {
url = aAddon.reviewURL.replace(/\/reviews\/.*$/, "/");
} else {
url = "https://addons.mozilla.org/search/?q="
+ encodeURIComponent(aAddon.name);
}
}
openURL(url);
},
//Страница на АМО
goAMO: function (aAddon) {
var sourceTracker = "/?src=external-Add-ons_Manager_Context_Menu-extension";
if (aAddon.reviewURL) {
var amoURL = aAddon.reviewURL.replace(/\/reviews\//, "/")
.replace(/\/(firefox|seamonkey|thunderbird|android)/, "")
.replace(/\/\?src\=api/, sourceTracker);
}
if (/personas.mozilla.org$/.test(aAddon.id)) {
amoURL = "https://addons.mozilla.org/addon/" + aAddon.id.match(/\d+/) + sourceTracker;
}
openURL(amoURL);
},
//Страница поддержки
support: function (aAddon) {
openURL(aAddon.supportURL);
},
//Открыть место установки
browseDir: function (aAddon) {
switch(aAddon.type){
case "plugin":
var pathes = aAddon.pluginFullpath;
for (var i = 0; i < pathes.length; i++) {
this.revealPath(pathes[i]);
}
return;
}
var gecko = parseInt(Services.appinfo.platformVersion);
var nsLocalFile = Components.Constructor("@mozilla.org/file/local;1", (gecko >= 14) ? "nsIFile" : "nsILocalFile",
"initWithPath");
var dir = Services.dirsvc.get("ProfD", Ci.nsIFile);
dir.append("extensions");
dir.append(aAddon.id);
var fileOrDir = dir.path + (dir.exists() ? "" : ".xpi");
try {
(new nsLocalFile(fileOrDir)).reveal();
} catch (ex) {
var addonDir = /.xpi$/.test(fileOrDir) ? dir.parent : dir;
try {
if (addonDir.exists()) {
addonDir.launch();
}
} catch (ex) {
var uri = Services.io.newFileURI(addonDir);
var protSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
getService(Ci.nsIExternalProtocolService);
protSvc.loadUrl(uri);
}
}
},
//Открыть папку установки
Folder: function (aAddon) {
var gecko = parseInt(Services.appinfo.platformVersion);
var nsLocalFile = Components.Constructor("@mozilla.org/file/local;1", (gecko >= 14) ? "nsIFile" : "nsILocalFile",
"initWithPath");
var dir = Services.dirsvc.get("ProfD", Ci.nsIFile);
dir.append('extensions');
dir.append(aAddon.id);
if ( dir.exists() ) dir.launch();
var file = Components.classes['@mozilla.org/file/directory_service;1']
.getService(Components.interfaces.nsIProperties)
.get('ProfD', Components.interfaces.nsILocalFile);
file.append('extensions');
file.append( aAddon.id + '.xpi' )
if ( file.exists() ) file.launch();
return;
},
//Копировать имя
copyName: function (aAddon) {
this.copyToClipboard(aAddon.name);
},
//Копировать ID
copyID: function (aAddon) {
this.copyToClipboard("ID: " + aAddon.id);
},
//Копировать версию
copyVersion: function (aAddon) {
this.copyToClipboard(aAddon.version);
},
//Копировать имя и версию
copyNameVersion: function (aAddon) {
this.copyToClipboard(aAddon.name + " " + aAddon.version);
},
//Вспомогательные функции
revealPath: function(path){
var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
file.initWithPath(path);
if(file.exists())
file.reveal();
},
copyToClipboard: function (aString) {
Cc["@mozilla.org/widget/clipboardhelper;1"].
getService(Ci.nsIClipboardHelper).copyString(aString);
}
};
AMD_Helper.init();
function $C(name, attr) {
var el = document.createElement(name);
if (attr) Object.keys(attr).forEach(function(n) el.setAttribute(n, attr[n]));
return el;
}
})();