333ywb
小狐狸
小狐狸
  • UID27284
  • 注册日期2008-12-03
  • 最后登录2018-12-14
  • 发帖数25
  • 经验44枚
  • 威望0点
  • 贡献值38点
  • 好评度0点
  • 社区居民
  • 忠实会员
阅读:190回复:2

【求助】UndoCloseTabBtn.uc脚本在65Nightly下不能运行,请大家帮忙,谢谢

楼主#
更多 发布于:2018-12-04 11:10
// ==UserScript==
// @Name                 UndoCloseTabBtn.uc.js
// @namespace         UndoCloseTab@gmail.com
// @description         可移动恢复已关闭标签按钮
// @author               defpt
// @charset              UTF-8
// @Compatibility        FF57+
// @version              v2018.04.04 更新兼容57+ by runningcheese
// @version              v2014.09.15
// ==/UserScript==
(function() {
        var buttonAttrs = {
                id: "undoclosetab-button",
                label: "恢复最后关闭的标签",
                tooltiptext: "左键:恢复最后关闭的标签\n右键:显示关闭标签菜单",
                class: "toolbarbutton-1 chromeclass-toolbar-additional",
                removable: "true",
                context: "_child", //点击按钮恢复最后一次关闭的标签
                                   //如果想左键恢复最后一次关闭的标签,右键打开已关闭标签列表,那么改为(context: "_child",)
                                   //如果想改成菜单形式的,那么改为(type: "menu-button",)
                image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABuUlEQVRIib2VL08DQRDFKxANqahErijJte/N5pI2oQlNuA+AqEBUkHAJAkMIAhJERYNBICr4ABUIFKlEIBA4DAJRgUBUIJpgKioqitkry8H9CxcmmeQutzu/eTO5mULhP4xkA0Ar6ruIOCR3SZ4A6JrnRhaAR3JqQ5RSRQDHJMckFxE+JtlzXbccCwDQMRemAFpaa5J8jQkc9ncRaccBfOvw1HjwPhORvjnTAFAB0BGRfkjdXEQOo2rs/5YZgIGIbEUlJiKOAc3MnQ8Ae0kKlvUFsBZb2y9Qm+Tc3Jv86AnJo4ja3lar1fU0EJKXlvLz8MdeTAOHnuetJAFc1y1bPZlkASwAXKVU0bPuuN/ojuOoOE+jAsCOBfDTJJXJarXahqX8NHeA+UEDBd3cASJyYCnYzx0AYBAAtNbNvINvknwxgKd6vb6aK4DkfZB95EyysimJyBmAUprgZkcEwe+SDq8FUgG8kfSizppF9Gg1dpI4vwBUSI7sMUzy2YzsjvELkkNrwAVjfjuN4mCu3GRYOCOtNVMFD6lpkbwOLaDlIiL5AMBPM0ZiTSlVNPX2SHpa66ZSqvinoHnZJ3jLDwknYoRNAAAAAElFTkSuQmCC",
                command: "History:UndoCloseTab"
        };
          
        var uCTBtn = $C('toolbarbutton', buttonAttrs);
  
        var popup = uCTBtn.appendChild($C("menupopup", {
                oncommand: "event.stopPropagation();",
                onpopupshowing: "this.parentNode.populateUndoSubmenu();",
                context: "",
                tooltip: "bhTooltip",
                popupsinherittooltip: "true"
        }));
        uCTBtn._getClosedTabCount = HistoryMenu.prototype._getClosedTabCount;
        uCTBtn.populateUndoSubmenu = eval("(" + HistoryMenu.prototype.populateUndoSubmenu.toString().replace(/\.undoTabMenu/g, "") + ")");
          
        // 来自 User Agent Overrider 扩展
    const log = function() { dump(Array.slice(arguments).join(' ') + '\n'); };
    const trace = function(error) { log(error); log(error.stack); };
    const ToolbarManager = (function() {
  
        /**
         * Remember the button position.
         * This function Modity from addon-sdk file lib/sdk/widget.js, and
         * function BrowserWindow.prototype._insertNodeInToolbar
         */
        let layoutWidget = function(document, button, isFirstRun) {
  
            // Add to the customization palette
            let toolbox = document.getElementById('navigator-toolbox');
            toolbox.palette.appendChild(button);
  
            // Search for widget toolbar by reading toolbar's currentset attribute
            let container = null;
            let toolbars = document.getElementsByTagName('toolbar');
            let id = button.getAttribute('id');
            for (let i = 0; i < toolbars.length; i += 1) {
                let toolbar = toolbars[i];
                if (toolbar.getAttribute('currentset').indexOf(id) !== -1) {
                    container = toolbar;
                }
            }
  
            // if widget isn't in any toolbar, default add it next to searchbar
            if (!container) {
                if (isFirstRun) {
                    container = document.getElementById('nav-bar');
                } else {
                    return;
                }
            }
  
            // Now retrieve a reference to the next toolbar item
            // by reading currentset attribute on the toolbar
            let nextNode = null;
            let currentSet = container.getAttribute('currentset');
            let ids = (currentSet === '__empty') ? [] : currentSet.split(',');
            let idx = ids.indexOf(id);
            if (idx !== -1) {
                for (let i = idx; i < ids.length; i += 1) {
                    nextNode = document.getElementById(ids[i]);
                    if (nextNode) {
                        break;
                    }
                }
            }
  
            // Finally insert our widget in the right toolbar and in the right position
            container.insertItem(id, nextNode, null, false);
  
            // Update DOM in order to save position
            // in this toolbar. But only do this the first time we add it to the toolbar
            if (ids.indexOf(id) === -1) {
                container.setAttribute('currentset', container.currentSet);
                document.persist(container.id, 'currentset');
            }
        };
  
        let addWidget = function(window, widget, isFirstRun) {
            try {
                layoutWidget(window.document, widget, isFirstRun);
            } catch(error) {
                trace(error);
            }
        };
  
        let removeWidget = function(window, widgetId) {
            try {
                let widget = window.document.getElementById(widgetId);
                widget.parentNode.removeChild(widget);
            } catch (error) {
                trace(error);
            }
        };
  
        let exports = {
            addWidget: addWidget,
            removeWidget: removeWidget,
        };
        return exports;
    })();
          
    ToolbarManager.addWidget(window, uCTBtn, false);
        document.insertBefore(document.createProcessingInstruction('xml-stylesheet', 'type="text/css" href="data:text/css;utf-8,' + encodeURIComponent('\
                #undoclosetab-button menuitem {max-width: 240px;}\
                ') + '"'), document.documentElement);
                 
        function $C(name, attr) {
                var el = document.createElement(name);
                if (attr) Object.keys(attr).forEach(function(n) { return el.setAttribute(n, attr[n]);});
                return el;
        }
})();
lonely_8
狐狸大王
狐狸大王
  • UID30273
  • 注册日期2009-09-03
  • 最后登录2018-12-05
  • 发帖数399
  • 经验182枚
  • 威望0点
  • 贡献值68点
  • 好评度46点
  • 社区居民
1楼#
发布于:2018-12-05 13:21
// ==UserScript==
// @Name                 UndoCloseTabBtn.uc.js
// @namespace         UndoCloseTab@gmail.com
// @description         可移动恢复已关闭标签按钮
// @author               defpt
// @charset              UTF-8
// @Compatibility        FF57+
// @version              v2018.04.04 更新兼容57+ by runningcheese
// @version              v2014.09.15
// ==/UserScript==
(function() {
    if(document.getElementById('undoclosetab-button')) return;
 
    CustomizableUI.createWidget({
        id: 'undoclosetab-button',
        label: '恢复最后关闭的标签',
        tooltiptext: '左键:恢复最后关闭的标签\n右键:显示关闭标签菜单',
        defaultArea : CustomizableUI.AREA_NAVBAR,
        onCreated: (uCTBtn) => {
            uCTBtn.setAttribute('context', '_child'); //点击按钮恢复最后一次关闭的标签
                               //如果想左键恢复最后一次关闭的标签,右键打开已关闭标签列表,那么改为(context: "_child",)
                               //如果想改成菜单形式的,那么改为(type: "menu-button",)
            uCTBtn.setAttribute('command', 'History:UndoCloseTab');
 
            uCTBtn.appendChild($C('menupopup', {
                oncommand: 'event.stopPropagation();',
                onpopupshowing: 'this.parentNode.populateUndoSubmenu();',
                context: '',
                tooltip: 'bhTooltip',
                popupsinherittooltip: 'true'
            }));
            uCTBtn._getClosedTabCount = HistoryMenu.prototype._getClosedTabCount;
            uCTBtn.populateUndoSubmenu = eval('(' + HistoryMenu.prototype.populateUndoSubmenu.toString().replace(/\.undoTabMenu/g, '') + ')');
        }
    });
 
 
    document.insertBefore(document.createProcessingInstruction(
        'xml-stylesheet', 'type="text/css" href="data:text/css;utf-8,' + encodeURIComponent('\
            #undoclosetab-button menuitem {max-width: 240px;}\
            #undoclosetab-button .toolbarbutton-icon {list-style-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABuUlEQVRIib2VL08DQRDFKxANqahErijJte/N5pI2oQlNuA+AqEBUkHAJAkMIAhJERYNBICr4ABUIFKlEIBA4DAJRgUBUIJpgKioqitkry8H9CxcmmeQutzu/eTO5mULhP4xkA0Ar6ruIOCR3SZ4A6JrnRhaAR3JqQ5RSRQDHJMckFxE+JtlzXbccCwDQMRemAFpaa5J8jQkc9ncRaccBfOvw1HjwPhORvjnTAFAB0BGRfkjdXEQOo2rs/5YZgIGIbEUlJiKOAc3MnQ8Ae0kKlvUFsBZb2y9Qm+Tc3Jv86AnJo4ja3lar1fU0EJKXlvLz8MdeTAOHnuetJAFc1y1bPZlkASwAXKVU0bPuuN/ojuOoOE+jAsCOBfDTJJXJarXahqX8NHeA+UEDBd3cASJyYCnYzx0AYBAAtNbNvINvknwxgKd6vb6aK4DkfZB95EyysimJyBmAUprgZkcEwe+SDq8FUgG8kfSizppF9Gg1dpI4vwBUSI7sMUzy2YzsjvELkkNrwAVjfjuN4mCu3GRYOCOtNVMFD6lpkbwOLaDlIiL5AMBPM0ZiTSlVNPX2SHpa66ZSqvinoHnZJ3jLDwknYoRNAAAAAElFTkSuQmCC")}\
    ') + '"'), document.documentElement);
               
    function $C(name, attr) {
        var el = document.createElement(name);
        if (attr) Object.keys(attr).forEach(function(n) { return el.setAttribute(n, attr[n]);});
        return el;
    }
})();
333ywb
小狐狸
小狐狸
  • UID27284
  • 注册日期2008-12-03
  • 最后登录2018-12-14
  • 发帖数25
  • 经验44枚
  • 威望0点
  • 贡献值38点
  • 好评度0点
  • 社区居民
  • 忠实会员
2楼#
发布于:2018-12-05 14:24
lonely_8:// ==UserScript==
// @Name                 UndoCloseTabBtn.uc.js
// @namespace         UndoCloseTab@gmail.com
// @des...
回到原帖
问题解决了,还是大佬厉害,每次遇到脚本问题都是你解决的,再次感谢万分
游客

返回顶部