<?xml version="1.0" encoding="UTF-8"?> <bindings xmlns="http://www.mozilla.org/xbl"> <binding id="openwith"> <implementation> <field name="_eventListeners">[];</field> <constructor><![CDATA[ var attrimage = false; // true или false Добавить иконки (атрибут "image") или нет // ['ID пункта', 'имя приложения', 'путь к приложению', 'аргументы через пробел (то что в двойных кавычках считается за один аргумент)', 'иконка (для ОС Windows необязательно)'], var arrayWindows = [ // для ОС Windows ['mypal', 'MyPal', 'c:\\MyPal\\mypal.exe', '%OpenURI'], ['firefox', 'Firefox', 'c:\\Firefox\\firefox.exe', '%OpenURI'], // ['iexplore', 'IE', 'C:\\Program Files\\Internet Explorer\\iexplore.exe', '%OpenURI'], // ['edge', 'Microsoft Edge', 'C:\\Windows\\explorer.exe', '"microsoft-edge:%OpenURI "', 'moz-icon://file://C:\\Windows\\SystemApps\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\\MicrosoftEdge.exe?size=16'], ]; var arrayLinux = [ // для ОС Linux ['smplayer', 'SMPlayer', '/usr/bin/smplayer', '%OpenURI', 'file:///usr/share/icons/Papirus-Dark/16x16/categories/smplayer.svg'], ]; var arrayOS, platform = this.getPlatform(); if (platform == "win") arrayOS = arrayWindows; else if (platform == "linux") arrayOS = arrayLinux; else return; var {classes: Cc, interfaces: Ci} = Components; var popup = this.parentNode; var nextitem = this.nextSibling; var sepopen = popup.querySelector("#context-sep-open"); var knsxul = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; arrayOS.forEach((item) => { var id = item[0], name = item[1], path = item[2]; var arg = !item[3] ? "" : item[3]; var iconpath = attrimage ? (!item[4] ? ("moz-icon://file://" + path + "?size=16") : item[4]) : null; var menuitem_0 = document.createElementNS(knsxul, "menuitem"); menuitem_0.id = "open-current-page-with-" + id; menuitem_0.className = "menuitem-iconic"; menuitem_0.setAttribute("label", "Открыть страницу в " + name); if (attrimage) menuitem_0.setAttribute("image", iconpath); popup.insertBefore(menuitem_0, nextitem); this._addEventListener(menuitem_0, "command", function(event) { try { var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); file.initWithPath(path); if (!file.exists() || !file.isExecutable()) return; var _arg = []; if (arg !== "") { _arg = arg.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/g).map((sp) => { if (/%OpenURI/g.test(sp)) { var uri = gBrowser.selectedBrowser.currentURI; if (!(uri instanceof Ci.nsIURI)) uri = Services.io.newURI(uri, null, null); return sp.replace(/^"|"$/g, "").replace("%OpenURI", decodeURIComponent(uri.spec)); } return sp.replace(/^"|"$/g, ""); }); } var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess); process.init(file); process.runwAsync(_arg, _arg.length); } catch(e) {} }, false); var menuitem_1 = document.createElementNS(knsxul, "menuitem"); menuitem_1.id = "open-link-with-" + id; menuitem_1.className = "menuitem-iconic open-with-another-application"; menuitem_1.setAttribute("label", "Открыть ссылку в " + name); if (attrimage) menuitem_1.setAttribute("image", iconpath); popup.insertBefore(menuitem_1, sepopen ? sepopen : nextitem); this._addEventListener(menuitem_1, "command", function(event) { try { var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); file.initWithPath(path); if (!file.exists() || !file.isExecutable() || !("gContextMenu" in window) || !("linkURL" in gContextMenu)) return; var _arg = []; if (arg !== "") { _arg = arg.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/g).map((sp) => { if (/%OpenURI/g.test(sp)) { return sp.replace(/^"|"$/g, "").replace("%OpenURI", decodeURIComponent(gContextMenu.linkURL)); } return sp.replace(/^"|"$/g, ""); }); } var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess); process.init(file); process.runwAsync(_arg, _arg.length); } catch(e) {} }, false); }); ]]></constructor> <destructor><![CDATA[ this._eventListeners.forEach((args) => args[0].removeEventListener(args[1], args[2], args[3])); ]]></destructor> <method name="getPlatform"> <body><![CDATA[ if ("AppConstants" in window) return AppConstants.platform; var platform = null, os = Services.appinfo.OS.toLowerCase(); if (os.startsWith("win")) platform = "win"; else if (os == "linux") platform = "linux"; return platform; ]]></body> </method> <method name="_addEventListener"> <body><![CDATA[ arguments[0].addEventListener(arguments[1], arguments[2], arguments[3]); this._eventListeners.push(arguments); ]]></body> </method> </implementation> </binding> </bindings> |