zhouhuajdsh
小狐狸
小狐狸
  • UID49842
  • 注册日期2015-04-27
  • 最后登录2020-12-25
  • 发帖数19
  • 经验18枚
  • 威望0点
  • 贡献值4点
  • 好评度0点
  • 社区居民
  • 忠实会员
阅读:2099回复:9

大神求修复下AddBMHere.uc.js

楼主#
更多 发布于:2020-05-10 03:53
76下失效了,无法添加书签,求修复


// ==UserScript==
// @name           AddBMHere.uc.js
// @description    为书签工具栏和书签菜单添加“添加书签到此”菜单
// @author         ding
// @include        main
// @version        firefox69修复样式
// @startup        window.AddBMHere.init();
// @shutdown       window.AddBMHere.destroy();
// ==/UserScript==
 
location.href.startsWith('chrome://browser/content/browser.x') && (function () {
 
    const MENU_NAME = "\u6DFB\u52A0\u4E66\u7B7E\u5230\u6B64";
    const MENU_ICON = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACp0lEQVRYhe1XMWgUQRRdJGDEiCIpUlyRIqCCRRAES4sEPAgimJVAEFZvPe52b/57nztDwIgrQRQCClqkEI2ICGJpYSEhWmulZcoUQQOeYBEkSCxyJ8O6d5fb85JCP2wxs//99/bPnz+zjvPfOrAoinpc1+3bNQGqOgtgYVfIjTHjAL6Q3BARf0fJi8XiEZKLJDdJbqrqBwAnd0wAgHt18vojIo+y2ezerpOTPGeRrpNcs8bdXQrP8wZihBVjzHh9DOA7ycGukEdR1Kuqj620P8vn8wcdx3FEZN6af5HL5Q7/NWLf9zOlUqkAYMn60qrv+5m6D8lDAFas90vcssFUpCSHSUYk38eLjeRmGIYTcQyAsSRfAJ9UdbZYLJ5qSqqqIyIyb39JQqWvkpxrFAPAdDN87d1DAGN/gEXkRgLoJ4B3xphbJLNTU1MHWmXPdd19AEZV9SbJRVX9EY+rqncaZeFVrKKHWxG2siAIhgBULQFvoijqSXQmeUxEXlspn69UKvvTkkdRtAfAXYv8bRiGJ5qCAIyS/GiJuJ5WgDHmqkW+XCqVzm4LKCKXVPVrDfgNQC4F+aSqrtbWfB1A0G6AGbsegiAY2i7W9/2M3TGb7ZymRvKlFcRrA+fZTalh0bUyY8wVqxbCNnCT9nmRitxxHEdEQisDl7eLA3Dewl1LLQDAdLMl8DyvN+lOSPK0hYtSC6idB/W1/N0+gyAYIjlHcg1AVVUfFAqF410VoKojxphxu1El9PqlMAwnRORMxzsgLqB2+4mTbiTN23Md3ZptAQmnWuT7fqZcLveLSIXkcgPfjgTctwJVATwXkYvlcrk/7uu6bp+qXiD5hORnS8TT1AIALIjIqojcZhu3G8/zBowxMwBWOspAPp8/mrqLOVu/bu208H/TfgFnF2PgEPffBgAAAABJRU5ErkJggg==";
    const AUTO_ADD = true; //是否不弹出面板自动添加
    const SIDEBAR_SUPPORT = false;//侧栏支持,需要定时检测
 
    if (window.AddBMHere) {
        window.AddBMHere.destroy();
        delete window.AddBMHere;
    }
 
    var AddBMHere = {
        addMenus: [],
        init: function () {
            $('PlacesToolbarItems').addEventListener('popupshowing', this, false);
            $('PlacesToolbarItems').addEventListener('popuphidden', this, false);
            var pop = $('BMB_bookmarksPopup');
            if (pop) {
                pop.addEventListener('popupshowing', this, false);
                pop.addEventListener('click', this, false);
                pop.addEventListener('popuphidden', this, false);
            }
            var panel = $('editBookmarkPanel');
            if (panel) {
                panel.addEventListener('popupshowing', this, false);
            }
            var placesContext = $("placesContext");
            if (placesContext) {
                placesContext.addEventListener('popupshowing', this, false);
                this.addPlaceMenu();
            }
            this.checkSideBar();
        },
        destroy: function () {
            $('PlacesToolbarItems').removeEventListener('popupshowing', this, false);
            $('PlacesToolbarItems').removeEventListener('popuphidden', this, false);
            var pop = $('BMB_bookmarksPopup');
            if (pop) {
                pop.removeEventListener('popupshowing', this, false);
                pop.removeEventListener('click', this, false);
                pop.removeEventListener('popuphidden', this, false);
            }
            var panel = $('editBookmarkPanel');
            if (panel) {
                panel.removeEventListener('popupshowing', this, false);
            }
            this.clearMenus();
 
 
            var placesContext = $("placesContext");
            if (placesContext) {
                placesContext.removeEventListener('popupshowing', this, false);
            }
            var p = $("addbmhere-place");
            if (p) {
                p.parentNode.removeChild(p);
            }
 
            if (SIDEBAR_SUPPORT) {
                var placesContextSide = $S("placesContext");
                if (placesContextSide) {
                    placesContextSide.removeEventListener('popupshowing', AddBMHere, false);
                    delete placesContextSide._add_menu;
                }
                var ps = $S("addbmhere-place");
                if (ps) {
                    ps.parentNode.removeChild(ps);
                }
                try{delete $("sidebar").contentWindow.AddBMHere;}catch(e){}
            }
        },
        clearMenus: function (parent) {
            let menuitems = (parent||document).querySelectorAll(".addbmhere-menu"),
                menuseparators = (parent||document).querySelectorAll(".addbmhere-separator");
            for (let menuitem of menuitems) {
                delete menuitem.parentNode._add_menu_flag;
                menuitem.parentNode.removeChild(menuitem);
            }
            for (let menuseparator of menuseparators) {
                delete menuseparator.parentNode._add_menu_flag;
                menuseparator.parentNode.removeChild(menuseparator);
            }
        },
        checkSideBar: function () {//初始会不成功,延迟判定
            if (SIDEBAR_SUPPORT) {
                let win = $("sidebar").contentWindow;
                if(!win.AddBMHere)win.AddBMHere = AddBMHere;
                var placesContextSide = $S("placesContext");
                if (placesContextSide){
                    if(!placesContextSide._add_menu){
                        placesContextSide.addEventListener('popupshowing', AddBMHere, false);
                        AddBMHere.addPlaceMenuSide();
                        placesContextSide._add_menu = true;
                    };
                }
                setTimeout(AddBMHere.checkSideBar, 1000);
            }
        },
        placesNode: null,
        getSideWin: function () {
            return $("sidebar").contentWindow;
        },
        addBookmark(parentNode) {
            //菜单会影响新增书签位置,先删除掉
            AddBMHere.removeMenu(parentNode);
            this.placesNode = parentNode._placesNode;
            PlacesCommandHook.bookmarkPage();
        },
        addBookmarkPlace() {
            this.placesNode = PlacesUIUtils.getViewForNode(window.document.popupNode).selectedNode;
            if (!this.placesNode) {
                try {
                    this.placesNode = window.document.popupNode._placesNode;
                } catch (e) {
                }
            }
            PlacesCommandHook.bookmarkPage();
        },
        addBookmarkPlaceSide() {
            this.placesNode = PlacesUIUtils.getViewForNode(this.getSideWin().document.popupNode).selectedNode;
            if (!this.placesNode) {
                try {
                    this.placesNode = this.getSideWin().document.popupNode._placesNode;
                } catch (e) {
                }
            }
            PlacesCommandHook.bookmarkPage();
        },
        addPlaceMenu: function () {
            let doc = document;
            var inspos = doc.getElementById("placesContext_openSeparator");
            let menuitem = doc.createXULElement("menuitem");
            menuitem.id = "addbmhere-place";
            menuitem.setAttribute("label", MENU_NAME);
            menuitem.setAttribute("oncommand", "window.AddBMHere.addBookmarkPlace();");
            menuitem.setAttribute("image", MENU_ICON);
            menuitem.setAttribute("class", "menuitem-iconic");
            inspos.parentNode.insertBefore(menuitem, inspos);
        },
        addPlaceMenuSide: function () {
            let doc = $("sidebar").contentWindow.document;
            var inspos = doc.getElementById("placesContext_openSeparator");
            let menuitem = doc.createXULElement("menuitem");
            menuitem.id = "addbmhere-place";
            menuitem.setAttribute("label", MENU_NAME);
            menuitem.setAttribute("oncommand", "window.AddBMHere.addBookmarkPlaceSide();");
            menuitem.setAttribute("image", MENU_ICON);
            menuitem.setAttribute("class", "menuitem-iconic");
            inspos.parentNode.insertBefore(menuitem, inspos);
        },
        addMenu: function (parentNode) {
            if (!parentNode._add_menu_flag) {
                var firstMenu = parentNode.firstChild;
                while (firstMenu) {
                    if (firstMenu.tagName == "menuitem" || firstMenu.tagName == "menu") break;
                    firstMenu = firstMenu.nextSibling;
                }
                var menuitem = document.createXULElement("menuitem");
 
                menuitem.setAttribute("label", MENU_NAME);
                menuitem.setAttribute("oncommand", "window.AddBMHere.addBookmark(this.parentNode);");
                menuitem.setAttribute("image", MENU_ICON);
                menuitem.setAttribute("class", "menuitem-iconic bookmark-item subviewbutton menuitem-with-favicon addbmhere-menu");
 
                parentNode._add_menu_flag = "1";
 
                parentNode.insertBefore(menuitem, firstMenu);
 
                var menuseparator = document.createXULElement("menuseparator");
                menuseparator.setAttribute("class", "bookmarks-actions-menuseparator addbmhere-separator");
                parentNode.insertBefore(menuseparator, firstMenu);
 
            }
        },
        removeMenu: function (parentNode) {
            if (parentNode._add_menu_flag) {
                let menuitem = parentNode.querySelector(".addbmhere-menu"),
                    menuseparator = parentNode.querySelector(".addbmhere-separator");
                if (menuitem) {
                    menuitem.parentNode.removeChild(menuitem);
                }
                if (menuseparator) {
                    menuseparator.parentNode.removeChild(menuseparator);
                }
                delete parentNode._add_menu_flag;
            }
        },
        handleEvent: function (event) {
            if (event.type == "popuphidden") {
                //为保证其他方式添加书签不收影响,隐藏时清除所有添加的菜单
                this.clearMenus(event.target);
                return;
            }
            if (event.target.id == "placesContext") {
                var isFloder = false;
                try {
                    let selectedNode = PlacesUIUtils.getViewForNode(event.target.ownerDocument.popupNode).selectedNode;
                    isFloder = !selectedNode || selectedNode.hasChildren;
                } catch (e) {
                    alert(e.message);
                }
                let menus = event.target.querySelectorAll("#addbmhere-place");
                for (let menu of menus) {
                    if (isFloder) {
                        menu.hidden = false;
                        menu.disabled = false;
                    } else {
                        menu.hidden = true;
                    }
                }
                return;
            }
            if (event.target.tagName == "panel") {
                setTimeout(function () {
                    gEditItemOverlay.toggleFolderTreeVisibility();
                    if (AddBMHere.placesNode) {
                        var panel = $('editBookmarkPanel');
                        //自动隐藏添加面板
                        if (AUTO_ADD) {
                            panel.setAttribute("style", "opacity:0");
                        }
                        var folderGuid = PlacesUtils.getConcreteItemGuid(AddBMHere.placesNode);
                        var folderItem = gEditItemOverlay._getFolderMenuItem(folderGuid, AddBMHere.placesNode.title);
                        gEditItemOverlay._folderMenuList.selectedItem = folderItem;
                        folderItem.doCommand();
                        AddBMHere.placesNode = null;
                        if (AUTO_ADD) {
                            setTimeout(function () {
                                panel.removeAttribute("style");
                                StarUI.panel.hidePopup();
                            }, 100);
                        }
                    }
                }, 1);
            } else {
                var menupopup;
                if (event.target.tagName == 'menu') {
                    menupopup = event.target.menupopup;
                } else if (event.target.tagName == 'menupopup') {
                    menupopup = event.target;
                } else return;
                if (!menupopup) return;
 
                AddBMHere.addMenu(menupopup);
 
            }
        }
    };
 
    AddBMHere.init();
    window.AddBMHere = AddBMHere;
 
    function $(id) {
        return document.getElementById(id);
    }
 
    function $S(id) {
        try {
            return $("sidebar").contentWindow.document.getElementById(id);
        } catch (e) {
            return null;
        }
    }
 
})();
cambriancn
小狐狸
小狐狸
  • UID57310
  • 注册日期2019-10-10
  • 最后登录2022-10-05
  • 发帖数28
  • 经验30枚
  • 威望0点
  • 贡献值16点
  • 好评度1点
1楼#
发布于:2020-05-10 12:19
etjim
火狐狸
火狐狸
  • UID30046
  • 注册日期2009-08-12
  • 最后登录2023-02-02
  • 发帖数161
  • 经验224枚
  • 威望0点
  • 贡献值56点
  • 好评度13点
  • 忠实会员
  • 社区居民
2楼#
发布于:2020-05-10 17:50
用扩展不好吗?Bookmark Tab Here
cambriancn
小狐狸
小狐狸
  • UID57310
  • 注册日期2019-10-10
  • 最后登录2022-10-05
  • 发帖数28
  • 经验30枚
  • 威望0点
  • 贡献值16点
  • 好评度1点
3楼#
发布于:2020-05-27 21:46
确实不能用了,还是脚本好点。扩展很突兀
goldbug
小狐狸
小狐狸
  • UID56123
  • 注册日期2017-11-20
  • 最后登录2023-01-19
  • 发帖数30
  • 经验39枚
  • 威望0点
  • 贡献值36点
  • 好评度0点
  • 社区居民
  • 忠实会员
4楼#
发布于:2020-06-18 16:40
扩展:quickly bookmark this page

有扩展能实现的,为何要用UC脚本?扩展做不到的,用UC脚本才是合理的。
crisco
小狐狸
小狐狸
  • UID57196
  • 注册日期2019-07-17
  • 最后登录2021-03-08
  • 发帖数13
  • 经验28枚
  • 威望0点
  • 贡献值16点
  • 好评度1点
  • 社区居民
5楼#
发布于:2020-08-14 08:09
同求修复。类似的扩展都不怎么好用。
Firefox...
crisco
小狐狸
小狐狸
  • UID57196
  • 注册日期2019-07-17
  • 最后登录2021-03-08
  • 发帖数13
  • 经验28枚
  • 威望0点
  • 贡献值16点
  • 好评度1点
  • 社区居民
6楼#
发布于:2020-08-14 08:10
goldbug:扩展:quickly bookmark this page

有扩展能实现的,为何要用UC脚本?扩展做不到的,用UC脚本才是合理的。
回到原帖
名字是不是错了?找不到这个扩展
Firefox...
jiayiming
火狐狸
火狐狸
  • UID35865
  • 注册日期2011-04-04
  • 最后登录2023-02-02
  • 发帖数175
  • 经验182枚
  • 威望0点
  • 贡献值30点
  • 好评度5点
  • 社区居民
  • 忠实会员
7楼#
发布于:2020-08-15 17:11
goldbug:扩展:quickly bookmark this page

有扩展能实现的,为何要用UC脚本?扩展做不到的,用UC脚本才是合理的。
回到原帖
不是 真有这个扩展吗
goldbug
小狐狸
小狐狸
  • UID56123
  • 注册日期2017-11-20
  • 最后登录2023-01-19
  • 发帖数30
  • 经验39枚
  • 威望0点
  • 贡献值36点
  • 好评度0点
  • 社区居民
  • 忠实会员
8楼#
发布于:2020-08-16 01:51
crisco:名字是不是错了?找不到这个扩展回到原帖

jiayiming:不是 真有这个扩展吗回到原帖
sorry ,我的错。

扩展名是Default Bookmark Folder。


用太熟悉了,反而搞混扩展名。这个扩展安装后,会在地址栏里附加一个图标,点击一下图标,就能把书签收藏了。而且还可以设置收藏到自定义的目标书签文件夹,也包括收藏到文件夹的最上面或是最底部。

把鼠标移动到图标上,就会有提示“quickly bookmark this page”,我把这个弄混了。
逗妇乳
小狐狸
小狐狸
  • UID50148
  • 注册日期2015-06-01
  • 最后登录2022-11-21
  • 发帖数83
  • 经验89枚
  • 威望0点
  • 贡献值32点
  • 好评度6点
9楼#
发布于:2022-08-09 11:28
游客

返回顶部