阅读:1475回复:5
求修改右键新标签打开链接脚本
night版上失效了。
(function() { var x = true; // false: 前台 | true: 后台 function $(id) {return document.getElementById(id)}; gBrowser.mPanelContainer.addEventListener('click', function(e) { if (e.button == 2 && !e.ctrlKey) { var onlink = XULBrowserWindow.overLink; var href = e.target.href || e.target.parentNode.href || onlink; if (href && onlink !== "") { if (/^javascript:/i.test(onlink.toString())) return; //e.preventDefault(); e.stopPropagation(); $("contentAreaContextMenu").hidePopup(); gBrowser.moveTabTo(gBrowser.loadOneTab(href, {inBackground: x}), gBrowser.mCurrentTab._tPos + 1); } } }, false); gBrowser.mPanelContainer.addEventListener('contextmenu', function(e) { if (e.button == 2 && !e.ctrlKey) { var onlink = XULBrowserWindow.overLink; var href = e.target.href || e.target.parentNode.href || onlink; if (href && onlink !== "") { if (/^javascript:/i.test(onlink.toString())) return; e.preventDefault(); //e.stopPropagation(); } } }, false); })(); |
|
1楼#
发布于:2018-03-20 13:33
这个自定义手势的脚本也在night上失效了。又没扩展代替
// ==UserScript== // @name Mouse Gestures (with Wheel Gesture and Rocker Gesture) // @namespace http://www.xuldev.org/ // @description 轻量级鼠标手势执行命令. // @include main // @author Gomita // @version 1.0.20080201 // @homepage http://www.xuldev.org/misc/ucjs.php // ==/UserScript== var ucjsMouseGestures = { // about:config enableWheelGestures: true, // 滚轮手势 (Scroll wheel with holding right-click) enableRockerGestures: true, // 摇杆手势 (Left-click with holding right-click and vice versa) _lastX: 0, _lastY: 0, _directionChain: "", _isMac: false, // for Mac init: function() { this._isMac = navigator.platform.indexOf("Mac") == 0; gBrowser.mPanelContainer.addEventListener("mousedown", this, false); gBrowser.mPanelContainer.addEventListener("mousemove", this, false); gBrowser.mPanelContainer.addEventListener("mouseup", this, false); gBrowser.mPanelContainer.addEventListener("contextmenu", this, true); if (this.enableRockerGestures) gBrowser.mPanelContainer.addEventListener("draggesture", this, true); if (this.enableWheelGestures) gBrowser.mPanelContainer.addEventListener("DOMMouseScroll", this, false); }, uninit: function() { gBrowser.mPanelContainer.removeEventListener("mousedown", this, false); gBrowser.mPanelContainer.removeEventListener("mousemove", this, false); gBrowser.mPanelContainer.removeEventListener("mouseup", this, false); gBrowser.mPanelContainer.removeEventListener("contextmenu", this, true); if (this.enableRockerGestures) gBrowser.mPanelContainer.removeEventListener("draggesture", this, true); if (this.enableWheelGestures) gBrowser.mPanelContainer.removeEventListener("DOMMouseScroll", this, false); }, _isMouseDownL: false, _isMouseDownR: false, _suppressContext: false, _shouldFireContext: false, // for Linux handleEvent: function(event) { switch (event.type) { case "mousedown": if (event.button == 2) { this._isMouseDownR = true; this._suppressContext = false; this._startGesture(event); if (this.enableRockerGestures && this._isMouseDownL) { this._isMouseDownR = false; this._suppressContext = true; this._directionChain = "L>R"; this._stopGesture(event); } } else if (this.enableRockerGestures && event.button == 0) { this._isMouseDownL = true; if (this._isMouseDownR) { this._isMouseDownL = false; this._suppressContext = true; this._directionChain = "L<R"; this._stopGesture(event); } } break; case "mousemove": if (this._isMouseDownR) { this._progressGesture(event); } break; case "mouseup": if ((this._isMouseDownR && event.button == 2) || (this._isMouseDownR && this._isMac && event.button == 0 && event.ctrlKey)) { this._isMouseDownR = false; if (this._directionChain) this._suppressContext = true; this._stopGesture(event); if (this._shouldFireContext) { this._shouldFireContext = false; this._displayContextMenu(event); } } else if (this.enableRockerGestures && event.button == 0 && this._isMouseDownL) { this._isMouseDownL = false; } break; case "contextmenu": if (this._suppressContext || this._isMouseDownR) { this._suppressContext = false; event.preventDefault(); event.stopPropagation(); if (this._isMouseDownR) { this._shouldFireContext = true; } } break; case "DOMMouseScroll": if (this.enableWheelGestures && this._isMouseDownR) { event.preventDefault(); event.stopPropagation(); this._suppressContext = true; this._directionChain = "W" + (event.detail > 0 ? "+" : "-"); this._stopGesture(event); } break; case "draggesture": this._isMouseDownL = false; break; } }, _displayContextMenu: function(event) { var evt = event.originalTarget.ownerDocument.createEvent("MouseEvents"); evt.initMouseEvent( "contextmenu", true, true, event.originalTarget.defaultView, 0, event.screenX, event.screenY, event.clientX, event.clientY, false, false, false, false, 2, null ); event.originalTarget.dispatchEvent(evt); }, _startGesture: function(event) { this._lastX = event.screenX; this._lastY = event.screenY; this._directionChain = ""; }, _progressGesture: function(event) { var x = event.screenX; var y = event.screenY; var distanceX = Math.abs(x - this._lastX); var distanceY = Math.abs(y - this._lastY); // minimal movement where the gesture is recognized const tolerance = 10; if (distanceX < tolerance && distanceY < tolerance) return; // determine current direction var direction; if (distanceX > distanceY) direction = x < this._lastX ? "L" : "R"; else direction = y < this._lastY ? "U" : "D"; // compare to last direction 开始比较鼠标的方向 var lastDirection = this._directionChain.charAt(this._directionChain.length - 1); if (direction != lastDirection) { this._directionChain += direction; XULBrowserWindow.statusTextField.label = "\uFEFF\u9F20\u6807\u624B\u52BF:" + this._directionChain; } // save current position 记录鼠标的坐标 this._lastX = x; this._lastY = y; }, _stopGesture: function(event) { try { if (this._directionChain) this._performAction(event); XULBrowserWindow.statusTextField.label = ""; } catch(ex) { XULBrowserWindow.statusTextField.label = ex; } this._directionChain = ""; }, //-------------自定义函数------------// _performAction: function(event) { // 映射. 支持自定义 switch (this._directionChain) { //MouseGesTures默认鼠标手势 //书签保存 case "R" : document.getElementById('menu_bookmarkThisPage').doCommand(); break; //阅读 case "L" :document.getElementById('reader-mode-button').click();; break; // 全文翻译 case "U": gBrowser.loadURI("javascript:{d=document;b=d.body;o=d.createElement('scri'+'pt');o.setAttribute('src','https://translate.google.cn/translate_a/element.js?cb=googleTranslateElementInit');o.setAttribute('type','text/javascript');b.appendChild(o);v=b.insertBefore(d.createElement('div'),b.firstChild);v.id='google_translate_element';v.style.display='none';p=d.createElement('scri'+'pt');p.text='function%20googleTranslateElementInit(){new%20google.translate.TranslateElement({pageLanguage:%22%22},%22google_translate_element%22);}';p.setAttribute('type','text/javascript');b.appendChild(p);}void%200;");break; // 下载 case "D": document.getElementById("Tools:Downloads").doCommand(); break; // 代理 //case "RD": var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); pref.setIntPref("network.proxy.type", pref.getIntPref("network.proxy.type") == 2 ? 5 : 2); break; //case "RU": var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); pref.setIntPref("network.proxy.type", pref.getIntPref("network.proxy.type") == 1 ? 5 : 1); break; //\ //未知的手势 default: throw "\uFEFF\u672A\u77E5\u7684\u9F20\u6807\u624B\u52BF\uFF1A" + this._directionChain; } } }; // エントリポイント ucjsMouseGestures.init(); window.addEventListener("unload", function(){ ucjsMouseGestures.uninit(); }, false); |
|
2楼#
发布于:2018-03-20 14:07
mPanelContainer
替换成 tabpanels mCurrentTab 替换成 selectedTab XULBrowserWindow.statusTextField.label 替换成 StatusPanel._label |
|
3楼#
发布于:2018-03-20 14:31
|
|
4楼#
发布于:2018-03-20 19:49
marb:谢谢。非常见效。请问从什么地方可以知道如何替换呢。要是以后还出现这问题好自己排除一下哦回到原帖看浏览器控制台哪里报错,通过错误提示的一些关键词 查找源码 https://dxr.mozilla.org/mozilla-central/source/ 看源码修改历史记录的 bug, 或者在 bugzilla 上高级搜索这些关键词找到相关 bug , 然后通过提交的补丁反推吧。 |
|
5楼#
发布于:2018-03-20 20:07
lonely_8:看浏览器控制台哪里报错,通过错误提示的一些关键词谢谢了。回来按你的方法试验一下 |
|