fire/fox
火狐狸
火狐狸
  • UID32624
  • 注册日期2010-04-21
  • 最后登录2024-09-05
  • 发帖数180
  • 经验177枚
  • 威望0点
  • 贡献值190点
  • 好评度10点
  • 社区居民
  • 忠实会员
阅读:1356回复:1

【已解决】更新117之后,解锁主菜单按钮的 movable-PanelUI-button.uc.js 失效

楼主#
更多 发布于:2023-09-08 20:40

https://github.com/xiaoxiaoflood/firefox-scripts/issues/265

已经按上面帖子更新了 scripts 文件,其他的 js 都没有问题,单单这个 movable-PanelUI-button.uc.js 失效。


// ==UserScript==
// @name            more
// @author          firefox
// @include         main
// @shutdown        more
// @onlyonce
// ==/UserScript==
    
Components.utils.import("resource:///modules/CustomizableUI.jsm");
var {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);
    
(function(){
let widgetId = "movable-PanelUI-button";
    
let listener = {
    onWidgetCreated: function(aWidgetId, aArea) {
        if (aWidgetId != widgetId)
            return;
            
        if(listener.css !== undefined)
            sss.unregisterSheet(listener.css, sss.AGENT_SHEET);
            
        listener.css = Services.io.newURI("data:text/css;charset=utf-8," + encodeURIComponent('\
#' + aWidgetId + '{\
list-style-image: url("chrome://browser/skin/menu.svg");\
}\
#PanelUI-button {\
display: none !important;\
}\
'), null, null);
            
        sss.loadAndRegisterSheet(listener.css, sss.AGENT_SHEET);
    }
}
    
CustomizableUI.addListener(listener);
CustomizableUI.createWidget({
    id: widgetId,
    type: "button",
    defaultArea: CustomizableUI.AREA_NAVBAR,
    label: "Main menu",
    tooltiptext: "打开应用程序菜单",
    onCreated: function(node) {
        let originalMenu = node.ownerDocument.defaultView.PanelUI;
            
        // helper function to not repeat so much code
        function setEvent(event) {
            node.addEventListener(event, function(){
                originalMenu.menuButton = node;
            }, {"capture": true});
            node.addEventListener(event, originalMenu);
        }
            
        setEvent("mousedown");
        setEvent("keypress");
    }
});
})();
fire/fox
火狐狸
火狐狸
  • UID32624
  • 注册日期2010-04-21
  • 最后登录2024-09-05
  • 发帖数180
  • 经验177枚
  • 威望0点
  • 贡献值190点
  • 好评度10点
  • 社区居民
  • 忠实会员
1楼#
发布于:2023-09-08 21:18



找了一个新的 uc.js,117 可用:
https://github.com/benzBrake/FirefoxCustomize/blob/master/userChromeJS/movablePanelUIButton.uc.js


// ==UserScript==
// @name
// @description     可移动 PanelUI 按钮
// @author          Ryan, firefox
// @include         main
// @shutdown        window.movablePanelUIButton.destroy()
// @compatibility   Firefox 78
// @homepage        https://github.com/benzBrake/FirefoxCustomize
// @note            2022.09.07 修正新窗口不能定制
// @note            2022.09.05 修正窗口报错
// @note            2022.08.27 fx 102+
// @note            2022.07.02 非 xiaoxiaoflood 的 userChromeJS 环境测试可用
// @note            2022.04.20 修改为可热插拔(不知道非 xiaoxiaoflood 的 userChromeJS 环境是否可用)
// @onlyonce
// ==/UserScript==
(function () {
    const CustomizableUI = globalThis.CustomizableUI || Cu.import("resource:///modules/CustomizableUI.jsm").CustomizableUI;
  
    if (window.movablePanelUIButton) {
        window.movablePanelUIButton.destroy();
    }
  
    window.movablePanelUIButton = {
        get sss() {
            delete this.sss;
            return this.sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
        },
        STYLE_ICON: {
            url: Services.io.newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(`
            #movable-PanelUI-button {
                list-style-image: url(chrome://browser/skin/menu.svg);
            }
            `)),
            type: 0
        },
        STYLE_DISPLAY: {
            url: Services.io.newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(`
            #PanelUI-button {
                display: none;
            }
            `)),
            type: 0
        },
        listener: {
            windows: windows,
            onCustomizeStart(win) {
                this.windows(function (doc, win, location) {
                    win.dispatchEvent(new CustomEvent("OriginalPanelUIButtonShow"));
                })
            },
            onCustomizeEnd(win) {
                this.windows(function (doc, win, location) {
                    win.dispatchEvent(new CustomEvent("OriginalPanelUIButtonHide"));
                })
            }
        },
        init: function () {
            this.sss.loadAndRegisterSheet(this.STYLE_ICON.url, this.STYLE_ICON.type);
            this.sss.loadAndRegisterSheet(this.STYLE_DISPLAY.url, this.STYLE_DISPLAY.type);
            CustomizableUI.addListener(this.listener);
            CustomizableUI.createWidget({
                id: "movable-PanelUI-button",
                type: "button",
                defaultArea: CustomizableUI.AREA_NAVBAR,
                localized: false,
                removable: true,
                onCreated: node => {
                    node.addEventListener('mousedown', this);
                    node.addEventListener('keypress', this);
                    let pNode = node.ownerDocument.getElementById('PanelUI-menu-button');
                    ['label', 'tooltiptext'].forEach(attr => node.setAttribute(attr, pNode.getAttribute(attr)));
                }
            });
            window.addEventListener('OriginalPanelUIButtonShow', this);
            window.addEventListener('OriginalPanelUIButtonHide', this);
        },
        handleEvent: function (event) {
            if (event.type === "mousedown" && event.button !== 0) return;
            switch (event.type) {
                case 'mousedown':
                case 'keypress':
                    let { target: node } = event;
                    let { ownerDocument: document } = node;
                    const { PanelUI } = document.defaultView;
                    PanelUI.menuButton = node;
                    PanelUI.show();
                    break;
                case 'OriginalPanelUIButtonShow':
                    this.sss.unregisterSheet(this.STYLE_DISPLAY.url, this.STYLE_DISPLAY.type);
                    break;
                case 'OriginalPanelUIButtonHide':
                    this.sss.loadAndRegisterSheet(this.STYLE_DISPLAY.url, this.STYLE_DISPLAY.type);
                    break;
            }
  
        },
        destroy: function () {
            this.sss.unregisterSheet(this.STYLE_ICON.url, this.STYLE_ICON.type);
            this.sss.unregisterSheet(this.STYLE_DISPLAY.url, this.STYLE_DISPLAY.type);
            CustomizableUI.destroyWidget("movable-PanelUI-button");
            windows(function (doc, win, location) {
                doc.defaultView.PanelUI.menuButton = doc.getElementById('PanelUI-button');
            })
            window.removeEventListener('OriginalPanelUIButtonShow', this);
            window.removeEventListener('OriginalPanelUIButtonHide', this);
            delete this;
        }
    }
  
    function windows(fun) {
        let windows = Services.wm.getEnumerator('navigator:browser');
        while (windows.hasMoreElements()) {
            let win = windows.getNext();
            if (!win._uc)
                continue;
            let { document, location } = win;
            if (fun(document, win, location))
                break;
        }
    }
  
    window.movablePanelUIButton.init();
})();
游客

返回顶部