ywzhaiqi / userChromeJS

我原创或修改或自用的 userChromeJS 脚本
337 stars 190 forks source link

SimpleDragModY修复github 拖曳无效的代码可以用在其他脚本上面吗? #10

Closed wenketel closed 10 years ago

wenketel commented 10 years ago
if (direction == "U") {
                        //搜索框搜索选中文字(后台)[识别URL并打开]
                        (/^\s*(?:(?:(?:ht|f)tps?:\/\/)?(?:(?:\w+?)(?:\.(?:[\w-]+?))*(?:\.(?:[a-zA-Z]{2,5}))|(?:(?:\d+)(?:\.\d+){3}))(?::\d{2,5})?(?:\/\S*|$)|data:text\/[\u0025-\u007a]+)\s*$/.test(event.dataTransfer.getData("text/unicode")) && gBrowser.addTab(event.dataTransfer.getData("text/unicode"))) || BrowserSearch.loadSearch(event.dataTransfer.getData("text/unicode"), true);
                        return;
                    }

fix github 拖曳无效的问题 · 64d65ef · ywzhaiqi/userChromeJS

修复github的方法可以用在紫云飞网站生成的EasyDrag.uc.js上面吗?其实我只要上面的代码可以正常使用就可以了.

ywzhaiqi commented 10 years ago

你可以查看我的修改日志,实际上就添加了 dragend 事件。

紫云飞网站生成的 EasyDrag.uc.js 简单修改

    location == "chrome://browser/content/browser.xul" && (function(event) {
        var self = arguments.callee;
        if (!event) {
            ["dragstart", "dragover", "drop", "dragend"].forEach(function(type) {
                gBrowser.mPanelContainer.addEventListener(type, self, false);
            });
            window.addEventListener("unload", function() {
                ["dragstart", "dragover", "drop", "dragend"].forEach(function(type) {
                    gBrowser.mPanelContainer.removeEventListener(type, self, false);
                });
            }, false);
            return;
        }
        switch (event.type) {
        case "dragstart":
            {
                self.startPoint = [event.screenX, event.screenY];
                self.sourceNode = event.target;
                event.target.localName == "img" && event.dataTransfer.setData("application/x-moz-file-promise-url", event.target.src);
                break;
            }
        case "dragover":
            {
                self.startPoint && (Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService).getCurrentSession().canDrop = true);
                break;
            }
        case "dragend":
        case "drop":
            {
                if (self.startPoint && event.target.localName != "textarea" && (!(event.target.localName == "input" && (event.target.type == "text" || event.target.type == "password"))) && event.target.contentEditable != "true") {
                    event.preventDefault();
                    event.stopPropagation();
                    var [subX, subY] = [event.screenX - self.startPoint[0], event.screenY - self.startPoint[1]];
                    var [distX, distY] = [(subX > 0 ? subX : (-subX)), (subY > 0 ? subY : (-subY))];
                    var direction;
                    if (distX > distY) direction = subX < 0 ? "L" : "R";
                    else direction = subY < 0 ? "U" : "D";
                    if (event.dataTransfer.types.contains("application/x-moz-file-promise-url")) {} else if (event.dataTransfer.types.contains("text/x-moz-url")) {} else {
                        //搜索框搜索选中文字(前台)
                        gBrowser.selectedTab = gBrowser.addTab();
                        BrowserSearch.loadSearch(event.dataTransfer.getData("text/unicode"), false);
                    }
                    self.startPoint = 0;
                }
            }
        }
    })()
wenketel commented 10 years ago

用BeyondCompare找到修改了的地方然后复制过去,现在已经可以在github搜索了, 但是在普通页面拖拽文字搜索会出现2个窗口了。 编辑:貌似要加上self.startPoint = 0;? 我试试 成功了,感谢。