Полезная информация

На IRC-канале #mozilla-ru можно получить техническую консультацию онлайн и, конечно же, порцию общения.

№7627-09-2019 19:33:30

Andrey_Krropotkin
Участник
 
Группа: Members
Зарегистрирован: 11-11-2011
Сообщений: 319
UA: unknown 0.0

Re: [CB]Toggle Restartless Add-ons

kokoss а в чем проблема? Он и так работает в 69 без отключения многопроцессорного режима.

Отсутствует

 

№7727-09-2019 20:01:12

kokoss
Участник
 
Группа: Members
Зарегистрирован: 15-02-2018
Сообщений: 525
UA: Firefox 52.0

Re: [CB]Toggle Restartless Add-ons

Andrey_Krropotkin
У меня в [firefox] 69 не работает(не активна), кнопку взял от сюда: https://forum.mozilla-russia.org/viewto … 78#p600078 ?

Отсутствует

 

№7827-09-2019 20:50:40

Andrey_Krropotkin
Участник
 
Группа: Members
Зарегистрирован: 11-11-2011
Сообщений: 319
UA: Firefox 69.0

Re: [CB]Toggle Restartless Add-ons

kokoss брал у Infocatcher здесь
У меня так:
секция /*Initialization Code*/

скрытый текст

Выделить код

Код:

// http://infocatcher.ucoz.net/js/cb/toggleRestartlessAddons.js
    // https://forum.mozilla-russia.org/viewtopic.php?id=57948
    // https://github.com/Infocatcher/Custom_Buttons/tree/master/Toggle_Restartless_Add-ons
    
    // Toggle Restartless Add-ons button for Custom Buttons
    // (code for "initialization" section)
    // Also the code can be used from main window context (as Mouse Gestures code, for example)
    
    // Also you can check for add-ons updates using right-click:
    // copy all code from
    // https://github.com/Infocatcher/Custom_Buttons/blob/master/Check_for_Addons_Updates/checkForAddonsUpdates.js
    // after "//== Check for Addons Updates begin"
    
    // See "var style = " to modify styles for specific add-ons
    
    // (c) Infocatcher 2013-2017
    // version 0.1.3pre3 - 2017-10-23
      
    var options = {
        addonTypes: ["extension"],
        // Possible values: "extension", "plugin"
        // From extensions: "userstyle" (Stylish), "greasemonkey-user-script" (Greasemonkey), "userscript" (Scriptish)
        // (swap to reorder in the menu)
        showVersions: 1,
        // 0 - don't show versions
        // 1 - show after name: "Addon Name 1.2"
        // 2 - show as "acceltext" (in place for hotkey text)
        showHidden: 0,
        // 0  - don't show hidden add-ons
        // -1 - show only enabled hidden add-ons (e.g. to track new items)
        // 1  - show all hidden add-ons
        sort: {
            enabled:     0,
            clickToPlay: 0,
            disabled:    0
            // Sort order:
            // 0, 0, 0 - sort add-ons of each type alphabetically
            // 0, 0, 1 - show enabled add-ons (of each type) first
            // 0, 1, 2 - enabled add-ons, then click-to-play and then disabled
        },
        closeMenu: false, // Close menu after left-click
        closeMenuClickToPlay: false // Close menu after left-click, for click to play plugins
        // Use Shift+click to invert closeMenu* behavior
    };
    
    var mp = document.createXULElement("menupopup");
    mp.setAttribute("onpopupshowing", "this.updateMenu();");
    mp.setAttribute("oncommand", "this.handleEvent(event);");
    mp.setAttribute("onmousedown", "if(event.button == 0) this.handleEvent(event);");
    mp.setAttribute("onclick", "if(event.button > 0) this.handleEvent(event);");
    mp.setAttribute("oncontextmenu", "return false;");
    mp.setAttribute("onpopuphidden", "this.destroyMenu();");
    
    var tb = this.parentNode;
    if(tb && tb.getAttribute("orient") == "vertical") {
        // https://addons.mozilla.org/firefox/addon/vertical-toolbar/
        var isRight = tb.parentNode.getAttribute("placement") == "right";
        mp.setAttribute("position", isRight ? "start_before" : "end_before");
    }
    
    var cleanupTimer = 0;
    mp.updateMenu = function() {
        clearTimeout(cleanupTimer);
        addStyle();
        getRestartlessAddons(options.addonTypes, function(addons) {
            var df = document.createDocumentFragment();
            var prevType;
            function sortPosition(addon) {
                if("STATE_ASK_TO_ACTIVATE" in AddonManager && addon.userDisabled == AddonManager.STATE_ASK_TO_ACTIVATE)
                    return options.sort.clickToPlay;
                if(addon.isActive)
                    return options.sort.enabled;
                return options.sort.disabled;
            }
            function key(addon) {
                return options.addonTypes.indexOf(addon.type)
                    + "\n" + sortPosition(addon)
                    + "\n" + addon.name.toLowerCase();
            }
            addons.sort(function(a, b) {
                var ka = key(a);
                var kb = key(b);
                return ka == kb ? 0 : ka < kb ? -1 : 1;
            }).forEach(function(addon) {
                var type = addon.type;
                if(prevType && type != prevType)
                    df.appendChild(document.createXULElement("menuseparator"));
                prevType = type;
                var icon = addon.iconURL || addon.icon64URL;
                var mi = document.createXULElement("menuitem");
                mi.className = "menuitem-iconic";
                var label = addon.name;
                if(options.showVersions == 1)
                    label += " " + addon.version;
                else if(options.showVersions == 2)
                    mi.setAttribute("acceltext", addon.version);
                mi.setAttribute("label", label);
                mi.setAttribute("image", icon || mp.icons[type] || "");
                if(!icon && mp.icons.useSVG)
                    mi.style.fill = "#15c";
                var tip = addon.description || "";
                var delay = "delayedStartupAddons" in Services
                    && Services.delayedStartupAddons[addon.id] || null;
                var isDelayed = delay !== null;
                mi.classList.toggle("toggleRestartlessAddons-isDelayed", isDelayed);
                if(isDelayed)
                    tip = "[Delayed Startup: " + delay.toLocaleString() + "]" + (tip ? "\n" + tip : "");
                tip && mi.setAttribute("tooltiptext", tip);
                mi.classList.toggle("toggleRestartlessAddons-isHidden", addon.hidden || false);
                setDisabled(mi, addon.userDisabled);
                mi._cbAddon = addon;
                df.appendChild(mi);
            });
            mp.textContent = "";
            mp.appendChild(df);
        });
    };
    mp.handleEvent = function(e) {
        var mi = e.target;
        if(!("_cbAddon" in mi))
            return;
        var addon = mi._cbAddon;
        if(e.type == "mousedown") {
            var closeMenu = isAskToActivateAddon(addon)
                ? options.closeMenuClickToPlay
                : options.closeMenu;
            if(e.shiftKey)
                closeMenu = !closeMenu;
            mi.setAttribute("closemenu", closeMenu ? "auto" : "none");
            return;
        }
        var hasMdf = hasModifier(e);
        if(e.type == "command" && (!hasMdf || e.shiftKey)) {
            let newDis = setNewDisabled(addon);
            setDisabled(mi, newDis);
        }
        else if(e.type == "command" && hasMdf || e.type == "click" && e.button == 1) {
            openAddonPage(addon);
            closeMenus(mi);
        }
        else if(e.type == "click" && e.button == 2) {
            if(openAddonOptions(addon))
                closeMenus(mi);
        }
    };
    mp.destroyMenu = function() {
        removeStyle();
        clearTimeout(cleanupTimer);
        cleanupTimer = setTimeout(function() {
            mp.textContent = "";
        }, 5000);
    };
    mp.icons = {
        get useSVG() {
            delete this.useSVG;
            return this.useSVG = Services.appinfo.name == "Firefox"
                && parseFloat(Services.appinfo.version) >= 57;
        },
        get plugin() {
            delete this.plugin;
            return this.plugin = this.useSVG
                ? "chrome://mozapps/skin/plugins/pluginGeneric.svg"
                : "chrome://mozapps/skin/plugins/pluginGeneric-16.png";
        },
        get extension() {
            delete this.extension;
            return this.extension = this.useSVG
                ? "chrome://mozapps/skin/extensions/extensionGeneric-16.svg"
                : "chrome://mozapps/skin/extensions/extensionGeneric-16.png";
        }
    };
    function isAskToActivateAddon(addon) {
        return addon.type == "plugin"
            && "STATE_ASK_TO_ACTIVATE" in AddonManager
            && Services.prefs.getBoolPref("plugins.click_to_play");
    }
    function setNewDisabled(addon) {
        var newDis = getNewDisabled(addon);
        var oldDis = addon.userDisabled;
        try {
            addon.userDisabled = newDis;
        }
        catch(e) { // Error: Cannot disable hidden add-on firefox@getpocket.com
            _log("Can't set addon.userDisabled to " + newDis + ", error:\n" + e);
            if(addon.hidden)
                setNewDisabledRaw(addon, newDis);
        }
        var realDis = addon.userDisabled;
        if(realDis != newDis && addon.type == "extension") { // Firefox 62+? Weird things happens
            setNewDisabledRaw(addon, newDis);
            realDis = addon.userDisabled;
        }
        if(realDis != newDis) { // We can't enable vulnerable plugins
            let err = "Can't set addon.userDisabled to " + newDis + ", real value: " + realDis;
            if(newDis) {
                _log(err + "\nSTATE_ASK_TO_ACTIVATE not supported?");
                newDis = false;
            }
            else {
                _log(err + "\nVulnerable plugin?");
                if(oldDis == AddonManager.STATE_ASK_TO_ACTIVATE)
                    newDis = true;
                else
                    newDis = AddonManager.STATE_ASK_TO_ACTIVATE;
            }
            addon.userDisabled = newDis;
        }
        return addon.userDisabled;
    }
    function getNewDisabled(addon) {
        // disabled -> STATE_ASK_TO_ACTIVATE -> enabled -> ...
        var curDis = addon.userDisabled;
        var newDis;
        if("STATE_ASK_TO_ACTIVATE" in AddonManager && curDis == AddonManager.STATE_ASK_TO_ACTIVATE)
            newDis = false;
        else if(!curDis)
            newDis = true;
        else {
            if(isAskToActivateAddon(addon))
                newDis = AddonManager.STATE_ASK_TO_ACTIVATE;
            else
                newDis = false;
        }
        return newDis;
    }
    function setNewDisabledRaw(addon, newDis) {
        _log("Let's try set addon.userDisabled using raw hack");
        let g = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", {});
        if("XPIDatabase" in g && "updateAddonDisabledState" in g.XPIDatabase) { // Firefox 61+
            let rawAddon = g.XPIDatabase.getAddons().find(function(rawAddon) {
                return rawAddon.id == addon.id;
            });
            g.XPIDatabase.updateAddonDisabledState(rawAddon, newDis);
        }
        else if("eval" in g) { // See "set userDisabled(val)"
            let addonFor = g.eval("addonFor");
            let rawAddon = addonFor(addon);
            //rawAddon.userDisabled = newDis;
            g.XPIProvider.updateAddonDisabledState(rawAddon, newDis);
        }
        else { // Firefox 57+? See https://forum.mozilla-russia.org/viewtopic.php?pid=745272#p745272
            updateAddonDisabledState(addon, newDis);
        }
    }
    function updateAddonDisabledState(addon, newDis) {
        var nsvo = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", {});
        var key = "_cbToggleRestartlessAddonsData";
        var url = URL.createObjectURL(new Blob([
            "XPIProvider.updateAddonDisabledState(addonFor(this." + key + "[0]), this." + key + "[1]); delete this." + key + ";"
        ]));
        addDestructor(function() {
            URL.revokeObjectURL(url);
        });
        (updateAddonDisabledState = function(addon, newDis) {
            nsvo[key] = [addon, newDis];
            Services.scriptloader.loadSubScript(url, nsvo);
        })(addon, newDis);
    }
    function setDisabled(mi, disabled) {
        var askToActivate = "STATE_ASK_TO_ACTIVATE" in AddonManager && disabled == AddonManager.STATE_ASK_TO_ACTIVATE;
        var cl = mi.classList;
        cl.toggle("toggleRestartlessAddons-askToActivate", askToActivate);
        cl.toggle("toggleRestartlessAddons-disabled", disabled && !askToActivate);
    }
    
    if(
        this instanceof XULElement // Custom Buttons
        && typeof event == "object"
        && !("type" in event) && typeof _phase == "string" && _phase == "init" // Initialization
    ) {
        this.type = "menu";
        this.orient = "horizontal";
        this.appendChild(mp);
    
        this.onmouseover = function(e) {
            if(e.target != this)
                return;
            Array.prototype.some.call(
                this.parentNode.getElementsByTagName("*"),
                function(node) {
                    if(
                        node != this
                        && node.namespaceURI == xulns
                        && node.boxObject
                        // See https://github.com/Infocatcher/Custom_Buttons/issues/28
                        //&& node.boxObject instanceof Components.interfaces.nsIMenuBoxObject
                        && "open" in node
                        && node.open
                        && node.getElementsByTagName("menupopup").length
                    ) {
                        node.open = false;
                        this.open = true;
                        return true;
                    }
                    return false;
                },
                this
            );
        };
        this.onmousedown = function(e) {
            if(e.target == this && e.button == 0 && hasModifier(e))
                e.preventDefault();
        };
        this.oncontextmenu = function(e) {
            if(e.target == this && !hasModifier(e) && hasUpdater())
                e.preventDefault();
        };
        this.onclick = function(e) {
            if(e.target != this)
                return;
            if(e.button == 0 && hasModifier(e) || e.button == 1)
                openAddonsManager();
            else if(e.button == 2 && !hasModifier(e) && hasUpdater())
                checkForAddonsUpdates.call(this);
        };
    }
    else { // Mouse gestures or something other...
        let e;
        if(typeof event == "object" && event instanceof Event && "screenX" in event) // FireGestures
            e = event;
        else if(
            this instanceof Components.interfaces.nsIDOMChromeWindow
            && "mgGestureState" in window && "endEvent" in mgGestureState // Mouse Gestures Redox
        )
            e = mgGestureState.endEvent;
        else {
            let anchor = this instanceof XULElement && this
                || window.gBrowser && gBrowser.selectedBrowser
                || document.documentElement;
            if("boxObject" in anchor) {
                let bo = anchor.boxObject;
                e = {
                    screenX: bo.screenX,
                    screenY: bo.screenY
                };
                if(this instanceof XULElement)
                    e.screenY += bo.height;
            }
        }
        if(!e || !("screenX" in e))
            throw new Error("[Toggle Restartless Add-ons]: Can't get event object");
        document.documentElement.appendChild(mp);
        mp.addEventListener("popuphidden", function destroy(e) {
            mp.removeEventListener(e.type, destroy, false);
            setTimeout(function() {
                mp.destroyMenu();
                mp.parentNode.removeChild(mp);
            }, 0);
        }, false);
        mp.openPopupAtScreen(e.screenX, e.screenY);
    }
    
    function getRestartlessAddons(addonTypes, callback, context) {
        if(!("AddonManager" in window))
            Components.utils.import("resource://gre/modules/AddonManager.jsm");
        if(!("Services" in window))
            Components.utils.import("resource://gre/modules/Services.jsm");
        var then, promise = AddonManager.getAddonsByTypes(addonTypes, then = function(addons) {
            var restartless = addons.filter(function(addon) {
                var ops = addon.operationsRequiringRestart;
                return !addon.appDisabled
                    && !(ops & AddonManager.OP_NEEDS_RESTART_ENABLE || ops & AddonManager.OP_NEEDS_RESTART_DISABLE)
                    && (
                        !addon.hidden
                        || options.showHidden > 0
                        || options.showHidden == -1 && !addon.userDisabled
                    );
            });
            callback.call(context, restartless);
        });
        promise && typeof promise.then == "function" && promise.then(then, Components.utils.reportError); // Firefox 61+
    }
    function openAddonOptions(addon) {
        // Based on code from chrome://mozapps/content/extensions/extensions.js
        // Firefox 21.0a1 (2013-01-27)
        var optionsURL = addon.optionsURL;
        if(!addon.isActive || !optionsURL)
            return false;
        if(addon.type == "plugin") // No options for now!
            return false;
        if(
            addon.optionsType == AddonManager.OPTIONS_TYPE_INLINE
            || addon.optionsType == (AddonManager.OPTIONS_TYPE_INLINE_INFO || NaN)
            || addon.optionsType == (AddonManager.OPTIONS_TYPE_INLINE_BROWSER || NaN)
        )
            openAddonPage(addon, true);
        else if(addon.optionsType == AddonManager.OPTIONS_TYPE_TAB && "switchToTabHavingURI" in window)
            switchToTabHavingURI(optionsURL, true);
        else {
            let windows = Services.wm.getEnumerator(null);
            while(windows.hasMoreElements()) {
                let win = windows.getNext();
                if(win.document.documentURI == optionsURL) {
                    win.focus();
                    return true;
                }
            }
            // Note: original code checks browser.preferences.instantApply and may open modal windows
            window.openDialog(optionsURL, "", "chrome,titlebar,toolbar,centerscreen,dialog=no");
        }
        return true;
    }
    function openAddonsManager(view) {
        var openAddonsMgr = window.BrowserOpenAddonsMgr // Firefox
            || window.openAddonsMgr // Thunderbird
            || window.toEM; // SeaMonkey
        openAddonsMgr(view);
    }
    function openAddonPage(addon, scrollToPreferences) {
        var platformVersion = parseFloat(
            Services.appinfo.name == "Pale Moon"
                ? Services.appinfo.version
                : Services.appinfo.platformVersion
        );
        scrollToPreferences = scrollToPreferences && platformVersion >= 12
            ? "/preferences"
            : "";
        openAddonsManager("addons://detail/" + encodeURIComponent(addon.id) + scrollToPreferences);
    }
    
    function hasModifier(e) {
        return e.ctrlKey || e.shiftKey || e.altKey || e.metaKey;
    }
    
    function addStyle() {
        if(addStyle.hasOwnProperty("_style"))
            return;
        var style = '\
            .toggleRestartlessAddons-isDelayed > .menu-iconic-text {\n\
                opacity: 0.75;\n\
                color: #070;\n\
            }\n\
            .toggleRestartlessAddons-isHidden > .menu-iconic-text {\n\
                color: #609;\n\
            }\n\
            .toggleRestartlessAddons-disabled > .menu-iconic-left {\n\
                opacity: 0.4;\n\
            }\n\
            .toggleRestartlessAddons-disabled > .menu-iconic-text,\n\
            .toggleRestartlessAddons-disabled > .menu-accel-container {\n\
                opacity: 0.5;\n\
            }\n\
            .toggleRestartlessAddons-askToActivate {\n\
                color: -moz-nativehyperlinktext;\n\
            }';
        addStyle._style = document.insertBefore(
            document.createProcessingInstruction(
                "xml-stylesheet",
                'href="' + "data:text/css,"
                    + encodeURIComponent(style) + '" type="text/css"'
            ),
            document.documentElement
        );
    }
    function removeStyle() {
        if(!addStyle.hasOwnProperty("_style"))
            return;
        var s = addStyle._style;
        s.parentNode.removeChild(s);
        delete addStyle._style;
    }
    function closeMenus(node) {
        // Based on function closeMenus from chrome://browser/content/utilityOverlay.js
        for(; node && "tagName" in node; node = node.parentNode) {
            if(
                node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
                && (node.localName == "menupopup" || node.localName == "popup")
            )
                node.hidePopup();
        }
    }
    function _log(s) {
        if(typeof LOG == "function") // Custom Buttons
            LOG(s);
        else // Or something else
            Services.console.logStringMessage("Toggle Restartless Add-ons: " + s);
    }
    
    function hasUpdater() {
        var has = checkForAddonsUpdates.toString().indexOf("about:addons") != -1;
        hasUpdater = function() {
            return has;
        };
        return has;
    }
    
    
    
    
    
    
    
    
    
    function checkForAddonsUpdates() {
// http://infocatcher.ucoz.net/js/cb/checkForAddonsUpdates.js
// https://forum.mozilla-russia.org/viewtopic.php?id=57958
// https://github.com/Infocatcher/Custom_Buttons/tree/master/Check_for_Addons_Updates

// Check for Addons Updates button for Custom Buttons
// (code for "code" section)

// (c) Infocatcher 2012-2014
// version 0.1.5 - 2014-10-13

// Button just open hidden tab with about:addons and trigger built-in "Check for Updates" function.
// And show tab, if found updates.

(function() {
var btn = this instanceof XULElement
    ? this
    : { // Launched not from custom button
        image: "", // Base64-encoded icon (if empty, will be used "imgLoading")
        label: "Check for Addons Updates",
        tooltipText: ""
    };
if("_cb_disabled" in btn)
    return;
btn._cb_disabled = true;

if(!("Services" in window))
    Components.utils.import("resource://gre/modules/Services.jsm");
var app = Services.appinfo.name;

var ADDONS_URL = "about:addons";

var progressIcon = new ProgressIcon(btn);
var image = btn.image || progressIcon.imgLoading;
var tip = btn.tooltipText;
btn.tooltipText = "Open " + ADDONS_URL + "…";

var tab, browser, gBrowser;
var tbTabInfo, tbTab;

var trgWindow = Services.wm.getMostRecentWindow("navigator:browser")
    || app == "Thunderbird" && Services.wm.getMostRecentWindow("mail:3pane")
    || window;
var trgDocument = trgWindow.document;
var tabmail = trgDocument.getElementById("tabmail");

if(tabmail && app == "Thunderbird") { // Note: SeaMonkey doesn't support content tabs in mail window
    let addonsWin;
    let receivePong = function(subject, topic, data) {
        addonsWin = subject;
    };
    Services.obs.addObserver(receivePong, "EM-pong", false);
    Services.obs.notifyObservers(null, "EM-ping", "");
    Services.obs.removeObserver(receivePong, "EM-pong");
    if(addonsWin) {
        let rootWindow = addonsWin
            .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
            .getInterface(Components.interfaces.nsIWebNavigation)
            .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
            .rootTreeItem
            .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
            .getInterface(Components.interfaces.nsIDOMWindow);
        tabmail = rootWindow.document.getElementById("tabmail");
        tbTabInfo = tabmail.getBrowserForDocument(addonsWin);
        tbTab = tab = tbTabInfo.tabNode;
        processAddonsTab(addonsWin);
    }
    else {
        Services.obs.addObserver(function observer(subject, topic, data) {
            Services.obs.removeObserver(observer, topic);
            if(subject.document.readyState == "complete")
                processAddonsTab(subject);
            else {
                subject.addEventListener("load", function onLoad(e) {
                    subject.removeEventListener(e.type, onLoad, false);
                    processAddonsTab(subject);
                }, false);
            }
        }, "EM-loaded", false);
        // See openAddonsMgr() -> openContentTab()
        tbTabInfo = tabmail.openTab("contentTab", {
            contentPage: ADDONS_URL,
            clickHandler: "specialTabs.siteClickHandler(event, /addons\.mozilla\.org/);",
            background: true
        });
        tbTab = tab = tbTabInfo.tabNode;
        tbTab.collapsed = true;
        // Note: dontSelectHiddenTab() not implemented
    }
}
else if("gBrowser" in trgWindow && trgWindow.gBrowser.tabs) {
    let isPending = false;
    let ws = Services.wm.getEnumerator("navigator:browser");
    windowsLoop:
    while(ws.hasMoreElements()) {
        let w = ws.getNext();
        let tabs = w.gBrowser.tabs;
        for(let i = 0, l = tabs.length; i < l; ++i) {
            let t = tabs[i];
            if(
                !t.closing
                && t.linkedBrowser
                && t.linkedBrowser.currentURI.spec == ADDONS_URL
            ) {
                tab = t;
                break windowsLoop;
            }
        }
    }

    gBrowser = trgWindow.gBrowser;
    if(!tab) {
        tab = gBrowser.addTab(ADDONS_URL, {
            triggeringPrincipal: "Services" in window // Firefox 63+
                && Services.scriptSecurityManager
                && Services.scriptSecurityManager.getSystemPrincipal()
        });
        tab.collapsed = true;
        tab.closing = true; // See "visibleTabs" getter in chrome://browser/content/tabbrowser.xml
        trgWindow.addEventListener("TabSelect", dontSelectHiddenTab, false);
    }
    else if(
        tab.getAttribute("pending") == "true" // Gecko >= 9.0
        || tab.linkedBrowser.contentDocument.readyState == "uninitialized"
        // || tab.linkedBrowser.__SS_restoreState == 1
    )
        isPending = true;

    browser = tab.linkedBrowser;
    if(isPending || browser.webProgress.isLoadingDocument) {
        browser.addEventListener("load", processAddonsTab, true);
        if(isPending) {
            if(parseFloat(Services.appinfo.platformVersion) >= 41) {
                // Workaround to correctly restore pending tab
                // See https://github.com/Infocatcher/Custom_Buttons/issues/39
                let selTab = gBrowser.selectedTab;
                gBrowser.selectedTab = tab;
                gBrowser.selectedTab = selTab;
            }
            else {
                browser.reload();
            }
        }
    }
    else {
        processAddonsTab();
    }
}
else {
    progressIcon.restore();
    btn.tooltipText = tip;
    delete btn._cb_disabled;
    Services.prompt.alert(window, btn.label, "Error: Can't find supported window!");
    return;
}

function processAddonsTab(e) {
    var doc;
    if(e && e instanceof Components.interfaces.nsIDOMWindow) {
        doc = e.document;
    }
    else if(e) {
        doc = e.target;
        if(doc.location != ADDONS_URL)
            return;
        browser.removeEventListener(e.type, processAddonsTab, true);
    }
    else {
        doc = browser.contentDocument;
    }

    progressIcon.loading();
    var inProgress = $("updates-progress");
    btn.tooltipText = inProgress.getAttribute("value");

    var origIcon = tab.image;
    tab.image = image;

    var updEnabledPref = "extensions.update.enabled";
    var updEnabled = Services.prefs.getBoolPref(updEnabledPref);
    if(!updEnabled)
        Services.prefs.setBoolPref(updEnabledPref, true);

    var notFound = $("updates-noneFound");
    var updated = $("updates-installed");
    // Avoid getting false results from the past update check (may not be required for "noneFound")
    notFound.hidden = updated.hidden = true;

    $("cmd_findAllUpdates").doCommand();

    var waitTimer = setInterval(function() {
        if(!doc.defaultView || doc.defaultView.closed) {
            stopWait();
            notify("Tab with add-ons manager was closed!");
            return;
        }
        if(!inProgress.hidden)
             return;
        var autoUpdate = $("utils-autoUpdateDefault");
        var autoUpdateChecked = autoUpdate.getAttribute("checked") == "true";

        var found = $("updates-manualUpdatesFound-btn");
        if(
            autoUpdateChecked
                ? notFound.hidden && updated.hidden
                : notFound.hidden && found.hidden
        ) // Too early?
            return;

        stopWait();
        if(!tbTab)
            tab.closing = false;
        function removeTab() {
            if(!tab.collapsed)
                return;
            if(tbTab)
                tabmail.closeTab(tbTabInfo, true /*aNoUndo*/);
            else {
                gBrowser.removeTab(tab);
                (function forgetClosedTab(isSecondTry) {
                    var ss = "nsISessionStore" in Components.interfaces
                        ? (
                            Components.classes["@mozilla.org/browser/sessionstore;1"]
                            || Components.classes["@mozilla.org/suite/sessionstore;1"]
                        ).getService(Components.interfaces.nsISessionStore)
                        : SessionStore; // Firefox 61+ https://bugzilla.mozilla.org/show_bug.cgi?id=1450559
                    if(!("forgetClosedTab" in ss))
                        return;
                    var closedTabs = JSON.parse(ss.getClosedTabData(window));
                    for(let i = 0, l = closedTabs.length; i < l; ++i) {
                        let closedTab = closedTabs[i];
                        let state = closedTab.state;
                        if(state.entries[state.index - 1].url == ADDONS_URL) {
                            ss.forgetClosedTab(window, i);
                            return;
                        }
                    }
                    if(!isSecondTry) // May be needed in SeaMonkey
                        setTimeout(forgetClosedTab, 0, true);
                })();
            }
        }

        if(!updEnabled)
            Services.prefs.setBoolPref(updEnabledPref, false);

        if(!notFound.hidden) {
            removeTab();
            notify(notFound.getAttribute("value"));
            return;
        }
        if(autoUpdateChecked) {
            removeTab();
            notify(updated.getAttribute("value"));
            return;
        }

        tab.collapsed = false;
        $("categories").selectedItem = $("category-availableUpdates");
        var tabWin = tab.ownerDocument.defaultView;
        if(tbTab)
            tabmail.switchToTab(tbTabInfo);
        else
            tabWin.gBrowser.selectedTab = tab;
        setTimeout(function() {
            tabWin.focus();
            doc.defaultView.focus();
            $("addon-list").focus();
        }, 0);
    }, 50);
    function $(id) {
        return doc.getElementById(id);
    }
    function stopWait() {
        clearInterval(waitTimer);
        progressIcon.restore();
        btn.tooltipText = tip;
        if(tab.image == image)
            tab.image = origIcon;
        trgWindow.removeEventListener("TabSelect", dontSelectHiddenTab, false);
        setTimeout(function() {
            delete btn._cb_disabled;
        }, 500);
    }
    function notify(msg) {
        Components.classes["@mozilla.org/alerts-service;1"]
            .getService(Components.interfaces.nsIAlertsService)
            .showAlertNotification(
                Services.appinfo.name == "Firefox" && parseFloat(Services.appinfo.version) >= 57
                    ? "chrome://mozapps/skin/extensions/extensionGeneric.svg"
                    : "chrome://mozapps/skin/extensions/extensionGeneric.png",
                btn.label,
                msg, false, "", null
            );
    }
}
function dontSelectHiddenTab(e) {
    // <tab /><tab collapsed="true" />
    // Close first tab: collapsed tab becomes selected
    var trgTab = e.originalTarget || e.target;
    if(trgTab != tab)
        return;

    if(/\n(?:BrowserOpenAddonsMgr|toEM)@chrome:\/\//.test(new Error().stack)) {
        // User open Add-ons Manager, show tab
        trgWindow.removeEventListener("TabSelect", dontSelectHiddenTab, false);
        setTimeout(function() { // Hidden tab can't be selected, so select it manually...
            tab.collapsed = tab.closing = false;
            gBrowser.selectedTab = tab;
        }, 0);
    }

    function done(t) {
        if(!t.hidden && !t.closing) {
            e.preventDefault();
            e.stopPropagation();
            return gBrowser.selectedTab = t;
        }
        return false;
    }
    for(var t = tab.nextSibling; t; t = t.nextSibling)
        if(done(t))
            return;
    for(var t = tab.previousSibling; t; t = t.previousSibling)
        if(done(t))
            return;
}
function ProgressIcon(btn) {
    if(!(btn instanceof XULElement)) {
        this.loading = this.restore = function() {};
        return;
    }
    var app = Services.appinfo.name;
    var pv = parseFloat(Services.appinfo.platformVersion);
    if(app == "SeaMonkey")
        this.imgConnecting = this.imgLoading = "chrome://communicator/skin/icons/loading.gif";
    else if(app == "Thunderbird") {
        this.imgConnecting = "chrome://messenger/skin/icons/connecting.png";
        this.imgLoading = "chrome://messenger/skin/icons/loading.png";
    }
    else {
        this.imgConnecting = "chrome://browser/skin/tabbrowser/connecting.png";
        this.imgLoading = app == "Firefox" && pv >= 48
            ? "chrome://global/skin/icons/loading.png"
            : "chrome://browser/skin/tabbrowser/loading.png";
    }
    var useAnimation = app == "Firefox" && pv >= 32;
    var btnIcon = btn.ownerDocument.getAnonymousElementByAttribute(btn, "class", "toolbarbutton-icon")
                    || btn.getElementsByClassName("toolbarbutton-icon")[0];
    var origIcon = btnIcon.src;
    btnIcon.src = this.imgConnecting;
    if(useAnimation) {
        let cs = btnIcon.ownerDocument.defaultView.getComputedStyle(btnIcon, null);
        let s = btnIcon.style;
        s.margin = [cs.marginTop, cs.marginRight, cs.marginBottom, cs.marginLeft].join(" ");
        s.padding = [cs.paddingTop, cs.paddingRight, cs.paddingBottom, cs.paddingLeft].join(" ");
        s.width = cs.width;
        s.height = cs.height;
        s.boxShadow = "none";
        s.borderColor = s.background = "transparent";
        btnIcon.setAttribute("fadein", "true");
        btnIcon.setAttribute("busy", "true");
        btnIcon.classList.add("tab-throbber");
        btnIcon._restore = function() {
            delete btnIcon._restore;
            btnIcon.removeAttribute("busy");
            btnIcon.removeAttribute("progress");
            setTimeout(function() {
                btnIcon.classList.remove("tab-throbber");
                btnIcon.removeAttribute("style");
                btnIcon.removeAttribute("fadein");
            }, 0);
        };
    }
    this.loading = function() {
        btnIcon.src = this.imgLoading;
        if(useAnimation)
            btnIcon.setAttribute("progress", "true");
    };
    this.restore = function() {
        btnIcon.src = origIcon;
        if(useAnimation)
            btnIcon._restore();
    };
}
}).call(this);
//== Check for Addons Updates end
}


this.tooltipText = "Переключатель джетпаков" 
                   + "\n\nУправление:\nЛКМ – открыть меню" 
                   + "\nПКМ – проверить обновления"
                   + "\nСКМ – открыть страницу дополнений"
                   + "\nShift+ПКМ – меню кнопки"
                   + "\n\nВ меню: \nЛКМ – включить/выключить дополнение"
                   + "\nShift+ЛКМ – включить/выключить дополнение без закрытия меню"   
                   + "\nСКМ – открыть страницу дополнения в управлении дополнениями"                    
                   + "\nПКМ – открыть настройки дополнения (если есть)";                    


секция /*CODE*/
скрытый текст

Выделить код

Код:

if(!event.target) // Button's hotkey pressed
    this.open = true;

Отсутствует

 

№7927-09-2019 21:26:52

kokoss
Участник
 
Группа: Members
Зарегистрирован: 15-02-2018
Сообщений: 525
UA: Firefox 52.0

Re: [CB]Toggle Restartless Add-ons

Andrey_Krropotkin
Этот код работает! Благодарю! А можно сделать что бы отключенные дополнения отражались в конце списка?

Отсутствует

 

№8027-09-2019 21:36:49

Andrey_Krropotkin
Участник
 
Группа: Members
Зарегистрирован: 11-11-2011
Сообщений: 319
UA: unknown 0.0

Re: [CB]Toggle Restartless Add-ons

kokoss это не ко мне, это не мой код, я в него не вникал.

Отсутствует

 

№8127-09-2019 21:53:20

Infocatcher
Not found
 
Группа: Extensions
Зарегистрирован: 24-05-2007
Сообщений: 4291
UA: Firefox 56.0

Re: [CB]Toggle Restartless Add-ons

kokoss пишет:

А можно сделать что бы отключенные дополнения отражались в конце списка?

В начале кода есть настройки, sort: { … disabled: 1 } переместит отключенные в конец списка:

Выделить код

Код:

var options = {
    …
    sort: {
        enabled:     0,
        clickToPlay: 0,
        disabled:    0
        // Sort order:
        // 0, 0, 0 - sort add-ons of each type alphabetically
        // 0, 0, 1 - show enabled add-ons (of each type) first
        // 0, 1, 2 - enabled add-ons, then click-to-play and then disabled
    },

Прошлое – это локомотив, который тянет за собой будущее. Бывает, что это прошлое вдобавок чужое. Ты едешь спиной вперед и видишь только то, что уже исчезло. А чтобы сойти с поезда, нужен билет. Ты держишь его в руках. Но кому ты его предъявишь?
Виктор Пелевин. Желтая стрела

Отсутствует

 

№8227-09-2019 22:36:11

kokoss
Участник
 
Группа: Members
Зарегистрирован: 15-02-2018
Сообщений: 525
UA: Firefox 52.0

Re: [CB]Toggle Restartless Add-ons

Infocatcher
Andrey_Krropotkin
Большое спасибо за помощь :beer:

Отредактировано kokoss (27-09-2019 23:30:40)

Отсутствует

 

Board footer

Powered by PunBB
Modified by Mozilla Russia
Copyright © 2004–2011 Mozilla Russia
Язык отображения форума: [Русский] [English]