iFox
小狐狸
小狐狸
  • UID49155
  • 注册日期2015-03-05
  • 最后登录2019-10-13
  • 发帖数81
  • 经验84枚
  • 威望0点
  • 贡献值44点
  • 好评度3点
  • 社区居民
  • 忠实会员
45楼#
发布于:2019-05-24 00:54
Firefox对自己好狠,废了扩展现在连脚本也不放过了啊,这是要单方面强行和我say goodbye啊啊
etjim
火狐狸
火狐狸
  • UID30046
  • 注册日期2009-08-12
  • 最后登录2019-10-15
  • 发帖数142
  • 经验205枚
  • 威望0点
  • 贡献值46点
  • 好评度8点
  • 忠实会员
  • 社区居民
46楼#
发布于:2019-07-02 12:33
你好楼主大大,又要再麻烦你一次,
今日更新到FF69b1,已经按照大大的提示,将所有在使用的uc脚本都修改了一遍;但以下这个脚本修改了以后,仍有部分功能失效,请问要如何修改呢,请指教一下。
// ==UserScript==
// @name           downloadPlus.uc.js
// @description    从硬盘中删除+下载重命名并可转码+双击复制链接+另存为+保存并打开+完成下载提示音+自动关闭下载产生的空白标签
// @author         w13998686967再次修改整合 (ywzhaiqi、黒仪大螃蟹、Alice0775、紫云飞)
// @include        chrome://browser/content/browser.xhtml
// @include        chrome://browser/content/places/places.xul
// @include        chrome://mozapps/content/downloads/unknownContentType.xul
// @include        chrome://mozapps/content/downloads/downloads.xul
// @version        2014.11.02 增加多个功能
// @version        2014.06.06 add delay to fix for new userChrome.js
// ==/UserScript==
  
(function() {
  
    var encoding = true //true,(新建下载)弹窗             false,不弹窗
    var rename = true //true,(下载改名)可改名           false,不可改
    var locking = true //true,(下载改名)自动锁定保存文件 false,不锁定
    var encodingConvert = true //true,(下载改名)开启下拉菜单选项 false,关闭下拉菜单选项
    var Convert = true //true,(保存并打开)兼容火狐版本26+(也许会有BUG)     false,火狐版本29+
  
    if (!window.Services) Components.utils.import("resource://gre/modules/Services.jsm");
    if (!window.DownloadUtils) Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
  
    switch (location.href) {
        case "chrome://browser/content/browser.xhtml":
            setTimeout(function() {
                new_Download(); // 新建下载
                downloadsPanel_removeFile(); // 从硬盘中删除
                //downloadSound_Play(); // 下载完成提示音
                downloadFileSize(); // 精确显示文件大小
                autoClose_blankTab(); // 自动关闭下载产生的空白标签
                saveAndOpen_on_main(); // 跟下面的 save_AndOpen 配合使用
                download_dialog_changeName_on_main(); // 跟下面的 download_dialog_changeName 配合使用
                download_speed(); //下载面板显示下载速度
            }, 200);
            break;
        case "chrome://mozapps/content/downloads/unknownContentType.xul":
            setTimeout(function() {
                save_And_Open(); // 保存并打开
                download_dialog_changeName(); // 下载改名
                download_dialog_saveas(); // 另存为...
                download_dialog_saveTo(); // 保存到...
                download_dialog_showCompleteURL(); // 下载弹出窗口双击链接复制完整链接
                download_dialog_doubleclicksaveL(); // 下载弹出窗口双击保存文件项执行下载
                window.sizeToContent(); // 下载弹出窗口大小自适应(确保在添加的按钮之后加载)
            }, 200);
            break;
        case "chrome://browser/content/places/places.xul":
            setTimeout(function() {
                new_Download(); // 新建下载(我的足迹)
                downloadsPanel_removeFile(); // 从硬盘中删除(我的足迹)
            }, 200);
            break;
    }
  
  
    // 下载完成提示音
    function downloadSound_Play() {
        var downloadPlaySound = {
  
            DL_START: null,
            DL_DONE: "file:///C:/WINDOWS/Media/chimes.wav",
            DL_CANCEL: null,
            DL_FAILED: null,
  
            _list: null,
            init: function sampleDownload_init() {
                XPCOMUtils.defineLazyModuleGetter(window, "Downloads",
                    "resource://gre/modules/Downloads.jsm");
  
  
                window.addEventListener("unload", this, false);
  
                //**** 监视下载
                if (!this._list) {
                    Downloads.getList(Downloads.ALL).then(list => {
                        this._list = list;
                        return this._list.addView(this);
                    }).then(null, Cu.reportError);
                }
            },
  
            uninit: function() {
                window.removeEventListener("unload", this, false);
                if (this._list) {
                    this._list.removeView(this);
                }
            },
  
            onDownloadAdded: function(aDownload) {
                //**** 开始下载
                if (this.DL_START);
                this.playSoundFile(this.DL_START);
            },
  
            onDownloadChanged: function(aDownload) {
                //**** 取消下载
                if (aDownload.canceled && this.DL_CANCEL)
                    this.playSoundFile(this.DL_CANCEL)
                    //**** 下载失败
                if (aDownload.error && this.DL_FAILED)
                    this.playSoundFile(this.DL_FAILED)
                    //**** 完成下载
                if (aDownload.succeeded && this.DL_DONE)
                    this.playSoundFile(this.DL_DONE)
            },
  
            playSoundFile: function(aFilePath) {
                if (!aFilePath)
                    return;
                var ios = Components.classes["@mozilla.org/network/io-service;1"]
                    .createInstance(Components.interfaces["nsIIOService"]);
                try {
                    var uri = ios.newURI(aFilePath, "UTF-8", null);
                } catch (e) {
                    return;
                }
                var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
                if (!file.exists())
                    return;
  
                this.play(uri);
            },
  
            play: function(aUri) {
                var sound = Components.classes["@mozilla.org/sound;1"]
                    .createInstance(Components.interfaces["nsISound"]);
                sound.play(aUri);
            },
  
            handleEvent: function(event) {
                switch (event.type) {
                    case "unload":
                        this.uninit();
                        break;
                }
            }
        }
        downloadPlaySound.init();
    }
  
    //新建下载
    function new_Download() {
            var createDownloadDialog = function() {
                if (encoding)
                    window.openDialog("data:application/vnd.mozilla.xul+xml;charset=UTF-8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPD94bWwtc3R5bGVzaGVldCBocmVmPSJjaHJvbWU6Ly9nbG9iYWwvc2tpbi8iIHR5cGU9InRleHQvY3NzIj8+Cjx3aW5kb3cgeG1sbnM9Imh0dHA6Ly93d3cubW96aWxsYS5vcmcva2V5bWFzdGVyL2dhdGVrZWVwZXIvdGhlcmUuaXMub25seS54dWwiIHdpZHRoPSI1MDAiIGhlaWdodD0iMzAwIiB0aXRsZT0i5paw5bu65LiL6L295Lu75YqhIj4KCTxoYm94IGFsaWduPSJjZW50ZXIiIHRvb2x0aXB0ZXh0PSJodHRwOi8vd3d3LmV4YW1wbGUuY29tL1sxLTEwMC0zXSAgKFvlvIDlp4st57uT5p2fLeS9jeaVsF0pIj4KCQk8bGFiZWwgdmFsdWU9IuaJuemHj+S7u+WKo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nlci9jb250ZW50L2Jyb3dzZXIueHVsIil7CgkJCW93bmVyID0gb3duZXIub3BlbmVyOwoJCX0KdmFyIG1haW53aW4gPSBDb21wb25lbnRzLmNsYXNzZXNbIkBtb3ppbGxhLm9yZy9hcHBzaGVsbC93aW5kb3ctbWVkaWF0b3I7MSJdLmdldFNlcnZpY2UoQ29tcG9uZW50cy5pbnRlcmZhY2VzLm5zSVdpbmRvd01lZGlhdG9yKS5nZXRNb3N0UmVjZW50V2luZG93KCJuYXZpZ2F0b3I6YnJvd3NlciIpOwkJCWRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoInRleHRib3giKS5hZGRFdmVudExpc3RlbmVyKCJrZXl1cCIsIFBhcnNlVVJMcywgZmFsc2UpOwoJCWRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoImJ1dHRvbiIpLmFkZEV2ZW50TGlzdGVuZXIoImNvbW1hbmQiLCBmdW5jdGlvbiAoKSB7CQlkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjdXJscyIpLnZhbHVlLnNwbGl0KCJcbiIpLmZvckVhY2goZnVuY3Rpb24gKHVybCkgewoJCQkJb3duZXIuc2F2ZVVSTCh1cmwgLCBudWxsLCBudWxsLCBudWxsLCBudWxsLCBudWxsLCBtYWlud2luLmRvY3VtZW50KTsKCQkJfSk7CgkJCWNsb3NlKCkKCQl9LCBmYWxzZSk7CgkJZG9jdW1lbnQucXVlcnlTZWxlY3RvcigidGV4dGJveCIpLnZhbHVlID0gb3duZXIucmVhZEZyb21DbGlwYm9hcmQoKTsKCQlQYXJzZVVSTHMoKTsKCQldXT4KCTwvc2NyaXB0Pgo8L3dpbmRvdz4=", "name", "top=" + (window.screenY + window.innerHeight / 4 - 50) + ",left=" + (window.screenX + window.innerWidth / 2 - 250));
                else
                    window.openDialog("data:application/vnd.mozilla.xul+xml;charset=UTF-8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPD94bWwtc3R5bGVza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cnVlLCBudWxsLCBtYWlud2luLmRvY3VtZW50KTsKCQkJfSk7CgkJCWNsb3NlKCkKCQl9LCBmYWxzZSk7CgkJZG9jdW1lbnQucXVlcnlTZWxlY3RvcigidGV4dGJveCIpLnZhbHVlID0gb3duZXIucmVhZEZyb21DbGlwYm9hcmQoKTsKCQlQYXJzZVVSTHMoKTsKCQldXT4KCTwvc2NyaXB0Pgo8L3dpbmRvdz4=", "name", "top=" + (window.screenY + window.innerHeight / 4 - 50) + ",left=" + (window.screenX + window.innerWidth / 2 - 250));
            }
  
            location.href.startsWith('chrome://browser/content/browser.x') && (function() {
                document.getElementById('downloads-button').parentNode.addEventListener('click', function(e) {
                    if (e.target.id == "downloads-button" || e.target.id == "downloads-indicator") {
                        if (e.button == 2) {
                            if (!(e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
                                createDownloadDialog();
                                e.stopPropagation();
                                e.preventDefault();
                            }
                        }
                    }
                }, false);
            })();
  
            location == "chrome://browser/content/places/places.xul" && (function() {
                var button = document.querySelector("#placesToolbar").insertBefore(document.createXULElement("toolbarbutton"), document.querySelector("#clearDownloadsButton"));
                button.id = "createNewDownload";
                button.label = "新建下载";
                button.style.paddingRight = "9px";
                button.addEventListener("command", createDownloadDialog, false);
                window.addEventListener("mouseover", function(e) {
                    button.style.display = (document.getElementById("searchFilter").attributes.getNamedItem("collection").value == "downloads") ? "-moz-box" : "none";
                }, false);
            })();
        }
        // 从硬盘中删除
    function downloadsPanel_removeFile() {
    var removeDownloadfile = {
        currentPanel: 1,
        removeStatus: function () {
            let RMBtn = document.querySelector("#removeDownload");
            if (RMBtn) {
                var listbox, node;
                let flag = removeDownloadfile.currentPanel;
                if (flag == "1") {
                    listbox = document.querySelector("#downloadsListBox");
                    node = listbox && listbox.selectedItems && listbox.selectedItems[0];
                } else if (flag == "3") {
                    listbox = document.querySelector("#downloadsRichListBox");
                    node = listbox && listbox.selectedItems && listbox.selectedItems[0];
                } else {
                    //listbox = document.querySelector("#panelMenu_downloadsMenu");
                    node = document.getElementById("panelDownloadsContextMenu");
                }
                let state = (node && node.getAttribute('state'));
                let exists = (node && node.getAttribute('exists'));
                RMBtn.setAttribute("disabled", "true");
                if (state != "0" && state != "4" && state != "5" && exists == "true") {
                    RMBtn.removeAttribute("disabled");
                }
            }
  
        },
        removeMenu: function (contextMenuId) {
            try {
                removeDownloadfile.removeStatus();
            } catch (e) {
                alert(e.message)
            }
            ;
            let pnl = document.querySelector("#" + contextMenuId);
            if (pnl.querySelector("#removeDownload")) return;
  
            let menuitem = document.getElementById("removeDownload") || document.createXULElement("menuitem"),
                rlm = pnl.querySelector('.downloadRemoveFromHistoryMenuItem');
  
            menuitem.setAttribute("label", rlm.getAttribute("label").indexOf("History") != -1 ? "Delete File" : "\u4ECE\u786C\u76D8\u4E2D\u5220\u9664");
            menuitem.setAttribute("id", "removeDownload");
  
            function removeSelectFile(path) {
                let file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
                try {
                    file.initWithPath(path);
                } catch (e) {
  
                }
                if (!file.exists()) {
                    if (/\..{0,10}(\.part)$/.test(file.path))
                        file.initWithPath(file.path.replace(".part", ""));
                    else
                        file.initWithPath(file.path + ".part");
                }
                if (file.exists()) {
                    file.permissions |= 0666;
                    file.remove(0);
                }
            }
  
            menuitem.onclick = function (e) {
  
                if (e.target.disabled) return;
                if (removeDownloadfile.currentPanel == "2") {
                    //var ddBox = document.getElementById("panelMenu_downloadsMenu");
                    //if(!ddBox)return;
                    try {
                        let sShell = document.getElementById("panelDownloadsContextMenu")._anchorNode._shell;
                        let path = sShell.download.target.path;
                        removeSelectFile(path);
                        sShell.doCommand("cmd_delete");
                    } catch (e) {
                    }
                } else {
                    var ddBox = document.getElementById("downloadsRichListBox");
                    if (!(ddBox && ddBox._placesView)) {
                        ddBox = document.getElementById("downloadsListBox");
                    }
                    if (!ddBox) return;
                    var len = ddBox.selectedItems.length;
  
                    for (var i = len - 1; i >= 0; i--) {
                        let sShell = ddBox.selectedItems[i]._shell;
                        let path = sShell.download.target.path;
                        removeSelectFile(path);
                        sShell.doCommand("cmd_delete");
                    }
                }
  
            };
  
            try {
                pnl.insertBefore(menuitem, rlm.nextSibling);
            } catch (e) {
                alert(e.message);
            }
            removeDownloadfile.removeStatus();
        },
        removeMenu1: function () {
            removeDownloadfile.currentPanel = "1";
            removeDownloadfile.removeMenu("downloadsContextMenu");
        },
        removeMenu2: function () {
            removeDownloadfile.currentPanel = "2";
            removeDownloadfile.removeMenu("panelDownloadsContextMenu");
        },
        removeMenu3: function () {
            removeDownloadfile.currentPanel = "3";
            removeDownloadfile.removeMenu("downloadsContextMenu");
        },
        inited1:false,
        init1: function () {
                if(removeDownloadfile.inited1)return;
                removeDownloadfile.inited1 = true;
            document.querySelector("#downloadsContextMenu").addEventListener("popupshowing", this.removeMenu1, false);
        },
        inited2:false,
        init2: function () {
                if(removeDownloadfile.inited2)return;
                removeDownloadfile.inited2 = true;
            document.querySelector("#panelDownloadsContextMenu").addEventListener("popupshowing", this.removeMenu2, false);
        },
        inited3:false,
        init3: function () {
                if(removeDownloadfile.inited3)return;
                removeDownloadfile.inited3 = true;
            document.querySelector("#downloadsContextMenu").addEventListener("popupshowing", this.removeMenu3, false);
        },
        init:function () {
            if (location != "chrome://browser/content/places/places.xul") {
                  
                DownloadsPanel._openPopupIfDataReadyOrg = DownloadsPanel._openPopupIfDataReady;
                DownloadsPanel._openPopupIfDataReady = function(){
                    DownloadsPanel._openPopupIfDataReadyOrg();
                    removeDownloadfile.init1();
                }
                  
                var times = 0;
                function checkStatus() {//等待列表弹出
                    let pnl = document.querySelector("#panelDownloadsContextMenu");
                    if (pnl && pnl.querySelector('.downloadRemoveFromHistoryMenuItem')) {
                        removeDownloadfile.init2()
                    } else {
                        times++;
                        if (times > 5) {
                            times = 0;
                            return;
                        }
                        setTimeout(checkStatus, 1000);
                    }
                }
  
                                DownloadsSubview.showOrg = DownloadsSubview.show;
                DownloadsSubview.show = async function show(anchor) {
                    DownloadsSubview.showOrg(anchor);
                    setTimeout(checkStatus, 1000);
                };
  
            } else {
                //我的足迹下载项列表
                removeDownloadfile.init3();
            }
        }
    }
  
    removeDownloadfile.init();
    window.removeDownloadfile = removeDownloadfile;
    }
  
    //精确显示文件大小
    function downloadFileSize() {
        location.href.startsWith('chrome://browser/content/browser.x') && (DownloadUtils.convertByteUnits =
            function DU_convertByteUnits(aBytes) {
                let unitIndex = 0;
                while ((aBytes >= 999.5) && (unitIndex < 3)) {
                    aBytes /= 1024;
                    unitIndex++;
                }
                return [(aBytes > 0) && (aBytes < 100) && (unitIndex != 0) ? (aBytes < 10 ? (parseInt(aBytes * 100) / 100).toFixed(2) : (parseInt(aBytes * 10) / 10).toFixed(1)) : parseInt(aBytes), ['bytes', 'KB', 'MB', 'GB'][unitIndex]];
            });
    }
  
    // 自动关闭下载产生的空白标签
    function autoClose_blankTab() {
        eval("gBrowser.mTabProgressListener = " + gBrowser.mTabProgressListener.toString().replace(/(?=var location)/, '\
            if (aWebProgress.DOMWindow.document.documentURI == "about:blank"\
            && aRequest.QueryInterface(nsIChannel).URI.spec != "about:blank" && aStatus == 0) {\
            aWebProgress.DOMWindow.setTimeout(function() {\
            !aWebProgress.isLoadingDocument && aWebProgress.DOMWindow.close();\
            }, 100);\
            }\
        '));
    }
  
    // 保存并打开
    function save_And_Open() {
            var saveAndOpen = document.getAnonymousElementByAttribute(document.querySelector("*"), "dlgtype", "extra2");
            saveAndOpen.parentNode.insertBefore(saveAndOpen, document.documentElement.getButton("accept").nextSibling);
            saveAndOpen.setAttribute("hidden", "false");
            saveAndOpen.setAttribute("label", "\u4FDD\u5B58\u5E76\u6253\u5F00");
            saveAndOpen.setAttribute("oncommand", 'Components.classes["@mozilla.org/browser/browserglue;1"].getService(Components.interfaces.nsIBrowserGlue).getMostRecentBrowserWindow().saveAndOpen.urls.push(dialog.mLauncher.source.asciiSpec);document.querySelector("#save").click();document.documentElement.getButton("accept").disabled=0;document.documentElement.getButton("accept").click()')
        }
        //作用于 main 窗口
    function saveAndOpen_on_main() {
        Components.utils.import("resource://gre/modules/Downloads.jsm");
        saveAndOpen = {
            urls: [],
            init: function() {
                Downloads.getList(Downloads.ALL).then(list => {
                    list.addView({
                        onDownloadChanged: function(dl) {
                            if (Convert) {
                                if (dl.progress == 100 && saveAndOpen.urls.indexOf(dl.source.url) > -1) {
                                    dl.launch();
                                    saveAndOpen.urls[saveAndOpen.urls.indexOf(dl.source.url)] = "";
                                }
                            } else {
                                if (dl.progress == 100 && saveAndOpen.urls.indexOf(dl.source.url) > -1) {
                                    (new FileUtils.File(dl.target.path)).launch();
                                    saveAndOpen.urls[saveAndOpen.urls.indexOf(dl.source.url)] = "";
                                }
                            }
                        },
                        onDownloadAdded: function() {},
                        onDownloadRemoved: function() {},
                    });
                }).then(null, Cu.reportError);
            }
  
        }
        saveAndOpen.init();
    }
  
    // 下载改名
    function download_dialog_changeName() {
            //注:同时关闭改名和下拉菜单会导致下载文件的文件名不显示(非要关闭请默认在28行最前面加//来注释掉该功能)
            if (location != "chrome://mozapps/content/downloads/unknownContentType.xul") return;
            document.querySelector("#mode").addEventListener("select", function() {
                if (dialog.dialogElement("save").selected) {
                    if (!document.querySelector("#locationtext")) {
                        if (rename || encodingConvert) {
                            var orginalString = "";
                            if (encodingConvert) {
                                try {
                                    orginalString = (opener.localStorage.getItem(dialog.mLauncher.source.spec) ||
                                        dialog.mLauncher.source.asciiSpec.substring(dialog.mLauncher.source.asciiSpec.lastIndexOf("/"))).replace(/[\/:*?"<>|]/g, "");
                                    opener.localStorage.removeItem(dialog.mLauncher.source.spec)
                                } catch (e) {
                                    orginalString = dialog.mLauncher.suggestedFileName;
                                }
                            }
                            if (encodingConvert)
                                var locationtext = document.querySelector("#location").parentNode.insertBefore(document.createXULElement("menulist"), document.querySelector("#location"));
                            else
                                var locationtext = document.querySelector("#location").parentNode.insertBefore(document.createXULElement("textbox"), document.querySelector("#location"));
                            locationtext.id = "locationtext";
                            if (rename && encodingConvert)
                                locationtext.setAttribute("editable", "true");
                            locationtext.setAttribute("style", "margin-top:-2px;margin-bottom:-3px");
                            locationtext.setAttribute("tooltiptext", "Ctrl+\u70B9\u51FB\u8F6C\u6362url\u7F16\u7801\n\u5DE6\u952E\u003AUNICODE\n\u53F3\u952E\u003AGB2312");
                            locationtext.addEventListener("click", function(e) {
                                if (e.ctrlKey) {
                                    if (e.button == 0)
                                        this.value = decodeURIComponent(this.value);
                                    if (e.button == 2) {
                                        e.preventDefault();
                                        converter.charset = "GB2312";
                                        this.value = converter.ConvertToUnicode(unescape(this.value));
                                    }
                                }
                            }, false);
                            if (rename)
                                locationtext.value = dialog.mLauncher.suggestedFileName;
                            if (encodingConvert) {
                                locationtext.addEventListener("command", function(e) {
                                    if (rename)
                                        locationtext.value = e.target.value;
                                    document.title = "Opening " + e.target.value;
                                });
                                let menupopup = locationtext.appendChild(document.createXULElement("menupopup"));
                                let menuitem = menupopup.appendChild(document.createXULElement("menuitem"));
                                menuitem.value = dialog.mLauncher.suggestedFileName;
                                menuitem.label = "Original: " + menuitem.value;
                                if (!rename)
                                    locationtext.value = menuitem.value;
                                let converter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
                                    .getService(Components.interfaces.nsIScriptableUnicodeConverter);
  
                                function createMenuitem(encoding) {
                                        converter.charset = encoding;
                                        let menuitem = menupopup.appendChild(document.createXULElement("menuitem"));
                                        menuitem.value = converter.ConvertToUnicode(orginalString).replace(/^"(.+)"$/, "$1");
                                        menuitem.label = encoding + ": " + menuitem.value;
                                    }
                                    ["GB18030", "BIG5", "Shift-JIS"].forEach(function(item) {
                                        createMenuitem(item)
                                    });
                            }
                        }
                    }
                    document.querySelector("#location").hidden = true;
                    document.querySelector("#locationtext").hidden = false;
                } else {
                    document.querySelector("#locationtext").hidden = true;
                    document.querySelector("#location").hidden = false;
                }
            }, false)
            if (locking)
                dialog.dialogElement("save").click();
            else
                dialog.dialogElement("save").selected && dialog.dialogElement("save").click();
            window.addEventListener("dialogaccept", function() {
                if ((document.querySelector("#locationtext").value != dialog.mLauncher.suggestedFileName) && dialog.dialogElement("save").selected) {
                    var mainwin = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
                    mainwin.eval("(" + mainwin.internalSave.toString().replace("let ", "").replace("var fpParams", "fileInfo.fileExt=null;fileInfo.fileName=aDefaultFileName;var fpParams") + ")")(dialog.mLauncher.source.asciiSpec, null, document.querySelector("#locationtext").value, null, null, null, null, null, null, mainwin.document, Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch).getBoolPref("browser.download.useDownloadDir"), null);
                    document.documentElement.removeAttribute("ondialogaccept");
                }
            }, false);
        }
        //作用于 main 窗口
    function download_dialog_changeName_on_main() {
        const obsService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
        const RESPONSE_TOPIC = 'http-on-examine-response';
  
        var respObserver = {
            observing: false,
            observe: function(subject, topic, data) {
                try {
                    let channel = subject.QueryInterface(Ci.nsIHttpChannel);
                    let header = channel.contentDispositionHeader;
                    let associatedWindow = channel.notificationCallbacks
                        .getInterface(Components.interfaces.nsILoadContext)
                        .associatedWindow;
                    associatedWindow.localStorage.setItem(channel.URI.spec, header.split("=")[1]);
                } catch (ex) {};
            },
            start: function() {
                if (!this.observing) {
                    obsService.addObserver(this, RESPONSE_TOPIC, false);
                    this.observing = true;
                }
            },
            stop: function() {
                if (this.observing) {
                    obsService.removeObserver(this, RESPONSE_TOPIC, false);
                    this.observing = false;
                }
            }
        };
  
        respObserver.start();
        addEventListener("beforeunload", function() {
            respObserver.stop();
        })
    }
  
  
    // 另存为...
    function download_dialog_saveas() {
        var saveas = document.documentElement.getButton("extra1");
            saveas.setAttribute("hidden", "false");
            saveas.setAttribute("label", "\u53E6\u5B58\u4E3A");
            saveas.addEventListener("command", function() {
                var mainwin = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
                mainwin.eval("(" + mainwin.internalSave.toString().replace("let ", "").replace("var fpParams", "fileInfo.fileExt=null;fileInfo.fileName=aDefaultFileName;var fpParams") + ")")(dialog.mLauncher.source.asciiSpec, null, (document.querySelector("#locationtext") ? document.querySelector("#locationtext").value : dialog.mLauncher.suggestedFileName), null, null, null, null, null, null, mainwin.document, 0, null);
                close();
            }, false);
    }
  
    // 保存到...
    function download_dialog_saveTo() {
        //目录路径的反斜杠\要双写\\
        //第一次使用要修改路径,否则无法下载
        //如果使用Firefox3.6 + userChromeJS v1.2,则路径中的汉字要转义为\u6C49\u5B57编码类型,否则会出现乱码
        var cssStr = (function() {
            /*
                    button[label="\4FDD\5B58\5230"] .dropmarker-icon{
                            display:none;
                    }
                    button[label="\4FDD\5B58\5230"]::after{
                            content:"";
                            display:-moz-box;
                            width:8px;
                            height:19px;
                            margin-left:-20px;
                            -moz-appearance: menulist-button;
                    }
                    button[label="\4FDD\5B58\5230"][disabled]::after{
                            opacity:.3;
                    }
                    */
        }).toString().replace(/^.+\s|.+$/g, "");
        var style = document.createProcessingInstruction("xml-stylesheet", "type=\"text/css\"" + " href=\"data:text/css;base64," + btoa(cssStr) + "\"");
        document.insertBefore(style, document.firstChild);
        var dir = [
            //["D:\\下载", "压缩"],
            //["D:\\软件", "软件"],
            //["D:\\文档", "文档"],
            //["D:\\音乐", "歌曲"],
            //["D:\\下载", "其他"],
        ["C:\\", "C盘"],
        ["D:\\", "D盘"],
        ["E:\\", "E盘"],
        ["F:\\", "F盘"]
        ];
        var saveTo = document.documentElement._buttons.cancel.parentNode.insertBefore(document.createXULElement("button"), document.documentElement._buttons.cancel);
        var saveToMenu = saveTo.appendChild(document.createXULElement("menupopup"));
        saveTo.classList.toggle("dialog-button");
        saveTo.label = "\u4FDD\u5B58\u5230";
        saveTo.type = "menu";
        dir.forEach(function(dir) {
            var [name, dir] = [dir[1], dir[0]];
            var item = saveToMenu.appendChild(document.createXULElement("menuitem"));
            item.setAttribute("label", (name || (dir.match(/[^\\/]+$/) || [dir])[0]));
            item.setAttribute("image", "moz-icon:file:///" + dir + "\\");
            item.setAttribute("class", "menuitem-iconic");
            item.onclick = function() {
                var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
                file.initWithPath(dir.replace(/^\./, Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path) + "\\" + (document.querySelector("#locationtext") ? document.querySelector("#locationtext").value : document.querySelector("#location").value));
                dialog.mLauncher.saveToDisk(file, 1);
                dialog.onCancel = function() {};
                close();
            };
        })
    }
  
    // 下载弹出窗口双击链接复制完整链接
    function download_dialog_showCompleteURL() {
        var s = document.querySelector("#source");
        s.value = dialog.mLauncher.source.spec;
        s.setAttribute("crop", "center");
        s.setAttribute("tooltiptext", dialog.mLauncher.source.spec);
        s.setAttribute("ondblclick", 'Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper).copyString(dialog.mLauncher.source.spec)')
    }
  
    // 下载弹出窗口双击保存文件项执行下载
    function download_dialog_doubleclicksaveL() {
        addEventListener("dblclick", function(event) {
            event.target.nodeName === "radio" && document.documentElement.getButton("accept").click()
        }, false)
    }
  
    function download_speed() {
        var appVersion = Services.appinfo.version.split(".")[0];
        if (appVersion >= 38) {
            eval("DownloadsViewItem.prototype._updateProgress = " +
                DownloadsViewItem.prototype._updateProgress.toString().replace('status.text', 'status.tip'));
        } else if (appVersion < 38) {
            eval("DownloadsViewItem.prototype._updateStatusLine = " +
                DownloadsViewItem.prototype._updateStatusLine.toString().replace('[statusTip', '[status'));
        }
    }
})();
lonely_8
狐狸大王
狐狸大王
  • UID30273
  • 注册日期2009-09-03
  • 最后登录2019-10-15
  • 发帖数485
  • 经验247枚
  • 威望0点
  • 贡献值72点
  • 好评度75点
  • 社区居民
  • 忠实会员
47楼#
发布于:2019-07-02 16:39
etjim:你好楼主大大,又要再麻烦你一次,
今日更新到FF69b1,已经按照大大的提示,将所有在使用的uc脚本都修改了一遍;但以下这个脚本修改了以后,仍有部分功能失效,请问要如何修改呢,请指教一下。
// ==UserScript==
// @...
回到原帖
// ==UserScript==
// @name           downloadPlus.uc.js
// @description    从硬盘中删除+下载重命名并可转码+双击复制链接+另存为+保存并打开+完成下载提示音+自动关闭下载产生的空白标签
// @author         w13998686967再次修改整合 (ywzhaiqi、黒仪大螃蟹、Alice0775、紫云飞)
// @include        chrome://browser/content/browser.xhtml
// @include        chrome://browser/content/places/places.xul
// @include        chrome://mozapps/content/downloads/unknownContentType.xul
// @include        chrome://mozapps/content/downloads/downloads.xul
// @version        2014.11.02 增加多个功能
// @version        2014.06.06 add delay to fix for new userChrome.js
// ==/UserScript==
   
(function() {
   
    var encoding = true //true,(新建下载)弹窗             false,不弹窗
    var rename = true //true,(下载改名)可改名           false,不可改
    var locking = true //true,(下载改名)自动锁定保存文件 false,不锁定
    var encodingConvert = true //true,(下载改名)开启下拉菜单选项 false,关闭下拉菜单选项
    var Convert = true //true,(保存并打开)兼容火狐版本26+(也许会有BUG)     false,火狐版本29+
   
    if (!window.Services) Components.utils.import("resource://gre/modules/Services.jsm");
    if (!window.DownloadUtils) Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
   
    switch (location.href) {
        case "chrome://browser/content/browser.xhtml":
            setTimeout(function() {
                new_Download(); // 新建下载
                downloadsPanel_removeFile(); // 从硬盘中删除
                //downloadSound_Play(); // 下载完成提示音
                downloadFileSize(); // 精确显示文件大小
                autoClose_blankTab(); // 自动关闭下载产生的空白标签
                saveAndOpen_on_main(); // 跟下面的 save_AndOpen 配合使用
                download_dialog_changeName_on_main(); // 跟下面的 download_dialog_changeName 配合使用
                download_speed(); //下载面板显示下载速度
            }, 200);
            break;
        case "chrome://mozapps/content/downloads/unknownContentType.xul":
            setTimeout(function() {
                save_And_Open(); // 保存并打开
                download_dialog_changeName(); // 下载改名
                download_dialog_saveas(); // 另存为...
                download_dialog_saveTo(); // 保存到...
                download_dialog_showCompleteURL(); // 下载弹出窗口双击链接复制完整链接
                download_dialog_doubleclicksaveL(); // 下载弹出窗口双击保存文件项执行下载
                window.sizeToContent(); // 下载弹出窗口大小自适应(确保在添加的按钮之后加载)
            }, 200);
            break;
        case "chrome://browser/content/places/places.xul":
            setTimeout(function() {
                new_Download(); // 新建下载(我的足迹)
                downloadsPanel_removeFile(); // 从硬盘中删除(我的足迹)
            }, 200);
            break;
    }
   
   
    // 下载完成提示音
    function downloadSound_Play() {
        var downloadPlaySound = {
   
            DL_START: null,
            DL_DONE: "file:///C:/WINDOWS/Media/chimes.wav",
            DL_CANCEL: null,
            DL_FAILED: null,
   
            _list: null,
            init: function sampleDownload_init() {
                XPCOMUtils.defineLazyModuleGetter(window, "Downloads",
                    "resource://gre/modules/Downloads.jsm");
   
   
                window.addEventListener("unload", this, false);
   
                //**** 监视下载
                if (!this._list) {
                    Downloads.getList(Downloads.ALL).then(list => {
                        this._list = list;
                        return this._list.addView(this);
                    }).then(null, Cu.reportError);
                }
            },
   
            uninit: function() {
                window.removeEventListener("unload", this, false);
                if (this._list) {
                    this._list.removeView(this);
                }
            },
   
            onDownloadAdded: function(aDownload) {
                //**** 开始下载
                if (this.DL_START);
                this.playSoundFile(this.DL_START);
            },
   
            onDownloadChanged: function(aDownload) {
                //**** 取消下载
                if (aDownload.canceled && this.DL_CANCEL)
                    this.playSoundFile(this.DL_CANCEL)
                    //**** 下载失败
                if (aDownload.error && this.DL_FAILED)
                    this.playSoundFile(this.DL_FAILED)
                    //**** 完成下载
                if (aDownload.succeeded && this.DL_DONE)
                    this.playSoundFile(this.DL_DONE)
            },
   
            playSoundFile: function(aFilePath) {
                if (!aFilePath)
                    return;
                var ios = Components.classes["@mozilla.org/network/io-service;1"]
                    .createInstance(Components.interfaces["nsIIOService"]);
                try {
                    var uri = ios.newURI(aFilePath, "UTF-8", null);
                } catch (e) {
                    return;
                }
                var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
                if (!file.exists())
                    return;
   
                this.play(uri);
            },
   
            play: function(aUri) {
                var sound = Components.classes["@mozilla.org/sound;1"]
                    .createInstance(Components.interfaces["nsISound"]);
                sound.play(aUri);
            },
   
            handleEvent: function(event) {
                switch (event.type) {
                    case "unload":
                        this.uninit();
                        break;
                }
            }
        }
        downloadPlaySound.init();
    }
   
    //新建下载
    function new_Download() {
            var createDownloadDialog = function() {
                if (encoding)
                    window.openDialog("data:application/vnd.mozilla.xul+xml;charset=UTF-8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPD94bWwtc3R5bGVzaGVldCBocmVmPSJjaHJvbWU6Ly9nbG9iYWwvc2tpbi8iIHR5cGU9InRleHQvY3NzIj8+Cjx3aW5kb3cgeG1sbnM9Imh0dHA6Ly93d3cubW96aWxsYS5vcmcva2V5bWFzdGVyL2dhdGVrZWVwZXIvdGhlcmUuaXMub25seS54dWwiIHdpZHRoPSI1MDAiIGhlaWdodD0iMzAwIiB0aXRsZT0i5paw5bu65LiL6L295Lu75YqhIj4KCTxoYm94IGFsaWduPSJjZW50ZXIiIHRvb2x0aXB0ZXh0PSJodHRwOi8vd3d3LmV4YW1wbGUuY29tL1sxLTEwMC0zXSAgKFvlvIDlp4st57uT5p2fLeS9jeaVsF0pIj4KCQk8bGFiZWwgdmFsdWU9IuaJuemHj+S7u+WKoSI+PC9sYWJlbD4KCQk8dGV4dGJveCBmbGV4PSIxIi8+Cgk8L2hib3g+Cgk8dGV4dGJveCBpZD0idXJscyIgbXVsdGlsaW5lPSJ0cnVlIiBmbGV4PSIxIi8+Cgk8aGJveCBkaXI9InJldmVyc2UiPgoJCTxidXR0b24gbGFiZWw9IuW8gOWni+S4i+i9vSIvPgoJPC9oYm94PgoJPHNjcmlwdD4KCQk8IVtDREFUQVsKCQlmdW5jdGlvbiBQYXJzZVVSTHMoKSB7CgkJCXZhciBiYXRjaHVybCA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoInRleHRib3giKS52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KS5hZGRFdmVudExpc3RlbmVyKCJrZXl1cCIsIFBhcnNlVVJMcywgZmFsc2UpOwoJCWRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoImJ1dHRvbiIpLmFkZEV2ZW50TGlzdGVuZXIoImNvbW1hbmQiLCBmdW5jdGlvbiAoKSB7CQlkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjdXJscyIpLnZhbHVlLnNwbGl0KCJcbiIpLmZvckVhY2goZnVuY3Rpb24gKHVybCkgewoJCQkJb3duZXIuc2F2ZVVSTCh1cmwgLCBudWxsLCBudWxsLCBudWxsLCBudWxsLCBudWxsLCBtYWlud2luLmRvY3VtZW50KTsKCQkJfSk7CgkJCWNsb3NlKCkKCQl9LCBmYWxzZSk7CgkJZG9jdW1lbnQucXVlcnlTZWxlY3RvcigidGV4dGJveCIpLnZhbHVlID0gb3duZXIucmVhZEZyb21DbGlwYm9hcmQoKTsKCQlQYXJzZVVSTHMoKTsKCQldXT4KCTwvc2NyaXB0Pgo8L3dpbmRvdz4=", "name", "top=" + (window.screenY + window.innerHeight / 4 - 50) + ",left=" + (window.screenX + window.innerWidth / 2 - 250));
                else
                    window.openDialog("data:application/vnd.mozilla.xul+xml;charset=UTF-8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPD94bWwtc3R5bGVzaGVldCBocmVmPSJjaHJvbWU6Ly9nbG9iYWwvc2tpbi8iIHR5cGU9InRleHQvY3NzIj8+Cjx3aW5kb3cgeG1sbnM9Imh0dHA6Ly93d3cubW96aWxsYS5vcmcva2V5bWFzdGVyL2dhdGVrZWVwZXIvdGhlcmUuaXMub25seS54dWwiIHdpZHRoPSI1MDAiIGhlaWdodD0iMzAwIiB0aXRsZT0i5paw5bu65LiL6L295Lu75YqhIj4KCTxoYm94IGFsaWduPSJjZW50ZXIiIHRvb2x0aXB0ZXh0PSJodHRwOi8vd3d3LmV4YW1wbGUuY29tL1sxLTEwMC0zXSAgKFvlvI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xlKG93bmVyLm9wZW5lciAmJiBvd25lci5sb2NhdGlvbiAhPSAiY2hyb21lOi8vYnJvd3Nlci9jb250ZW50L2Jyb3dzZXIueHVsIil7CgkJCW93bmVyID0gb3duZXIub3BlbmVyOwoJCX0KdmFyIG1haW53aW4gPSBDb21wb25lbnRzLmNsYXNzZXNbIkBtb3ppbGxhLm9yZy9hcHBzaGVsbC93aW5kb3ctbWVkaWF0b3I7MSJdLmdldFNlcnZpY2UoQ29tcG9uZW50cy5pbnRlcmZhY2VzLm5zSVdpbmRvd01lZGlhdG9yKS5nZXRNb3N0UmVjZW50V2luZG93KCJuYXZpZ2F0b3I6YnJvd3NlciIpOwkJCWRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoInRleHRib3giKS5hZGRFdmVudExpc3RlbmVyKCJrZXl1cCIsIFBhcnNlVVJMcywgZmFsc2UpOwoJCWRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoImJ1dHRvbiIpLmFkZEV2ZW50TGlzdGVuZXIoImNvbW1hbmQiLCBmdW5jdGlvbiAoKSB7CQlkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjdXJscyIpLnZhbHVlLnNwbGl0KCJcbiIpLmZvckVhY2goZnVuY3Rpb24gKHVybCkgewoJCQkJb3duZXIuc2F2ZVVSTCh1cmwgLCBudWxsLCBudWxsLCBudWxsLCB0cnVlLCBudWxsLCBtYWlud2luLmRvY3VtZW50KTsKCQkJfSk7CgkJCWNsb3NlKCkKCQl9LCBmYWxzZSk7CgkJZG9jdW1lbnQucXVlcnlTZWxlY3RvcigidGV4dGJveCIpLnZhbHVlID0gb3duZXIucmVhZEZyb21DbGlwYm9hcmQoKTsKCQlQYXJzZVVSTHMoKTsKCQldXT4KCTwvc2NyaXB0Pgo8L3dpbmRvdz4=", "name", "top=" + (window.screenY + window.innerHeight / 4 - 50) + ",left=" + (window.screenX + window.innerWidth / 2 - 250));
            }
   
            location.href.startsWith('chrome://browser/content/browser.x') && (function() {
                document.getElementById('downloads-button').parentNode.addEventListener('click', function(e) {
                    if (e.target.id == "downloads-button" || e.target.id == "downloads-indicator") {
                        if (e.button == 2) {
                            if (!(e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
                                createDownloadDialog();
                                e.stopPropagation();
                                e.preventDefault();
                            }
                        }
                    }
                }, false);
            })();
   
            location == "chrome://browser/content/places/places.xul" && (function() {
                var button = document.querySelector("#placesToolbar").insertBefore(document.createXULElement("toolbarbutton"), document.querySelector("#clearDownloadsButton"));
                button.id = "createNewDownload";
                button.label = "新建下载";
                button.style.paddingRight = "9px";
                button.addEventListener("command", createDownloadDialog, false);
                window.addEventListener("mouseover", function(e) {
                    button.style.display = (document.getElementById("searchFilter").attributes.getNamedItem("collection").value == "downloads") ? "-moz-box" : "none";
                }, false);
            })();
        }
        // 从硬盘中删除
    function downloadsPanel_removeFile() {
    var removeDownloadfile = {
        currentPanel: 1,
        removeStatus: function () {
            let RMBtn = document.querySelector("#removeDownload");
            if (RMBtn) {
                var listbox, node;
                let flag = removeDownloadfile.currentPanel;
                if (flag == "1") {
                    listbox = document.querySelector("#downloadsListBox");
                    node = listbox && listbox.selectedItems && listbox.selectedItems[0];
                } else if (flag == "3") {
                    listbox = document.querySelector("#downloadsRichListBox");
                    node = listbox && listbox.selectedItems && listbox.selectedItems[0];
                } else {
                    //listbox = document.querySelector("#panelMenu_downloadsMenu");
                    node = document.getElementById("panelDownloadsContextMenu");
                }
                let state = (node && node.getAttribute('state'));
                let exists = (node && node.getAttribute('exists'));
                RMBtn.setAttribute("disabled", "true");
                if (state != "0" && state != "4" && state != "5" && exists == "true") {
                    RMBtn.removeAttribute("disabled");
                }
            }
   
        },
        removeMenu: function (contextMenuId) {
            try {
                removeDownloadfile.removeStatus();
            } catch (e) {
                alert(e.message)
            }
            ;
            let pnl = document.querySelector("#" + contextMenuId);
            if (pnl.querySelector("#removeDownload")) return;
   
            let menuitem = document.getElementById("removeDownload") || document.createXULElement("menuitem"),
                rlm = pnl.querySelector('.downloadRemoveFromHistoryMenuItem');
   
            menuitem.setAttribute("label", rlm.getAttribute("label").indexOf("History") != -1 ? "Delete File" : "\u4ECE\u786C\u76D8\u4E2D\u5220\u9664");
            menuitem.setAttribute("id", "removeDownload");
   
            function removeSelectFile(path) {
                let file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
                try {
                    file.initWithPath(path);
                } catch (e) {
   
                }
                if (!file.exists()) {
                    if (/\..{0,10}(\.part)$/.test(file.path))
                        file.initWithPath(file.path.replace(".part", ""));
                    else
                        file.initWithPath(file.path + ".part");
                }
                if (file.exists()) {
                    file.permissions |= 0666;
                    file.remove(0);
                }
            }
   
            menuitem.onclick = function (e) {
   
                if (e.target.disabled) return;
                if (removeDownloadfile.currentPanel == "2") {
                    //var ddBox = document.getElementById("panelMenu_downloadsMenu");
                    //if(!ddBox)return;
                    try {
                        let sShell = document.getElementById("panelDownloadsContextMenu")._anchorNode._shell;
                        let path = sShell.download.target.path;
                        removeSelectFile(path);
                        sShell.doCommand("cmd_delete");
                    } catch (e) {
                    }
                } else {
                    var ddBox = document.getElementById("downloadsRichListBox");
                    if (!(ddBox && ddBox._placesView)) {
                        ddBox = document.getElementById("downloadsListBox");
                    }
                    if (!ddBox) return;
                    var len = ddBox.selectedItems.length;
   
                    for (var i = len - 1; i >= 0; i--) {
                        let sShell = ddBox.selectedItems[i]._shell;
                        let path = sShell.download.target.path;
                        removeSelectFile(path);
                        sShell.doCommand("cmd_delete");
                    }
                }
   
            };
   
            try {
                pnl.insertBefore(menuitem, rlm.nextSibling);
            } catch (e) {
                alert(e.message);
            }
            removeDownloadfile.removeStatus();
        },
        removeMenu1: function () {
            removeDownloadfile.currentPanel = "1";
            removeDownloadfile.removeMenu("downloadsContextMenu");
        },
        removeMenu2: function () {
            removeDownloadfile.currentPanel = "2";
            removeDownloadfile.removeMenu("panelDownloadsContextMenu");
        },
        removeMenu3: function () {
            removeDownloadfile.currentPanel = "3";
            removeDownloadfile.removeMenu("downloadsContextMenu");
        },
        inited1:false,
        init1: function () {
                if(removeDownloadfile.inited1)return;
                removeDownloadfile.inited1 = true;
            document.querySelector("#downloadsContextMenu").addEventListener("popupshowing", this.removeMenu1, false);
        },
        inited2:false,
        init2: function () {
                if(removeDownloadfile.inited2)return;
                removeDownloadfile.inited2 = true;
            document.querySelector("#panelDownloadsContextMenu").addEventListener("popupshowing", this.removeMenu2, false);
        },
        inited3:false,
        init3: function () {
                if(removeDownloadfile.inited3)return;
                removeDownloadfile.inited3 = true;
            document.querySelector("#downloadsContextMenu").addEventListener("popupshowing", this.removeMenu3, false);
        },
        init:function () {
            if (location != "chrome://browser/content/places/places.xul") {
                   
                DownloadsPanel._openPopupIfDataReadyOrg = DownloadsPanel._openPopupIfDataReady;
                DownloadsPanel._openPopupIfDataReady = function(){
                    DownloadsPanel._openPopupIfDataReadyOrg();
                    removeDownloadfile.init1();
                }
                   
                var times = 0;
                function checkStatus() {//等待列表弹出
                    let pnl = document.querySelector("#panelDownloadsContextMenu");
                    if (pnl && pnl.querySelector('.downloadRemoveFromHistoryMenuItem')) {
                        removeDownloadfile.init2()
                    } else {
                        times++;
                        if (times > 5) {
                            times = 0;
                            return;
                        }
                        setTimeout(checkStatus, 1000);
                    }
                }
   
                                DownloadsSubview.showOrg = DownloadsSubview.show;
                DownloadsSubview.show = async function show(anchor) {
                    DownloadsSubview.showOrg(anchor);
                    setTimeout(checkStatus, 1000);
                };
   
            } else {
                //我的足迹下载项列表
                removeDownloadfile.init3();
            }
        }
    }
   
    removeDownloadfile.init();
    window.removeDownloadfile = removeDownloadfile;
    }
   
    //精确显示文件大小
    function downloadFileSize() {
        location.href.startsWith('chrome://browser/content/browser.x') && (DownloadUtils.convertByteUnits =
            function DU_convertByteUnits(aBytes) {
                let unitIndex = 0;
                while ((aBytes >= 999.5) && (unitIndex < 3)) {
                    aBytes /= 1024;
                    unitIndex++;
                }
                return [(aBytes > 0) && (aBytes < 100) && (unitIndex != 0) ? (aBytes < 10 ? (parseInt(aBytes * 100) / 100).toFixed(2) : (parseInt(aBytes * 10) / 10).toFixed(1)) : parseInt(aBytes), ['bytes', 'KB', 'MB', 'GB'][unitIndex]];
            });
    }
   
    // 自动关闭下载产生的空白标签
    function autoClose_blankTab() {
        gBrowser.addTabsProgressListener({
            onStateChange (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
                if (!aRequest || !aWebProgress.isTopLevel) return;
                let location;
                try {
                    aRequest.QueryInterface(Ci.nsIChannel);
                    location = aRequest.URI;
                } catch (ex) {}
                if ((aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) &&
                    (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) &&
                    location && location.spec !== 'about:blank' &&
                    aBrowser.documentURI && aBrowser.documentURI.spec === 'about:blank' &&
                    Components.isSuccessCode(aStatus) && !aWebProgress.isLoadingDocument
                ) {
                    gBrowser.removeTab(gBrowser.getTabForBrowser(aBrowser));
                }
            }
        });
    }
   
    // 保存并打开
    function save_And_Open() {
            var saveAndOpen = document.documentElement.getButton("extra2");
            saveAndOpen.parentNode.insertBefore(saveAndOpen, document.documentElement.getButton("accept").nextSibling);
            saveAndOpen.setAttribute("hidden", "false");
            saveAndOpen.setAttribute("label", "\u4FDD\u5B58\u5E76\u6253\u5F00");
            saveAndOpen.addEventListener("command", () => {
                Services.wm.getMostRecentWindow("navigator:browser").saveAndOpen.urls.push(dialog.mLauncher.source.asciiSpec);
                document.querySelector("#save").click();
                document.documentElement.getButton("accept").disabled=0;
                document.documentElement.getButton("accept").click()
            });
        }
        //作用于 main 窗口
    function saveAndOpen_on_main() {
        Components.utils.import("resource://gre/modules/Downloads.jsm");
        saveAndOpen = {
            urls: [],
            init: function() {
                Downloads.getList(Downloads.ALL).then(list => {
                    list.addView({
                        onDownloadChanged: function(dl) {
                            if(dl.progress != 100) return;
                            const index = saveAndOpen.urls.indexOf(dl.source.url);
                            if (Convert) {
                                if (index > -1) {
                                    dl.launch();
                                    saveAndOpen.urls.splice(index, 1);
                                }
                            } else {
                                if (index > -1) {
                                    (new FileUtils.File(dl.target.path)).launch();
                                    saveAndOpen.urls.splice(index, 1);
                                }
                            }
                        },
                        onDownloadAdded: function() {},
                        onDownloadRemoved: function() {},
                    });
                }).then(null, Cu.reportError);
            }
   
        }
        saveAndOpen.init();
    }
   
    // 下载改名
    function download_dialog_changeName() {
            //注:同时关闭改名和下拉菜单会导致下载文件的文件名不显示(非要关闭请默认在28行最前面加//来注释掉该功能)
            if (location != "chrome://mozapps/content/downloads/unknownContentType.xul") return;
            document.querySelector("#mode").addEventListener("select", function() {
                if (dialog.dialogElement("save").selected) {
                    if (!document.querySelector("#locationtext")) {
                        if (rename || encodingConvert) {
                            var orginalString = "";
                            if (encodingConvert) {
                                try {
                                    orginalString = (opener.localStorage.getItem(dialog.mLauncher.source.spec) ||
                                        dialog.mLauncher.source.asciiSpec.substring(dialog.mLauncher.source.asciiSpec.lastIndexOf("/"))).replace(/[\/:*?"<>|]/g, "");
                                    opener.localStorage.removeItem(dialog.mLauncher.source.spec)
                                } catch (e) {
                                    orginalString = dialog.mLauncher.suggestedFileName;
                                }
                            }
                            var location = document.querySelector("#location"), locationtext;
                            if (encodingConvert)
                                locationtext = document.createXULElement("menulist");
                            else
                                locationtext = document.createXULElement("textbox");
                            locationtext.id = "locationtext";
                            if (rename && encodingConvert)
                                locationtext.setAttribute("editable", "true");
                            locationtext.setAttribute("style", "margin-top:-2px;margin-bottom:-3px");
                            locationtext.setAttribute("tooltiptext", "Ctrl+\u70B9\u51FB\u8F6C\u6362url\u7F16\u7801\n\u5DE6\u952E\u003AUNICODE\n\u53F3\u952E\u003AGB2312");
                            location.parentNode.insertBefore(locationtext, location);
                            locationtext.addEventListener("click", function(e) {
                                if (e.ctrlKey) {
                                    if (e.button == 0)
                                        this.value = decodeURIComponent(this.value);
                                    if (e.button == 2) {
                                        e.preventDefault();
                                        converter.charset = "GB2312";
                                        this.value = converter.ConvertToUnicode(unescape(this.value));
                                    }
                                }
                            }, false);
                            if (rename)
                                locationtext.value = dialog.mLauncher.suggestedFileName;
                            if (encodingConvert) {
                                locationtext.addEventListener("command", function(e) {
                                    if (rename)
                                        locationtext.value = e.target.value;
                                    document.title = "Opening " + e.target.value;
                                });
                                let menupopup = locationtext.appendChild(document.createXULElement("menupopup"));
                                let menuitem = menupopup.appendChild(document.createXULElement("menuitem"));
                                menuitem.value = dialog.mLauncher.suggestedFileName;
                                menuitem.label = "Original: " + menuitem.value;
                                if (!rename)
                                    locationtext.value = menuitem.value;
                                let converter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
                                    .getService(Components.interfaces.nsIScriptableUnicodeConverter);
   
                                function createMenuitem(encoding) {
                                        converter.charset = encoding;
                                        let menuitem = menupopup.appendChild(document.createXULElement("menuitem"));
                                        menuitem.value = converter.ConvertToUnicode(orginalString).replace(/^"(.+)"$/, "$1");
                                        menuitem.label = encoding + ": " + menuitem.value;
                                    }
                                    ["GB18030", "BIG5", "Shift-JIS"].forEach(function(item) {
                                        createMenuitem(item)
                                    });
                            }
                        }
                    }
                    document.querySelector("#location").hidden = true;
                    document.querySelector("#locationtext").hidden = false;
                } else {
                    document.querySelector("#locationtext").hidden = true;
                    document.querySelector("#location").hidden = false;
                }
            }, false)
            if (locking)
                dialog.dialogElement("save").click();
            else
                dialog.dialogElement("save").selected && dialog.dialogElement("save").click();
            window.addEventListener("dialogaccept", function(event) {
                if ((document.querySelector("#locationtext").value != dialog.mLauncher.suggestedFileName) && dialog.dialogElement("save").selected) {
                    event.stopPropagation();
                    var mainwin = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
                    mainwin.eval("(" + mainwin.internalSave.toString().replace("let ", "").replace("var fpParams", "fileInfo.fileExt=null;fileInfo.fileName=aDefaultFileName;var fpParams") + ")")(dialog.mLauncher.source.asciiSpec, null, document.querySelector("#locationtext").value, null, null, false, null, null, null, null, Services.prefs.getBoolPref("browser.download.useDownloadDir", false), null, mainwin.PrivateBrowsingUtils.isBrowserPrivate(mainwin.gBrowser.selectedBrowser), Services.scriptSecurityManager.getSystemPrincipal());
                    document.documentElement.removeAttribute("ondialogaccept");
                }
            }, true);
        }
        //作用于 main 窗口
    function download_dialog_changeName_on_main() {
        const obsService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
        const RESPONSE_TOPIC = 'http-on-examine-response';
   
        var respObserver = {
            observing: false,
            observe: function(subject, topic, data) {
                try {
                    let channel = subject.QueryInterface(Ci.nsIHttpChannel);
                    let header = channel.contentDispositionHeader;
                    let associatedWindow = channel.notificationCallbacks
                        .getInterface(Components.interfaces.nsILoadContext)
                        .associatedWindow;
                    associatedWindow.localStorage.setItem(channel.URI.spec, header.split("=")[1]);
                } catch (ex) {};
            },
            start: function() {
                if (!this.observing) {
                    obsService.addObserver(this, RESPONSE_TOPIC, false);
                    this.observing = true;
                }
            },
            stop: function() {
                if (this.observing) {
                    obsService.removeObserver(this, RESPONSE_TOPIC, false);
                    this.observing = false;
                }
            }
        };
   
        respObserver.start();
        addEventListener("beforeunload", function() {
            respObserver.stop();
        })
    }
   
   
    // 另存为...
    function download_dialog_saveas() {
        var saveas = document.documentElement.getButton("extra1");
            saveas.setAttribute("hidden", "false");
            saveas.setAttribute("label", "\u53E6\u5B58\u4E3A");
            saveas.addEventListener("command", function() {
                var mainwin = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
                mainwin.eval("(" + mainwin.internalSave.toString().replace("let ", "").replace("var fpParams", "fileInfo.fileExt=null;fileInfo.fileName=aDefaultFileName;var fpParams") + ")")(dialog.mLauncher.source.asciiSpec, null, (document.querySelector("#locationtext") ? document.querySelector("#locationtext").value : dialog.mLauncher.suggestedFileName), null, null, false, null, null, null, null, false, null, mainwin.PrivateBrowsingUtils.isBrowserPrivate(mainwin.gBrowser.selectedBrowser), Services.scriptSecurityManager.getSystemPrincipal());
                close();
            }, false);
    }
   
    // 保存到...
    function download_dialog_saveTo() {
        //目录路径的反斜杠\要双写\\
        //第一次使用要修改路径,否则无法下载
        //如果使用Firefox3.6 + userChromeJS v1.2,则路径中的汉字要转义为\u6C49\u5B57编码类型,否则会出现乱码
        var cssStr = (function() {/*
            button[label="\4FDD\5B58\5230"] .box-inherit.button-box{
                position: relative;
            }
            button[label="\4FDD\5B58\5230"] dropmarker{
                position: absolute;
                top: 0px;
                right: 2px;
            }
        */}).toString().replace(/^.+\s|.+$/g, "");
        var shadowRoot = document.documentElement.shadowRoot;
        if(shadowRoot){
            var style = document.createElementNS('http://www.w3.org/1999/xhtml', 'html:style');
            style.textContent = cssStr;
            shadowRoot.insertBefore(style,shadowRoot.firstChild);
        }else{
            var style = document.createProcessingInstruction("xml-stylesheet", "type=\"text/css\"" + " href=\"data:text/css;base64," + btoa(cssStr) + "\"");
            document.insertBefore(style, document.firstChild);
        }
        var dir = [
            //["D:\\下载", "压缩"],
            //["D:\\软件", "软件"],
            //["D:\\文档", "文档"],
            //["D:\\音乐", "歌曲"],
            //["D:\\下载", "其他"],
        ["C:\\", "C盘"],
        ["D:\\", "D盘"],
        ["E:\\", "E盘"],
        ["F:\\", "F盘"]
        ];
        var saveTo = document.documentElement._buttons.cancel.parentNode.insertBefore(document.createXULElement("button"), document.documentElement._buttons.cancel);
        var saveToMenu = saveTo.appendChild(document.createXULElement("menupopup"));
        saveTo.classList.toggle("dialog-button");
        saveTo.label = "\u4FDD\u5B58\u5230";
        saveTo.type = "menu";
        saveTo.querySelector('.box-inherit.button-box').appendChild(document.createXULElement('dropmarker'));
        dir.forEach(function(dir) {
            var [name, dir] = [dir[1], dir[0]];
            var item = saveToMenu.appendChild(document.createXULElement("menuitem"));
            item.setAttribute("label", (name || (dir.match(/[^\\/]+$/) || [dir])[0]));
            item.setAttribute("image", "moz-icon:file:///" + dir + "\\");
            item.setAttribute("class", "menuitem-iconic");
            item.onclick = function() {
                var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
                var path = dir.replace(/^\./, Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path);
                path = path.endsWith("\\") ? path : path + "\\";
                file.initWithPath(path + (document.querySelector("#locationtext") ? document.querySelector("#locationtext").value : document.querySelector("#location").value));
                dialog.mLauncher.saveToDisk(file, 1);
                dialog.onCancel = function() {};
                close();
            };
        })
    }
   
    // 下载弹出窗口双击链接复制完整链接
    function download_dialog_showCompleteURL() {
        var s = document.querySelector("#source");
        s.value = dialog.mLauncher.source.spec;
        s.setAttribute("crop", "center");
        s.setAttribute("tooltiptext", dialog.mLauncher.source.spec);
        s.setAttribute("ondblclick", 'Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper).copyString(dialog.mLauncher.source.spec)')
    }
   
    // 下载弹出窗口双击保存文件项执行下载
    function download_dialog_doubleclicksaveL() {
        addEventListener("dblclick", function(event) {
            event.target.nodeName === "radio" && document.documentElement.getButton("accept").click()
        }, false)
    }
   
    function download_speed() {
        var appVersion = Services.appinfo.version.split(".")[0];
        if (appVersion >= 38 && DownloadsViewItem.prototype._updateProgress) {
            eval("DownloadsViewItem.prototype._updateProgress = " +
                DownloadsViewItem.prototype._updateProgress.toString().replace('status.text', 'status.tip'));
        } else if (appVersion < 38 && DownloadsViewItem.prototype._updateStatusLine) {
            eval("DownloadsViewItem.prototype._updateStatusLine = " +
                DownloadsViewItem.prototype._updateStatusLine.toString().replace('[statusTip', '[status'));
        }
    }
})();

脚本功能太复杂,有些地方可能遗漏。
新建下载功能已经没法修了,FF 已经禁止了远程 xul 的加载。
除非改用其它方式呈现界面,但本人没太多空闲时间,或者看看其他人能否帮忙解决。
etjim
火狐狸
火狐狸
  • UID30046
  • 注册日期2009-08-12
  • 最后登录2019-10-15
  • 发帖数142
  • 经验205枚
  • 威望0点
  • 贡献值46点
  • 好评度8点
  • 忠实会员
  • 社区居民
48楼#
发布于:2019-07-02 17:52
lonely_8:// ==UserScript==
// @name           downloadPlus.uc.js
// @description    从硬盘中删除+下载重命名并可转码+双击复制链接+另存为+保存并打开+完成下载提示音+自...
回到原帖
谢谢大大的帮助,新建下载功能基本上用不上,其他亲测有效
linee
小狐狸
小狐狸
  • UID5884
  • 注册日期2005-05-11
  • 最后登录2019-09-24
  • 发帖数89
  • 经验27枚
  • 威望0点
  • 贡献值8点
  • 好评度0点
  • 社区居民
  • 忠实会员
49楼#
发布于:2019-07-11 21:13
这个按照顶楼改了, 基本能用了, 只是有点小毛病, 菜单往左偏了点距离, 请帮忙改下, 十分感谢.
// ==UserScript==
// @label                  CustomFirefoxMenu.uc.js
// @description       火狐選單
// @author               skofkyo
// @license               MIT License
// @compatibility    Firefox 45+
// @charset              UTF-8
// @version              2016.7.29
// @include              main
// @note                   2016.7.30 部分元素使用複製 調整代碼
// @note                   2016.7.17 V2修正CSS新視窗移動按鈕沒有圖示的問題
// @note                   2016.7.17 修正PanelUI按鈕右鍵選單 新視窗無效的問題
// @note                   2016.7.16 重寫代碼 使用新函數
// @homepageURL    https://github.com/skofkyo/userChromeJS/blob/master/userButton/00-FirefoxBtnMod.uc.js
// ==/UserScript==
(function() {
 
    var mode = 0;//位置 0可移動按鈕 1頁面右鍵選單 2僅PanelUI按鈕右鍵選單
    var PUb = true;// true/false 移動按鈕模式時是否同時添加PanelUI按鈕右鍵選單
 
    var CustomFirefoxMenu = {
         
        startup: function() {
            if (PUb && mode !== 1 && mode !== 2 || mode == 2) this.addPUContextMenu();
        },
         
        init: function() {
            this.addmenuitem();
            if (mode == 0) {this.addmenumovebtn();} else if (mode == 1) {this.addContextMenu();}
            this.addstyle();
        },
 
        addmenumovebtn: function() {
            CustomizableUI.createWidget({
                id: 'CustomFirefoxMenu',
                type: 'custom',
                defaultArea: CustomizableUI.AREA_NAVBAR,
                onBuild: function(aDocument) {
                    var tb = aDocument.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
                    var props = {
                        id: 'CustomFirefoxMenu',
                        class: 'toolbarbutton-1 chromeclass-toolbar-additional',
                        removable: 'true',
                        overflows: "false",
                        label: '火狐選單',
                        tooltiptext: "火狐選單",
                        type: 'menu',
                        popup: "CustomFirefoxMenuPopup"
                    };
                    for (var p in props)
                        tb.setAttribute(p, props[p]);
                    return tb;
                }
            });
        },
 
        addContextMenu: function() {
            var ins = $("contentAreaContextMenu").firstChild;
            ins.parentNode.insertBefore($C("menu", {
                id: "CustomFirefoxMenu",
                class: "menu-iconic",
                label: "火狐選單",
                image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABuElEQVQ4jZ2Tz0sUYRjH908IB6XbZpQdBL106NBF/4BtMy/doluw669g/YUkaCTYJXYtIsiDEHjYi4gQBFG3DmJ0Si/lKJsz78zOrDNus7w78/Egzjq9XtoH3svL83ye7/fheVKVvDZkjGqmOdbJ/zxjpENUclo21U5xDBnVzNS/n2LyGu6bYZzSfZxiBqeUpfb+EU7x3qWQGGA/v8Px+lPc1w8QMz04K0OtxPEu/I155OEPnFIWc+KqCvDK00SBR/Nol9Cz1I7jXXjlKaLAp7b2RAX8/faBi9E09jj59EqRHGyXkfr3JEAU0kQySACkvoM1e0sBNHa/EMkGYuZmC2DN9ye7W79x3z5Uiq3ZHuT+NgDV5cEWwF64nQCEvo1TzFBdHuB4fQJRSGOOdVJbfQxRCIA115ucQdPWUSKU1L++w3rWhyikqX9eiRUqQ/S3XiRr3Upsw5rrPfNedwHwt5ZUgCikaYpfioioUY9lA4TOIWLqugo4X6aweqBaOR+urWMv3b18E2Ml0zc4+fgS+ecnkQyIAg+p7+BvLiImu9VVNkY6RNvHlNeMVCWnZds657xmHOWuZE4BnUvgBJzQjdgAAAAASUVORK5CYII=",
            }), ins);
            var m = $('CustomFirefoxMenu');
            var mp = $('CustomFirefoxMenuPopup');
            mp.removeAttribute("position");
            m.appendChild(mp);
        },
 
        addmenuitem: function() {
            var mp = $C("menupopup", {
                id: "CustomFirefoxMenuPopup",
                position: "after_start",
            });
            $('mainPopupSet').appendChild(mp);
             
            var menues = [
            {moveid: "file-menu"}, 
            {moveid: "edit-menu"}, 
            {moveid: "view-menu"}, 
            {moveid: "history-menu"}, 
            {moveid: "bookmarksMenu"}, 
            {moveid: "tools-menu"}, 
            {moveid: "helpMenu"}, 
            {label: "sep"}, 
            {moveid: "menu_preferences",clone: true}, 
            {moveid: "fullScreenItem",clone: true}, 
            {moveid: "charsetMenu"}, 
            {moveid: "menu_openDownloads",clone: true}, 
            {moveid: "menu_openAddons",clone: true}, 
            {moveid: "webDeveloperMenu"}, 
            {
                label: "錯誤主控台",
                tooltiptext: "錯誤主控台",
                oncommand: "toJavaScriptConsole();",
                image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA2ElEQVQ4jY2SURGDMBBEIwEJSHm7CpCAhEqoAyRUAhIqIRKQgAT60WMmTRPam8kMOXIve3tJqQhgsH0HqPJEfkhXISnbPjqAQ1LuFgOj7SMOPs/vev+Xgt66VFCraK2mB5I2SRswA2Mtv2wDGIDJ9ippL299SNolbbYXYOIzJttL/D9sr7XR5wi78os2xl7/NA7PjRw9wNfhlFJqAKa68Fb09hNQGPoG2V7DuK8RdhTwMYVqpPkK8Osp/+vB3C0OP3ILICkDtyYkPJgDNoQvJWA9n3Fctpy1LyNPBAjW0Ns9AAAAAElFTkSuQmCC"
            }, 
            {label: "sep"}, 
            {moveid: "aboutName",clone: true}, 
            {
                label: "重新啟動瀏覽器",
                tooltiptext: "重新啟動瀏覽器",
                oncommand: "Services.appinfo.invalidateCachesOnRestart() || ('BrowserUtils' in window) ? BrowserUtils.restartApplication(): Application.restart();",
                image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABgklEQVQ4jX1Su0pDQRC9hVjEVysBX8FCiKTZIsgumznnH2wikUQR9EsEwVrBwkrBXoPGSvATJIrxFcR8gkVAr81svIk3LizsnnmdOTNRNOSUSqUVknG4AA6H+fYdEVkDcEKyrYF7JL/0fSEii6mBJOdI1pNVScZq8wDeNMmniCz3BXvvZ0g+a1BbRLadc7P5fH40+BSLxUmSx5qkKyJLyep1NVxaayf+a5HkkRba6vWswa/GmCnFqgBaoQXFRgDsA/gmGfcYADhVYFsrVAY1EJFpADcJ/KBHCcA7ydh7P6P/B2V0q4kdyQ/F7kgeACgnE3RJxkGwMDIR2Q2CDU5G8fIwBvfqtJMQLAbwQnJV8d82ggZB1SBqyq0ow5r+j0OCda3wZIzJKFYm2dR2moGuMSZD8lH9N5I6XCVWdTxt/oVCYQzAufpd9xmdc7nEqrZEZNNam42iKLLWZknWwl6QbDvncn8qiMg8ycaQ/sNteO8X0nf0N1EVwBmAjjLq6H8jzf8HTUH5xYEpCK8AAAAASUVORK5CYII="
            }, 
            {moveid: "menu_FileQuitItem",clone: true}
            ];
 
            var i, item, menue, mid;
            for (i = 0; i &lt; menues.length; i++) {
                menue = menues[i];
                mid = menue.moveid;
                if (mid) {
                    if (mid != null && menue.clone) {
                        mp.appendChild($(menue.moveid).cloneNode(true));
                    } else if (mid != null) {
                        mp.appendChild($(menue.moveid));
                    }
                } else if (menue.label == "sep") {
                    item = $C("menuseparator");
                    mp.appendChild(item);
                } else {
                    item = $C('menuitem', {
                        label: menue.label,
                        class: "menuitem-iconic",
                        tooltiptext: menue.tooltiptext,
                        oncommand: menue.oncommand,
                        image: menue.image,
                    });
                    mp.appendChild(item);
                }
            }
 
        },
         
        addstyle: function() {
            //移動按鈕的樣式
            var cssStr = '@-moz-document url("chrome://browser/content/browser.xul"), url("chrome://browser/content/browser.xhtml"){' 
            + '#CustomFirefoxMenu .toolbarbutton-icon' 
            + '{list-style-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADmElEQVRYhcWX308cVRTH5w/Ap91F0BLjkxIfTPR19cHaqLEo0QeMDya2D41EdhZKq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GHaIRfj8H+OsMchUQztnNxDgPG9/Dnl19976ImtP+Q6ZzDscUi7kfawxzH+j/hf6BR628uPQMQAAAAASUVORK5CYII=)}' 
            + '}';
            var sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
            var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
            sss.loadAndRegisterSheet(ios.newURI("data:text/css;base64," + btoa(cssStr), null, null), sss.USER_SHEET);
        },
         
        addPUContextMenu: function(event) {
            var pb = $("PanelUI-button")
            pb.addEventListener("contextmenu", function(event) {
                $("CustomFirefoxMenuPopup").openPopup(this, "after_pointer", 0, true, false);
                event.preventDefault();
            }, false);
        },
 
    };
 
    CustomFirefoxMenu.startup();
    CustomFirefoxMenu.init();
    window.CustomFirefoxMenu = CustomFirefoxMenu;
 
    function $(id) { return document.getElementById(id);}
 
    function $C(name, attr) {
        var el = document.createXULElement(name);
        if (attr) Object.keys(attr).forEach(function(n) { return el.setAttribute(n, attr[n]);});
        return el;
    }
 
}());
lonely_8
狐狸大王
狐狸大王
  • UID30273
  • 注册日期2009-09-03
  • 最后登录2019-10-15
  • 发帖数485
  • 经验247枚
  • 威望0点
  • 贡献值72点
  • 好评度75点
  • 社区居民
  • 忠实会员
50楼#
发布于:2019-07-11 21:45
linee:这个按照顶楼改了, 基本能用了, 只是有点小毛病, 菜单往左偏了点距离, 请帮忙改下, 十分感谢.
// ==UserScript==
// @label                  CustomFirefoxMenu.uc.js...
回到原帖
118行改为
const menu = $(menue.moveid);
mp.appendChild(menu);
if(menu.render && menu.firstElementChild.classList.contains('menubar-text')){
    menu.firstElementChild.remove();
    menu.renderedOnce = false;
    menu.render();
}
linee
小狐狸
小狐狸
  • UID5884
  • 注册日期2005-05-11
  • 最后登录2019-09-24
  • 发帖数89
  • 经验27枚
  • 威望0点
  • 贡献值8点
  • 好评度0点
  • 社区居民
  • 忠实会员
51楼#
发布于:2019-07-11 22:47
lonely_8:118行改为
const menu = $(menue.moveid);
mp.appendChild(menu);
if(menu.render && menu.firstElementChild.classList.contain...
回到原帖
谢谢大大, 这下完美了.
cooling
小狐狸
小狐狸
  • UID36051
  • 注册日期2011-04-20
  • 最后登录2019-10-14
  • 发帖数11
  • 经验42枚
  • 威望0点
  • 贡献值8点
  • 好评度0点
  • 社区居民
52楼#
发布于:2019-07-19 10:25



楼主热心,能否帮忙修改一下autoPopup++.uc.js或AutoPopup.uc.js?69下也是失效了,非常感谢!
// ==UserScript==
// @name           autoPopup++
// @description    可定制化的自动弹出/关闭菜单/面板
// @description:en Auto popup/close menu/panel
// @updateURL      https://raw.githubusercontent.com/xinggsf/uc/master/autoPopup.uc.js
// 配置文件        https://raw.githubusercontent.com/xinggsf/uc/master/_autoPopup.js
// @homepageURL    http://bbs.kafan.cn/thread-1866855-1-1.html
// @include        chrome://browser/content/browser.xhtml
// @compatibility  Firefox 45+
// @startup        onAutoPopup.startup();
// @shutdown       onAutoPopup.shutdown();
// @author         xinggsf
// @version        2017.6.29
// @note  修改Profiles\chrome\Local\_autoPopup.js配置文件可实现定制化
// ==/UserScript==
-function() {
function clone(src){//浅克隆
    if (!src) return;
    let r = src.constructor === Object ?
        new src.constructor() :
        new src.constructor(src.valueOf());
    for (let key in src){
        if ( r[key] !== src[key] ){
            r[key] = src[key];
        }
    }
    r.toString = src.toString;
    r.valueOf = src.valueOf;
    return r;
}
 
const $ = id =&gt; document.getElementById(id),
idWidgetPanel = 'customizationui-widget-panel',
 
ppmPos = ['after_start','end_before','before_start','start_before'];
function getPopupPos(elt) {
    let box, w, h, b = !1,
    x = elt.boxObject.screenX,
    y = elt.boxObject.screenY;
 
    while (elt = elt.parentNode.closest('toolbar,hbox,vbox')) {
        h = elt.boxObject.height;
        w = elt.boxObject.width;
        if (h &gt;= 45 && h &gt;= 3 * w) {
            b = !0;
            break;
        }
        if (w &gt;= 45 && w &gt;= 3 * h) break;
    }
    if (!elt) return ppmPos[0];
    box = elt.boxObject;
    x = b ? (x &lt;= w / 2 + box.screenX ? 1 : 3) :
            (y &lt;= h / 2 + box.screenY ? 0 : 2);
    return ppmPos[x];
}
 
let nDelay, blackIDs, whiteIDs;
function loadUserSet() {
    let aFile = FileUtils.getFile("UChrm", ["local", "_autoPopup.js"], false);
    if (!aFile.exists() || !aFile.isFile()) return;
    let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
    let sstream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
    fstream.init(aFile, -1, 0, 0);
    sstream.init(fstream);
    let data = sstream.read(sstream.available());
    try {
        data = decodeURIComponent(escape(data));
    } catch (e) {}
    sstream.close();
    fstream.close();
    if (data) return eval(data);
    /*
    let sandbox = new Cu.Sandbox(new XPCNativeWrapper(window));
    try {
        Cu.evalInSandbox(data, sandbox, 'latest');
    } catch (e) {
        return;
    }
 
    {nDelay, blackIDs, whiteIDs} = sandbox; */
}
 
class MenuAct {//菜单动作基类
    constructor(btnCSS = '', menuId = '') {
        this.btnCSS = btnCSS;
        this.menuId = menuId;
    }
    isButton(e) {
        this._ppm = 0;
        this.btn = e;
        return this.btnCSS ? e.matches(this.btnCSS) : this._isButton(e);
    }
    getPopupMenu(e) {
        if (this.menuId) return $(this.menuId);
        let s = e.getAttribute('context') || e.getAttribute('popup');
        return (s && $(s)) || e.querySelector('menupopup');
        //let c = e.ownerDocument.getAnonymousNodes(e);
    }
    get ppm() {
        let m = this._ppm || this.getPopupMenu(this.btn);
        if (m) {
            let frm = m.querySelector('iframe[src][type=content]');
            if (frm) this.frameURI = frm.getAttribute('src');
            this._ppm = m;
        }
        return m;
    }
    open(){
        let m = this.ppm;
        //console.log(m);
        if (m) {
            if (m.openPopup)
                m.openPopup(this.btn, getPopupPos(this.btn));
            else if (m.showPopup)
                m.showPopup();
            else if (m.popupBoxObject)
                m.popupBoxObject.showPopup();
        }
        else this.btn.click();
    }
    close(){
        if (idWidgetPanel === this.menuid)
            gURLBar.click();
        else if (this.ppm) {
            if (this.ppm.hidePopup)
                this.ppm.hidePopup();
            else if (this.ppm.popupBoxObject)
                this.ppm.popupBoxObject.hidePopup();
            else if (this.btn.closePopup)
                this.btn.closePopup();
        }
    }
}
let menuActContainer = [
    new class extends MenuAct{//处理白名单
        _isButton(e) {
            if (!e.hasAttribute('id')) return !1;
            let id = e.id;
            this.item = whiteIDs.find(k =&gt; k.id === id);
            return !!this.item;
        }
        getPopupMenu(e) {
            let id = this.item.popMenu;
            return (id && $(id)) || super.getPopupMenu(e);
        }
        open() {
            let fn = this.item.open;
            fn ? fn(this.btn) : super.open();
        }
        close() {
            let fn = this.item.close;
            fn ? fn(this.ppm) : super.close();
        }
    }(),
    new class extends MenuAct{//处理黑名单
        _isButton(e) {
            return blackIDs.some(css =&gt; e.mozMatchesSelector(css));
        }
        open() {}
    }(),
    new class extends MenuAct{
        getPopupMenu(e) {
            return this.btn;
        }
        close() {
            this.btn.open = !1;
        }
        open() {
            this.btn.open = !0;
        }
    }('menulist'),
    new class extends MenuAct{
        close() {
            this.ppm.parentNode.closePopup();
        }
    }('dropmarker'),
    new MenuAct('[widget-id][widget-type]',idWidgetPanel),
    //omnibar中的搜索引擎图标 btn =&gt; $('omnibar-in-urlbar').click()
    new MenuAct('#omnibar-defaultEngine','omnibar-engine-menu'),
    new class extends MenuAct{//原始搜索按钮
        close() {
            BrowserSearch.searchBar.textbox.closePopup();
        }
        open() {
            BrowserSearch.searchBar.openSuggestionsPanel();
        }
    }('[anonid=searchbar-search-button]','PopupSearchAutoComplete'),
    //new MenuAct('toolbarbutton[role=button][type=menu]'),
    //new MenuAct('#bookmarks-menu-button &gt; toolbarbutton', 'BMB_bookmarksPopup'),
    new class extends MenuAct{
        _isButton(e) {
            return e.matches('toolbarbutton') && e.parentNode
                .matches('toolbarbutton') && this.ppm;
        }
        getPopupMenu(e) {
            return super.getPopupMenu(e.parentNode);
        }
    }(),
    new class extends MenuAct{
        _isButton(e) {
            return /toolbarbutton|button/.test(e.localName) && this.ppm;
        }
    }(),
    new class extends MenuAct{
        _isButton(e) {
            return e.closest('toolbar') && this.ppm &&
            ('image' === e.nodeName || e.matches('[src^="data:image"]'));
        }
    }(),
];
let btnManager, ppmManager, _inMenu;
class AutoPop {
    constructor() {
        this.timer = 0;
        this.act = null;//MenuAct
    }
    clearTimer() {
        if (this.timer) {
            clearTimeout(this.timer);
            this.timer = 0;
        }
    }
    clean() {
        if (!this.act) return;
        this.clearTimer();
        this.act = null;
    }
    inMenu(e) {
        let a = ppmManager.act;
        if (!a || !a.ppm) return !1;
        if (e.nodeName === 'menuitem' || e === a.btn || a.frameURI === e.baseURI ||
            a.ppm.contains(e) || e.closest('vbox.panel-arrowcontainer,menupopup,popupset'))
            return !0;
        if (a.ppm.id !== idWidgetPanel) return !1;
        //console.log(e, e.ownerDocument, e.ownerDocument.location.href);
        // if (e.ownerDocument === document && e.matches('iframe[src][type=content]'))
            // a.frameURI = e.getAttribute('src');
        // return e.closest('[panelopen=true]');
        if (e.closest('[panelopen=true]')) return !0;
        // chrome://*.html仍然是旧式的扩展,文档类型为XULDocument
        return /^(moz-extension|chrome):\/\/.+\.html?$/i.test(e.ownerDocument.location.href);//e.ownerDocument instanceof HTMLDocument &&
    }
}
btnManager = new class extends AutoPop {
    setTimer() {
        this.timer = setTimeout(() =&gt; {
            this.act.open();
            ppmManager.clean();
            ppmManager.act = clone(this.act);
            this.clean();
        }, nDelay +9);
    }
    mouseOver(e) {
        this.clean();
        _inMenu = this.inMenu(e);
        if (_inMenu || e.disabled)
            return;
        for (let k of menuActContainer) {
            if (k.isButton(e)) {
                this.act = k;
                this.setTimer();
                break;
            }
        }
    }
}();
ppmManager = new class extends AutoPop {
    clean() {
        if (this.act) {
            this.act.close();
            super.clean();
        }
    }
    setTimer() {
        if (!this.timer) this.timer = setTimeout(() =&gt; {
            this.clean();
        }, nDelay);
    }
    mouseOver(e) {
        if (_inMenu) {
            this.clearTimer();
            return;
        }
        if (this.act) this.setTimer();
    }
}();
 
if (window.onAutoPopup) {
    window.onAutoPopup.shutdown();
    delete window.onAutoPopup;
}
let prevElt;
window.onAutoPopup = {//事件处理“类”
    startup() {
        prevElt = null;
        loadUserSet();
        let btnOmni = $('omnibar-defaultEngine');
        if (!BrowserSearch.searchBar || btnOmni)
            menuActContainer.splice(6, 1);
        if (!btnOmni)
            menuActContainer.splice(5, 1);
 
        window.addEventListener('mouseover', this.mouseOver, !1);
        window.addEventListener("unload", this.shutdown);
    },
    shutdown: ev =&gt; window.removeEventListener('mouseover', this.mouseOver),
    mouseOver(ev) {
        if (!document.hasFocus()) {
            ppmManager.clean();
            return;
        }
        let e = ev.originalTarget;
        if (e === prevElt) return;
        prevElt = e;
        btnManager.mouseOver(e);
        ppmManager.mouseOver(e);
    }
}
onAutoPopup.startup();
 
}();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
     
// ==UserScript==
// @name           AutoPopup.uc.js
// @description    Auto popup menulist/menupopup
// @compatibility  Firefox 30.0+
// @author         GOLF-AT, modify by gsf
// @version        2015.1.30
// ==UserScript==
   
(function () {
    var nDelay = 300;
    var overElt = null;
    var PopElt = null;
    var PopTimer = null;
    var HideTimer = null;
    var searchBar = null;
    var AlwaysPop = false;
   
    //by gsf,支持Fx的CSS所有语法: #表示id,. 表示class,或[id='demo']
    var BlackIDs = [];
   
    //by gsf, 白名单,及触发动作
    var whiteIDs = [{
        id: 'omnibar-defaultEngine',
        popMemu: 'omnibar-engine-menu',
        run: function(overElem){
            document.getElementById('omnibar-in-urlbar').click(0);
        }
    },
    {
        id: 'readLater',
        popMemu: 'readLater-popup',
        run: null
        //function(overElem){ PopElt.popup();}
    },
    {
        id: 'foxyproxy-toolbar-icon',
        popMemu: 'foxyproxy-toolbarbutton-popup',
        run: null
    }];
    var whitesInx = -1;
   
    var popupPos = ['after_start', 'end_before', 'before_start', 'start_before'];
   
    var menuPanelID = 'PanelUI-popup';
    var downPanelID = 'downloadsPanel';
    var widgetPanelID = 'customizationui-widget-panel';
   
    function IsWidgetBtn(elt) {
        try {
            return elt.hasAttribute('widget-id')
                && elt.getAttribute('widget-type') == 'view';
        } catch (e) {
            return false;
        }
    }
   
    function IsSearchBtn(elt) {
        try {
            return elt.getAttribute("anonid") == 'searchbar-search-button'
            || whitesInx === 0;
        } catch (e) {
            return false;
        }
    }
   
    function IsNewMenuBtn(elt) {
        try {
            return elt.id == 'PanelUI-menu-button';
        } catch (e) {
            return false;
        }
    }
   
    function IsDownloadBtn(elt) {
        try {
            return elt.localName == 'toolbarbutton'
            && elt.id == 'downloads-button';
        } catch (e) {
            return false;
        }
    }
   
    function IsAutoComplete(elt) {
        try {
            return elt.getAttribute('type').substr(0, 12) == 'autocomplete';
        } catch (e) {
            return false;
        }
    }
   
    function getPopupMenu(elt) {
        if (whitesInx &gt; -1 && PopElt)
            return PopElt;
        var nodes = elt ? elt.ownerDocument.getAnonymousNodes(elt) : null;
        for (let [i, k] in Iterator(nodes)) {
            if (k.localName == 'menupopup')
                return k;
        }
   
        var s = elt.getAttribute('popup');
        return s ? document.getElementById(s) : null;
    }
   
    function isBlackNode(elt) {
        return BlackIDs.some(function(css) {
            return css.length &gt; 0 && document.querySelector(css);
        });
    }
   
    function getPopupPos(elt) {
        var x, y, pos, box;
   
        for (pos = 0, x = elt.boxObject.screenX, y = elt
            .boxObject.screenY; elt != null; elt = elt.parentNode)
        {
            if (elt.localName == 'window' || !elt.parentNode)
                break;
            else if ('toolbar' != elt.localName &&
                'hbox' != elt.localName && 'vbox' != elt.localName);
            else if (elt.boxObject.height &gt;= 3 * elt.boxObject.width) {
                if (elt.boxObject.height &gt;= 45) {
                    pos = 9;
                    break;
                }
            } else if (elt.boxObject.width &gt;= 3 * elt.boxObject.height) {
                if (elt.boxObject.width &gt;= 45) {
                    pos = 8;
                    break;
                }
            }
        }
        try {
            box = elt.boxObject;
            x = (pos & 1) ? (x &lt;= box.width / 2 + box.screenX ? 1 : 3) :
                            (y &lt;= box.height / 2 + box.screenY ? 0 : 2);
        } catch (e) {
            x = 0;
        }
        return popupPos[x];    
    }
   
    function getPopupNode(node) {
        if (whitesInx &gt; -1 && PopElt)
            return PopElt;
        var elt, isPop, s;
   
        for (; node != null; node = node.parentNode) {
            if (node == PopElt)
                return node;
   
            isPop = false; //Node isn't Popup node
            s = node.localName;
            if (s == 'menupopup' || s == 'popup' || s == 'menulist'
               || IsAutoComplete(node) || IsMenuButton(node))
                isPop = true;
            else if (s == 'dropmarker') {
                if (node.getAttribute('type') == 'menu') {
                    elt = node.parentNode;
                    if (elt.firstChild.localName == 'menupopup')
                        isPop = true;
                } else if (node.className == 'autocomplete-history-dropmarker')
                    isPop = true;
                else {
                    try {
                        isPop = node.parentNode.id == 'urlbar';
                    } catch (ex) {}
                }
            } else if (s == 'menu')
                isPop = 'menubar' == node.parentNode.localName;
            else if (IsButton(node)) {
                for (elt = node; (elt = elt.nextSibling) != null;) {
                    if (elt.localName == 'dropmarker' &&
                        elt.boxObject.width &gt; 0 &&
                        elt.boxObject.height &gt; 0)
                        break;
                }
                if (elt) break;
            }
            if (isPop) break;
        }
        if (PopElt && node) {
            //Whether node is child of PopElt
            for (elt = node.parentNode; elt != null; elt = elt.parentNode) {
                if (elt == PopElt)
                    return PopElt;
            }
        }
        return isPop ? node : null;
    }
   
    function AutoPopup() {
        PopTimer = null;
        if (!overElt) return;
          
        if (whitesInx &gt; -1 && PopElt && whiteIDs[whitesInx].run) {
            whiteIDs[whitesInx].run(overElt);
            return;
        }
        !PopElt && (PopElt = overElt);
   
        if (overElt.localName == 'dropmarker')
            PopElt.showPopup();
        else if (overElt.localName == 'menulist')
            overElt.open = true;
        else if (IsNewMenuBtn(overElt)) {
            PanelUI.show();
            PopElt = document.getElementById(menuPanelID);
        } else if (IsWidgetBtn(overElt)) {
            var cmdEvent = document.createEvent('xulcommandevent');
            cmdEvent.initCommandEvent("command", true, true, window, 0, false,
                false, false, false, null);
            overElt.dispatchEvent(cmdEvent);
            PopElt = document.getElementById(widgetPanelID);
        } else if (IsDownloadBtn(overElt)) {
            PopElt = document.getElementById(downPanelID);
            DownloadsPanel.showPanel();
        } else if (IsSearchBtn(overElt)) {
            searchBar.openSuggestionsPanel();
            //console.log('search click!');
        } else {
            PopElt = getPopupMenu(overElt);
            try {
                var Pos = getPopupPos(overElt);
                PopElt.openPopup(overElt, Pos, 0, 0, false, false, null);
            } catch (e) {
                PopElt = null;
            }
        }
    }
   
    function HidePopup() {
        try {
            if (overElt.localName == 'dropmarker')
                PopElt.parentNode.closePopup();
            else if (overElt.localName == 'menulist')
                PopElt.open = false;
            else if (IsDownloadBtn(overElt))
                DownloadsPanel.hidePanel();
            //else if (IsNewMenuBtn(overElt) || IsWidgetBtn(overElt))
            else if (PopElt && PopElt.hidePopup)
                PopElt.hidePopup();
            else if (PopElt.popupBoxObject)
                PopElt.popupBoxObject.hidePopup();
             else if (IsSearchBtn(overElt))
                 searchBar.textbox.closePopup();           
        } catch (e) {}
   
        HideTimer = null;
        overElt = PopElt = null;
    }
   
    function MouseOver(e) {
        if (!AlwaysPop && !document.hasFocus())
            return;
        var popNode, n = e.originalTarget;
   
        whitesInx = -1;
        //gsf:some,forEach,filter等数组遍历方法接受第二个参数,表作用域this,可不用call了
        if (n.hasAttribute('id') && whiteIDs.some(function(k,i,me){
            //for (let [i, k] in Iterator(whiteIDs)) {
            if (k.id == n.id) {
                overElt = n;
                whitesInx = i;
                PopElt = document.getElementById(k.popMemu);
                PopTimer = setTimeout(AutoPopup, nDelay);
                return true;
            }
        })) return;
          
        popNode = getPopupNode(e.originalTarget);
        if (!popNode || (popNode && popNode.disabled) || isBlackNode(popNode)) {
            MouseOut();
            return;
        }
   
        if (HideTimer) {
            window.clearTimeout(HideTimer);
            HideTimer = null;
        }
        try {
            if (IsAutoComplete(popNode)) return;
   
            for (var elt = popNode; elt != null; elt = elt.parentNode) {
                if (elt.localName == 'menupopup' ||
                    elt.localName == 'popup')
                    return;
            }
        }
        catch (ex) {}
   
        if (PopElt && popNode == PopElt && PopElt != overElt)
            return;
        if (overElt && popNode != overElt)
            HidePopup();
        overElt = popNode;
        PopElt = null;
        PopTimer = setTimeout(AutoPopup, nDelay);
    }
   
    function MouseOut(e) {
        if (PopTimer) {
            window.clearTimeout(PopTimer);
            PopTimer = null;
        }
        if (!HideTimer && PopElt)
            HideTimer = window.setTimeout(HidePopup, 500);
    }
   
    function IsButton(elt) {
        try {
            return elt.localName == 'button' ||
            elt.localName == 'toolbarbutton';
        } catch (e) {
            return false;
        }
    }
   
    function IsMenuButton(elt) {
        return IsNewMenuBtn(elt) || IsDownloadBtn(elt) || IsWidgetBtn(elt)
            || (IsButton(elt) && getPopupMenu(elt));
    }
   
    searchBar = BrowserSearch.searchBar;
    window.addEventListener('mouseover', MouseOver, false);
})();
喜欢firefox,不喜欢chrome
lonely_8
狐狸大王
狐狸大王
  • UID30273
  • 注册日期2009-09-03
  • 最后登录2019-10-15
  • 发帖数485
  • 经验247枚
  • 威望0点
  • 贡献值72点
  • 好评度75点
  • 社区居民
  • 忠实会员
53楼#
发布于:2019-07-19 13:41
cooling:楼主热心,能否帮忙修改一下autoPopup++.uc.js或AutoPopup.uc.js?69下也是失效了,非常感谢!
// ==UserScript==
// @name           autoPopup++
// @de...
回到原帖
两个脚本都将所有的
.boxObject
删掉,注意包括前面的英文句号。


脚本2:


var nodes = elt ? elt.ownerDocument.getAnonymousNodes(elt) : null;
for (let [i, k] in Iterator(nodes)) {
    if (k.localName == 'menupopup')
        return k;
}
替换为

var node = elt ? elt.querySelector('menupopup') : null;
if(node) return node;
crisco
小狐狸
小狐狸
  • UID57196
  • 注册日期2019-07-17
  • 最后登录2019-10-15
  • 发帖数5
  • 经验18枚
  • 威望0点
  • 贡献值8点
  • 好评度0点
  • 社区居民
54楼#
发布于:2019-07-19 15:33
升级到68后,通过AnotherButton自定义的按钮的菜单项,设置了 clone: false,属性 的就显示错位,而且没有后面表示有子菜单的箭头。求楼主给看看,谢谢!

图片:Screenshot_20190719152931.png





脚本及配置文件:AnotherButton.zip
Firefox...
cooling
小狐狸
小狐狸
  • UID36051
  • 注册日期2011-04-20
  • 最后登录2019-10-14
  • 发帖数11
  • 经验42枚
  • 威望0点
  • 贡献值8点
  • 好评度0点
  • 社区居民
55楼#
发布于:2019-07-19 17:22
lonely_8:两个脚本都将所有的
.boxObject
删掉,注意包括前面的英文句号。


脚本2:


var nodes = elt ? elt.ownerDocument.getAnonymousNodes(elt) : null...
回到原帖
脚本1搞定了,谢谢层主!
喜欢firefox,不喜欢chrome
lonely_8
狐狸大王
狐狸大王
  • UID30273
  • 注册日期2009-09-03
  • 最后登录2019-10-15
  • 发帖数485
  • 经验247枚
  • 威望0点
  • 贡献值72点
  • 好评度75点
  • 社区居民
  • 忠实会员
56楼#
发布于:2019-07-19 19:23
crisco:升级到68后,通过AnotherButton自定义的按钮的菜单项,设置了 clone: false,属性 的就显示错位,而且没有后面表示有子菜单的箭头。求楼主给看看,谢谢!




脚本及配置文件:
回到原帖
修改“自定义按钮.uc.js”
1、732 行改为
const menuitem = this.CreateMenuitem(obj);
this.Popup.appendChild(menuitem);
if(menuitem.render){
    for(const child of menuitem.childNodes){
        if(child.localName !== 'menupopup')
            child.remove();
    }
    menuitem.renderedOnce = false;
    menuitem.render();
}
2、删掉 100 到 102 行。
crisco
小狐狸
小狐狸
  • UID57196
  • 注册日期2019-07-17
  • 最后登录2019-10-15
  • 发帖数5
  • 经验18枚
  • 威望0点
  • 贡献值8点
  • 好评度0点
  • 社区居民
57楼#
发布于:2019-07-22 08:28
lonely_8:修改“自定义按钮.uc.js”
1、732 行改为
const menuitem = this.CreateMenuitem(obj);
this.Popup.appendChild(menuitem);
if(menuitem.r...
回到原帖
可以了,非常感谢!
Firefox...
jiayiming
火狐狸
火狐狸
  • UID35865
  • 注册日期2011-04-04
  • 最后登录2019-10-14
  • 发帖数138
  • 经验138枚
  • 威望0点
  • 贡献值14点
  • 好评度2点
  • 社区居民
  • 忠实会员
58楼#
发布于:2019-08-03 02:46
69b10又要改toolkit.legacyUserProfileCustomizations.stylesheets了。。
333ywb
小狐狸
小狐狸
  • UID27284
  • 注册日期2008-12-03
  • 最后登录2019-10-15
  • 发帖数93
  • 经验102枚
  • 威望0点
  • 贡献值100点
  • 好评度0点
  • 社区居民
  • 忠实会员
59楼#
发布于:2019-08-12 17:01
70.0a1的失效问题已经按照方法解决了,谢谢
游客

返回顶部