brucmao
火狐狸
火狐狸
  • UID39549
  • 注册日期2013-05-29
  • 最后登录2016-08-27
  • 发帖数101
  • 经验154枚
  • 威望0点
  • 贡献值134点
  • 好评度5点
阅读:3703回复:6

[求助]帮忙修改sidebar这个uc脚本

楼主#
更多 发布于:2015-01-05 16:13
我在用Sidebar.uc.js 这个uc脚本,
Sidebar.uc.rar
展示效果如下

图片:QQ截图20150105155903.png


我想在红色地方添加下载选项的按钮,就是展示下面的页面

图片:QQ图片20150105160145.png


我用DOM Inspector和Element Inspector 获取的id如下

图片:QQ图片20150105155210.png


但是打开chrome://browser/content/places/places.xul 却显示的是书签
// ==UserScript==
// @name            Sidebar.uc.js
// @description     侧边栏功能增强
// @include         chrome://browser/content/browser.xul
// @charset         UTF-8
// ==/UserScript==
(function() {
    if (!document.getElementById('sidebar-box')) return;
    if (!window.SidebarMod) {
        window.SidebarMod = {
            sitelist:[{
                name: '历史',
                url: 'chrome://browser/content/history/history-panel.xul',
                favicon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAH7SURBVDhPhVI9a9tQFBUeO4YOwZTSH+Ch1I2esIdi10jvPYsMmTLkH5Sm9lI8FIsOHUsU+gOMKSGEBNwiB5K9xJbdQJYQYtWIYEonL82HBhNe7316LnbT2AcOsu5759xzr6zdB+FoibPlTPL6OJMUQkuo8nwEtvGsx/TtgOuXASci6hripkMuoy7ZufaXnqtr/0eP69UeI7coDBjpH7JseLKXDW+6RhgbGbdg9F5dj3FeNAryyck7KeR6GHCDYs2y6JZpss/4O+rq5oRRFWsS0PEXRD4G4QjFOLc6mjJAXPlLi2iCSa78zFNZhK6tuDMRMELwo0hWcYF49q8BIvINiimAcR2EW2MDxcO+nX5sWdYT06TnlsXOKKWP5GWFeBQylC89Tj6gEEa5gD2syCIAujdALJCQ4hRYi8lp1CENTPH7e/ohGqyhyU87/UBpJUC4O2mA4yAhDc81aSPfhPqBuaCu3wXGHu+Ac76oyhJ5j4U5j8UjIF59+pYsua2N8uaR/Hyz8HKf2dg936R1VdK0dbeTeuO2R6WN1uD1ZntqYZMofCkkofsAOHrhFVOqHKPktt8CBZqsu77tOOLv/99xnETOo1yKoTvsoKKOpgFjVGQSZQT0QPAVBBcyNnS+VzwGjgNGdTAaopHsCAsD1u7Enofyx6OFmZ9K07Q/7iAmIuxhVMIAAAAASUVORK5CYII='
            },{
                name: '附加组件',
                url: 'about:addons',
                favicon: "chrome://mozapps/skin/extensions/extensionGeneric-16.png#-moz-resolution=16,16"
            },{
                name: '侧栏翻译',
                url: 'http://translate.google.com/#auto/zh-CN/',
                favicon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAElSURBVDhPrZE/awJBEEevEOz9JPkS6dIHLCzSpQtYBQIhpYF0dmJnkyKkE1FSaCMcxCNBwcI/ICYhiF20sBl5w82y4U4NwYUHe8f+3szsBkdZ65+FGM3ms1SqZVkupsr351C+PgYSH01fBK5vikrhIq/YN8xn/b8J/KAvOiig9W7Y1kDUDzVweVeSq1Ac5x2Rs9ZKTuoiuceN4kazea0iHbE/JIBfAi7QWmfvh19GcwVJqmAy7iVmJwj3r0v3GuwTAubOFEd6D1TmG6gGVDYB+4SAsKE/4sW8CAg+hZFWZ++PoQf3CQjxKreNyMn8LvTgLgEH7Fm5I0DAv50CHyoSov3T2rsG6MTuxwmwpgkAgYUNLhucgJUmyT68KX7Yh0wc/+8Kgi1VwxKf8jOsdgAAAABJRU5ErkJggg=='
            },{
                name: 'webQQ',
                url: 'http://w.qq.com/',
                favicon: 'data:image/ico;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAA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majr/AAAAAElFTkSuQmCC'
                }],
    
            makeButton: function (sitelist) {
                var i,
                    len = sitelist.length,
                    item,
                    btn,
                    frag = document.createDocumentFragment();
                    insertpoint = document.querySelector('#sidebar-header .close-icon');
                for (i = 0; i < len; i++) {
                    item = sitelist<span style="font-style: italic;">;
                    btn = frag.appendChild(document.createElement('toolbarbutton'));
                    btn.setAttribute('tooltiptext', item.name);
                    btn.setAttribute('style', 'list-style-image: url("' + item.favicon + '")');
                    btn.setAttribute('url', item.url);
                    btn.setAttribute('onclick', 'openWebPanel(this.getAttribute("tooltiptext"), this.getAttribute("url"))');
                }
                insertpoint.parentNode.insertBefore(frag, insertpoint);
            },
    
            //添加侧栏前进、后退、刷新按钮
            addControlBtn: function(){
                    var SHBtn = document.getElementById("sidebar-header");
                    if(SHBtn) {
                            var _sidebarBtn = document.createElement('toolbarbutton');
                            _sidebarBtn.setAttribute('type', 'button');
                            _sidebarBtn.setAttribute("tooltiptext","左键:后退\n中键:刷新\n右键:前进");
                            _sidebarBtn.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");
                            _sidebarBtn.setAttribute("image","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABaSURBVDhPzYzJEcAwCAPpJ62kaHfmHCMzJEbi4Y/3BSuNbE/OdnScTuZSniIbKEdGSQ1k2UtZuKEdFijnfhIgepWtD6QCKPf3PAiUHVVQ2YdqAK+GDeDcCrMLOe2fMX6PACcAAAAASUVORK5CYII=");
                            _sidebarBtn.addEventListener("click",
                            function(event) {
                                    var webPanel = document.getElementById('sidebar').contentDocument.getElementById("web-panels-browser");
                                    if (event.button == 2) {
                                            event.preventDefault();
                                            event.stopPropagation();
                                            webPanel.contentWindow.history.forward();
                                    } else if (event.button == 1){
                                            webPanel.contentWindow.location.reload();
                                    } else {
                                            webPanel.contentWindow.history.back();
                                    }
                            },
                            false);
                            SHBtn.insertBefore(_sidebarBtn, SHBtn.childNodes[2]);
                    }
            },
    
            toggleSidebar: function (commandID, forceOpen) {
                var sidebarBox = document.getElementById("sidebar-box"),
                sidebar = document.getElementById("sidebar"),
                sidebarTitle = document.getElementById("sidebar-title"),
                sidebarBoxArrow = document.getElementById('sidebar-box-arrow'),
                lastcommand = commandID || sidebarBox.getAttribute('sidebarcommand') || sidebarBox.getAttribute('sidebarlastcommand') || 'viewHistorySidebar';
                    
                if (!commandID && sidebarBox.hidden) {
                    if (sidebarBox.getAttribute('sidebarcommand') === '') {
                        toggleSidebar(lastcommand, true);
                        sidebarBox.setAttribute('sidebarlastcommand', lastcommand);
                    } else {
                        sidebarBox.hidden = false;
                        if (sidebarBoxArrow) sidebarBoxArrow.className = '';
                    }
                    return;
                }
                    
                if (!commandID) commandID = sidebarBox.getAttribute("sidebarcommand");
                let sidebarBroadcaster = document.getElementById(commandID);
                    
                if (sidebarBroadcaster.getAttribute("checked") == "true") {
                    if (!forceOpen) {
                        if (sidebarBox.getAttribute('sidebarcommand') !== 'viewWebPanelsSidebar') {
                            sidebar.setAttribute("src", "about:blank");
                            sidebar.docShell.createAboutBlankContentViewer(null);
                            sidebarBox.setAttribute("sidebarcommand", "");
                            sidebarTitle.value = "";
                            sidebarBox.setAttribute('sidebarlastcommand', lastcommand);
                        }
                        sidebarBox.setAttribute("sidebarcommand", "");
                        sidebarBox.setAttribute('sidebarlastcommand', lastcommand);
                        sidebarBroadcaster.removeAttribute("checked");
                        sidebarBox.hidden = true;
                        if (sidebarBoxArrow) sidebarBoxArrow.className = 'right';
                        gBrowser.selectedBrowser.focus();
                    } else {
                        fireSidebarFocusedEvent();
                    }
                    return;
                }
                    
                var broadcasters = document.getElementsByAttribute("group", "sidebar");
                for (let broadcaster of broadcasters) {
                    if (broadcaster.localName != "broadcaster") continue;
                    if (broadcaster != sidebarBroadcaster) broadcaster.removeAttribute("checked");
                    else sidebarBroadcaster.setAttribute("checked", "true");
                }
                    
                sidebarBox.hidden = false;
                if (sidebarBoxArrow)sidebarBoxArrow.className = '';
                    
                var url = sidebarBroadcaster.getAttribute("sidebarurl");
                var title = sidebarBroadcaster.getAttribute("sidebartitle");
                if (!title) title = sidebarBroadcaster.getAttribute("label");
                sidebar.setAttribute("src", url);
                sidebarBox.setAttribute("sidebarcommand", sidebarBroadcaster.id);
                if ( title &&  title !== '') sidebarTitle.value = title;
                sidebarBox.setAttribute("src", url);
                sidebarBox.setAttribute('sidebarlastcommand', lastcommand);
                    
                if (sidebar.contentDocument.location.href != url) sidebar.addEventListener("load", sidebarOnLoad, true);
                else fireSidebarFocusedEvent();
            },
    
            modifySidebarClickBehaviour: function () {
                var sidebar = document.getElementById('sidebar');
                sidebar.addEventListener('DOMContentLoaded', function(){
                    if (sidebar.contentDocument){
                        sidebar.removeEventListener('DOMContentLoaded', arguments.callee, false);
                        var wpb = sidebar.contentDocument.getElementById('web-panels-browser');
                        if (wpb) {
                            wpb.onclick = null;
                        }
                    }
                }, false);
                    
                eval("window.asyncOpenWebPanel = " + window.asyncOpenWebPanel.toString().slice(0, -1) + 
                    'var wpb = sidebar.contentDocument.getElementById("web-panels-browser");' +
                    'if (wpb) wpb.onclick = null;' + '}'
                );
                    
                eval("window.openWebPanel = " + window.openWebPanel.toString().slice(0, -1) + 
                    'var wpb = sidebar.contentDocument.getElementById("web-panels-browser");' +
                    'if (wpb) wpb.onclick = null;' + '}'
                );
            },
    
            init: function() {
                window.toggleSidebar = this.toggleSidebar;
                this.makeButton(this.sitelist);
                this.addControlBtn();
                this.modifySidebarClickBehaviour();
            }
        };
            
        SidebarMod.init();
    }
})();</span>
问题1,应该怎么修改这个uc脚本呢,添加下载选项
问题2,我同时在用Omnisiderbar这个扩展,点击附加组件和点击siderbar.uc.js这个脚本的附加组件图标展示结果不一致,但我看地址都是 about:addons
怎么才能点击右边附加组件图标变成左边的效果

图片:3.png

@brucmao
文科
千年狐狸
千年狐狸
  • UID39959
  • 注册日期2013-10-17
  • 最后登录2019-05-06
  • 发帖数2069
  • 经验1328枚
  • 威望4点
  • 贡献值340点
  • 好评度255点
  • 最爱沙发
  • 社区居民
  • 忠实会员
1楼#
发布于:2015-01-05 16:50
chrome://mozapps/content/downloads/downloads.xul
chrome://mozapps/content/extensions/extensions.xul
brucmao
火狐狸
火狐狸
  • UID39549
  • 注册日期2013-05-29
  • 最后登录2016-08-27
  • 发帖数101
  • 经验154枚
  • 威望0点
  • 贡献值134点
  • 好评度5点
2楼#
发布于:2015-01-06 09:41
文科:chrome://mozapps/content/downloads/downloads.xul
chrome://mozapps/content/extensions/extensions.xul
回到原帖
第一个直接复制到地址栏不能打开,第二个也不是我想要的效果,没有Omnisiderbar显示的漂亮
@brucmao
文科
千年狐狸
千年狐狸
  • UID39959
  • 注册日期2013-10-17
  • 最后登录2019-05-06
  • 发帖数2069
  • 经验1328枚
  • 威望4点
  • 贡献值340点
  • 好评度255点
  • 最爱沙发
  • 社区居民
  • 忠实会员
3楼#
发布于:2015-01-06 13:42
brucmao:第一个直接复制到地址栏不能打开,第二个也不是我想要的效果,没有Omnisiderbar显示的漂亮回到原帖
我这里可以。Omnisiderbar应该用了样式
yykhyn
小狐狸
小狐狸
  • UID12952
  • 注册日期2006-05-25
  • 最后登录2019-05-01
  • 发帖数21
  • 经验18枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
4楼#
发布于:2015-01-06 15:01
{
    name: '下载',
    url: 'about:downloads',
    favicon: "chrome://browser/skin/places/downloads.png"
},
brucmao
火狐狸
火狐狸
  • UID39549
  • 注册日期2013-05-29
  • 最后登录2016-08-27
  • 发帖数101
  • 经验154枚
  • 威望0点
  • 贡献值134点
  • 好评度5点
5楼#
发布于:2015-01-07 09:52
yykhyn:{
    name: '下载',
    url: 'about:downloads',
    favicon: "chrome://browser/skin/places/downloads.png"
},
回到原帖
这个好,估计Omnisiderbar还用了样式来修饰
@brucmao
eagle5678
千年狐狸
千年狐狸
  • UID4956
  • 注册日期2005-04-10
  • 最后登录2019-06-25
  • 发帖数1183
  • 经验133枚
  • 威望0点
  • 贡献值66点
  • 好评度3点
6楼#
发布于:2017-11-21 11:00
现在好你不起作用了
游客

返回顶部