凭枰
狐狸大王
狐狸大王
  • UID32865
  • 注册日期2010-05-17
  • 最后登录2021-08-29
  • 发帖数536
  • 经验489枚
  • 威望1点
  • 贡献值226点
  • 好评度50点
  • 社区居民
  • 忠实会员
阅读:5438回复:6

改进zAutoPopup.uc.js

楼主#
更多 发布于:2014-05-04 20:19
下面的代码在29能正常工作,但有三点遗憾,不知能否改进:
1、对 Adblock Edge 无效。
2、对前进后退按钮无效。
2、对三条杠内的扩展下拉菜单无效。

// ==UserScript==
// <a href="home.php?mod=space&uid=467097">@Name</a>           zAutoPopup.uc.js
// @description    Auto popup menulist/menupopup
// @compatibility  Firefox 2.0+
// <a href="home.php?mod=space&uid=321866">@author</a>         GOLF-AT
// <a href="home.php?mod=space&uid=570682">@version</a>        2.0.0.20131119
   
(function() {
    var PopElt = null;    var DropElt = null;
    var PopTimer = null;  var HideTimer = null;
    var AlwaysPop = false;  var nDelay = 200;
   
    function IsNewMenuBtn(elt) {
        try {
            return elt.id=='PanelUI-menu-button';
        }catch(e) {
            return false;
        }
    }
   
    function AutoPopup()
    {
        PopTimer = null;
        if (DropElt) {
            if (DropElt.localName=='dropmarker' ||
                IsNewMenuBtn(DropElt))
                PopElt = DropElt;
            else {
                var v = null;
                try {
                    v = DropElt.ownerDocument.
                        getAnonymousNodes(DropElt);
                }catch(ex) {}
                if (v!=null && v.length!=0 && v[0].
                    localName=='menupopup')
                    PopElt = v[0];
                else
                    PopElt = DropElt.childNodes[0];
            }
   
            if (IsNewMenuBtn(PopElt)) {
                PanelUI.show(); return;
            }
            try {
                PopElt.showPopup(PopElt.parentNode,
                    -1, -1, 'popup', 'bottomleft',
                    'topleft');
            }catch(e) { PopElt = null; }
        }
    }
   
    function HidePopup()
    {
        try {
            if (PopElt.localName=='dropmarker')
                PopElt.parentNode.closePopup();
            else if (IsNewMenuBtn(PopElt))
                PanelUI.hide();
            else
                PopElt.hidePopup();
        }catch(e) {}
        HideTimer = null; DropElt = null;
        PopElt = null;
    }
   
    function MouseOver(e)
    {
        if (!AlwaysPop && !document.hasFocus())
            return;
   
        if (IsButton(e.target)) {
            type = e.target.getAttribute('type');
            if (type == 'menu-button') {
                if (e.originalTarget!=e.target)
                    return;
            }
            /*else {
                if (type != 'menu') return;
            }*/
        }
   
        if (HideTimer) {
            window.clearTimeout(HideTimer);
            HideTimer = null;
        }
        try {
            if ('PopupAutoComplete'==e.target.id.
                substr(0,17))
                return;
            for(var elt=e.target; elt!=null; elt=
                elt.parentNode) {
                if (elt.localName=='popup' || elt.
                    localName=='menupopup')
                    return;
            }
        }catch(ex) {}
   
        if (IsNewMenuBtn(PopElt)) {
            if (e.target != PopElt) HidePopup();
        }
        else if (PopElt != null) {
            if (DropElt!=null && e.target==DropElt)
                return;
            try {
                if (PopElt.localName != 'dropmarker'
                    ) {
                    for(var elt=e.target; elt!=null;
                        elt=elt.parentNode) {
                        if (elt == PopElt) return;
                    }
                }
            }catch(ex) {}
            HidePopup();
        }
        DropElt = e.target;
        PopTimer = setTimeout(AutoPopup, nDelay);
    }
   
    function MouseOut(e)
    {
        if (PopTimer) {
            window.clearTimeout(PopTimer);
            PopTimer = null;
        }
        if (!HideTimer && PopElt && !IsNewMenuBtn(e.
            target))
            HideTimer = window.setTimeout(HidePopup,
                500);
    }
   
    function IsButton(elt) {
        try {
            return elt.localName=='toolbarbutton' || elt
                .localName=='button';
        }catch(e) { return false; }
    }
   
    function IsMenuButton(elt) {
        if (IsNewMenuBtn(elt)) return true;
   
        if (!IsButton(elt)) return false;
        for(var i=0; i<2; i++) {
            try {
                var nodes = i==0x01 ? elt.childNodes : elt.
                    ownerDocument.getAnonymousNodes(elt);
                if (nodes!=null && nodes.length && nodes[0]
                    .localName=='menupopup')
                    return true;
            }catch(e) {}
        }
        return false;
    }
   
    function EnumElement(elt) {
        try {
            if (elt.localName == 'prefpane') {
                elt.addEventListener('paneload', function(e) {
                    setTimeout(function() { EnumElement(e.
                        target); }, 100);
                    }, false);
            }
            else if(elt.id=='sidebar' && !elt.hasAttribute(
                'AutoPopup')) {
                elt.setAttribute('AutoPopup', true)
                elt.addEventListener('SidebarFocused',
                    function(e) { EnumElement(elt); }, false);
            }
            else if(elt.id == 'editBookmarkPanel')
                return;
        }catch(e) {}
   
        for(var i=0; i<2; i++) {
            var nodes = null;
            try {
                if (elt.localName == 'browser') {
                    i = 1;
                    nodes = elt.contentDocument.childNodes;
                }
                else
                    nodes = i==0x01 ? elt.childNodes : elt.
                        ownerDocument.getAnonymousNodes(elt);
            }catch(e) { nodes = null; }
            if (nodes == null) continue;
   
            for(var n=0; n<nodes.length; n++) {
                try {
                    var node = nodes[n];
                    if ('PopupAutoComplete'==node.getAttribute(
                        'id').substr(0,17) || 'menupopup'==node
                        .localName || node.localName=='popup')
                        ;
                    else if (node.localName != 'dropmarker') {
                        if (node.localName=='menu' && 'menubar'
                            ==node.parentNode.localName)
                            ;
                        else if(!IsMenuButton(node))
                            node = null;
                    }
                    else if(node.getAttribute('type')=='menu') {
                        node = node.parentNode;
                        if (!node.firstChild || node.firstChild.
                            localName!='menupopup')
                            continue;
                    }
                    if (node == null) {
                        EnumElement(nodes[n]); continue;
                    }
                    if (node.hasAttribute('command')) continue;
   
                    node.addEventListener('mouseout', MouseOut,
                        false);
                    node.addEventListener('mouseover',MouseOver,
                        false);
                }catch(e) {}
            }
        }
    }
   
    setTimeout(function() { EnumElement(document); }, 100);
})();
   
  (function () {
      var stylishBtn = document.getElementById("stylish-toolbar-button");
      if (!stylishBtn) return;
      var menupopup = document.getElementById("stylish-popup");
      if (!menupopup) return;
   
      stylishBtn.setAttribute("popup", "");//取消原来的下拉菜单
      stylishBtn.insertBefore(menupopup, stylishBtn.firstChild);
   
  })();
   
   
   
(function() {
            var GMBtn = document.getElementById("greasemonkey-tbb");
            if (!GMBtn) return;
            var GMMenupopup = GMBtn.firstChild;
            if (!GMMenupopup) return;
            var GMEnable = document.getElementById("gm_toggle_enabled");
            if (!GMEnable) return;
            var GMCheck = document.getElementById("gm_toggle_checked");
           
               
   
            GMMenupopup.setAttribute("id","greasemonkey-popup");//
            GMEnable.removeAttribute("oncommand");
            GMEnable.setAttribute("oncommand","GM_util.setEnabled(!GM_util.getEnabled());GMsetIconStatus(event);");//
            GMCheck.removeAttribute("oncommand");
            GMCheck.setAttribute("oncommand","GM_util.setEnabled(!GM_util.getEnabled());GMsetIconStatus(event);");//
   
            GMBtn.removeAttribute("command");//取消按钮功能(会导致autoPopup无法自动弹出下拉菜单)
            GMBtn.removeAttribute("oncommand");//取消原来按钮(奇葩的GM居然还做两遍,上面这行是为了切换图标?)
   
            GMBtn.setAttribute("type", "menu");//按钮+右键菜单
             
 GMBtn.setAttribute("onclick", 
"GM_util.setEnabled(!GM_util.getEnabled());GMsetIconStatus(event);");//GMsetStatusDirectly(event);
   
               
            GMsetIconStatus = function (event) {
                if(event.button > 0) return;//left click only
                GMenabled = true;
                if (GMenabled == null) return;
                if (!GMenabled) {GMBtn.style.opacity = '0.3';
                } else {
                    GMBtn.removeAttribute('disabled');
                    GMBtn.setAttribute('style','opacity: 1.0');
                }
            };
        })();
fang5566
管理员
管理员
  • UID3719
  • 注册日期2005-03-07
  • 最后登录2024-06-03
  • 发帖数18483
  • 经验4837枚
  • 威望5点
  • 贡献值4316点
  • 好评度1116点
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 终身成就
1楼#
发布于:2014-05-05 09:37
作者是 golf+at?
@GOLF-AT
一下
Firefox More than meets your experience
紫焰蔷薇
火狐狸
火狐狸
  • UID38153
  • 注册日期2012-01-24
  • 最后登录2021-09-04
  • 发帖数221
  • 经验102枚
  • 威望0点
  • 贡献值36点
  • 好评度7点
  • 社区居民
  • 忠实会员
2楼#
发布于:2014-05-05 10:30
fang5566:作者是 golf+at?
@GOLF-AT
一下
回到原帖
请问这种UC.JS脚本怎么知道它可以起什么作用,还有安装之后要怎么操作,比如按什么快捷键?小白翻了一下代码,不像stylish有/**/做备注,根本不知道它可以干嘛,搜索也是一些求助贴,没有说明。
fang5566
管理员
管理员
  • UID3719
  • 注册日期2005-03-07
  • 最后登录2024-06-03
  • 发帖数18483
  • 经验4837枚
  • 威望5点
  • 贡献值4316点
  • 好评度1116点
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 终身成就
3楼#
发布于:2014-05-05 11:05
紫焰蔷薇:请问这种UC.JS脚本怎么知道它可以起什么作用,还有安装之后要怎么操作,比如按什么快捷键?小白翻了一下代码,不像stylish有/**/做备注,根本不知道它可以干嘛,搜索也是一些求助贴,没有说明。回到原帖
http://g.mozest.com/thread-20276-1-1
这里有介绍怎么使用、安装。
uc脚本大家提供时候最好简单介绍一下怎么使用,方便别人。description字段里面也有描述,比如这个就是自动弹出菜单的脚本。
Firefox More than meets your experience
凭枰
狐狸大王
狐狸大王
  • UID32865
  • 注册日期2010-05-17
  • 最后登录2021-08-29
  • 发帖数536
  • 经验489枚
  • 威望1点
  • 贡献值226点
  • 好评度50点
  • 社区居民
  • 忠实会员
4楼#
发布于:2014-05-05 12:20
fang5566:作者是 golf+at?
@GOLF-AT
一下
回到原帖
这是卡饭修改的版本,golfat的原版连stylish和greasemonkey都不能解决。
紫焰蔷薇
火狐狸
火狐狸
  • UID38153
  • 注册日期2012-01-24
  • 最后登录2021-09-04
  • 发帖数221
  • 经验102枚
  • 威望0点
  • 贡献值36点
  • 好评度7点
  • 社区居民
  • 忠实会员
5楼#
发布于:2014-05-05 13:53
凭枰:这是卡饭修改的版本,golfat的原版连stylish和greasemonkey都不能解决。回到原帖
哦 谢谢
凭枰
狐狸大王
狐狸大王
  • UID32865
  • 注册日期2010-05-17
  • 最后登录2021-08-29
  • 发帖数536
  • 经验489枚
  • 威望1点
  • 贡献值226点
  • 好评度50点
  • 社区居民
  • 忠实会员
6楼#
发布于:2014-05-09 14:27
发现对 ABE 也无效。
游客

返回顶部