阅读:1811回复:4
[已解决] linux 上使用 contextHideOnClick.uc.js 屏蔽右键菜单的问题
linux 系统的右键菜单是按下右键就实时弹出来的,所以要用到 contextHideOnClick.uc.js 这个屏蔽右键菜单的脚本,才能正常使用鼠标手势的脚本。
但这样就没有右键菜单了,有没有办法可以按住某个键比如 alt,就能正常弹出右键菜单呢? contextHideOnClick.uc.js: // ==UserScript== // @name Context Menu - Hide on Click // @author xiaoxiaoflood // @include main // @startup UC.contextHideOnClick.exec(win); // @shutdown UC.contextHideOnClick.destroy(); // @onlyonce // ==/UserScript== UC.contextHideOnClick = { initNSMouseEvent_orig: MouseEvent.prototype.initNSMouseEvent, exec: function (win) { win.MouseEvent.prototype.initNSMouseEvent = function () { if (arguments[0] === 'contextmenu' && arguments[13] === 2) { arguments[5] += 2; arguments[6] += 2; } return UC.contextHideOnClick.initNSMouseEvent_orig.apply(this, arguments); } }, destroy: function () { _uc.windows((doc, win) => { win.MouseEvent.prototype.initNSMouseEvent = this.initNSMouseEvent_orig; }); delete UC.contextHideOnClick; } } |
|
1楼#
发布于:2022-03-08 10:21
发现我这个鼠标手势也可以屏蔽右键菜单,但不知道怎么才能用快捷键取消屏蔽。
16行:hideFireContext: true, //==UserScript== // @name Mousegestures.uc.js // @description Mouse gestures // @include chrome://browser/content/browser.xhtml // @charset UTF-8 //==/UserScript== (() => { 'use strict'; let ucjsMouseGestures = { lastX: 0, lastY: 0, directionChain: '', isMouseDownL: false, isMouseDownR: false, hideFireContext: true, shouldFireContext: false, GESTURES: { 'L': {name: '后退', cmd: () => gBrowser.webNavigation.canGoBack && gBrowser.webNavigation.goBack()}, 'R': {name: '前进', cmd: () => gBrowser.webNavigation.canGoForward && gBrowser.webNavigation.goForward()}, 'UD': {name: '刷新', cmd: function() { document.getElementById("Browser:Reload").doCommand();}}, 'DU': {name: '停止', cmd: function() { document.getElementById("Browser:Stop").doCommand();}}, 'RL': {name: '主页', cmd: function() { BrowserHome(); }}, 'U': {name: '新建标签', cmd: function() { BrowserOpenTab(); }}, 'D': {name: '新标签页打开', cmd: function() { gBrowser.selectedBrowser.messageManager.sendAsyncMessage('chromeToContent', 'open-link'); }}, 'DR': {name: '关闭标签页', cmd: function(event) { gBrowser.removeCurrentTab(); }}, 'DL': {name: '恢复关闭的标签页', cmd: function() { try { document.getElementById('History:UndoCloseTab').doCommand(); } catch (ex) { if ('undoRemoveTab' in gBrowser) gBrowser.undoRemoveTab(); else throw "Session Restore feature is disabled." } } }, 'RU': {name: '页首', cmd: () => goDoCommand('cmd_scrollTop')}, 'RD': {name: '页尾', cmd: () => goDoCommand('cmd_scrollBottom')}, 'UL': {name: '上一个标签页', cmd: function(event) { gBrowser.tabContainer.advanceSelectedTab(-1, true);}}, 'UR': {name: '下一个标签页', cmd: function(event) { gBrowser.tabContainer.advanceSelectedTab(+1, true);}}, }, init: function() { let self = this; ['mousedown', 'mousemove', 'mouseup', 'contextmenu', 'DOMMouseScroll'].forEach(type => { gBrowser.tabpanels.addEventListener(type, self, true); }); gBrowser.tabpanels.addEventListener('unload', () => { ['mousedown', 'mousemove', 'mouseup', 'contextmenu', 'DOMMouseScroll'].forEach(type => { gBrowser.tabpanels.removeEventListener(type, self, true); }); }, false); Services.mm.loadFrameScript(this.frameScript, true); Services.mm.addMessageListener('contentToChrome', this.chromeListener); }, chromeListener: function (message) { const { document, gBrowser } = message.target.ownerGlobal; const { cmd, url } = message.data; switch (cmd) { case 'newTab-focus': if(url) { let nuevoTab = gBrowser.addTab(url, { owner: gBrowser.selectedTab, relatedToCurrent: true, triggeringPrincipal: gBrowser.selectedBrowser.contentPrincipal }); // gBrowser.selectedTab = nuevoTab; //Delete this line if wanna background tab } break; } }, frameScript: 'data:application/javascript;charset=UTF-8,' + encodeURIComponent('(' + (function () { let clickedElement; var GetLink = function (e) { ImgSrc = undefined; LnkSrc = undefined; clickedElement = e.target; switch (clickedElement.tagName) { case 'IMG': //Clikeo sobre una imagen ImgSrc = clickedElement.src || clickedElement.currentSrc; //La imagen LnkSrc = clickedElement.parentElement.href || clickedElement.currentSrc; //El link donde va la imagen (url o img) break; case 'AREA': //Deberia ser imagen let uM = clickedElement.ownerDocument.querySelector('[usemap]'); if (uM && uM.useMap == '#' + clickedElement.parentElement.name) ImgSrc = uM.src; break; default: //Caso generico try { LnkSrc = clickedElement.href || clickedElement.parentElement.href || clickedElement.parentElement.parentElement.href || clickedElement.parentElement.parentElement.parentElement.href || clickedElement.parentElement.parentElement.parentElement.parentElement.href; } catch(e) {} break; } } addEventListener('mousedown', GetLink, true); contentListener = function (msg) { switch (msg.data) { case 'open-link': if(typeof LnkSrc != 'undefined') sendAsyncMessage('contentToChrome', {cmd: 'newTab-focus', url: LnkSrc}); break; } } addMessageListener('chromeToContent', contentListener); }).toString() + ')();'), handleEvent: function(event) { switch (event.type) { case 'mousedown': if (event.button == 2) { (gBrowser.mPanelContainer || gBrowser.tabpanels).addEventListener("mousemove", this, false); this.isMouseDownR = true; this.hideFireContext = false; [this.lastX, this.lastY, this.directionChain] = [event.screenX, event.screenY, '']; } if (event.button == 0) { this.isMouseDownR = false; this.stopGesture(); } break; case 'mousemove': if (this.isMouseDownR) { let[subX, subY] = [event.screenX - this.lastX, event.screenY - this.lastY]; let[distX, distY] = [(subX > 0 ? subX : (-subX)), (subY > 0 ? subY : (-subY))]; let direction; if (distX < 10 && distY < 10) return; if (distX > distY) direction = subX < 0 ? 'L' : 'R'; else direction = subY < 0 ? 'U' : 'D'; if (!this.xdTrailArea) { this.xdTrailArea = document.createXULElement('hbox'); let canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'); canvas.setAttribute('width', window.screen.width); canvas.setAttribute('height', window.screen.height); this.xdTrailAreaContext = canvas.getContext('2d'); this.xdTrailArea.style.cssText = '-moz-user-focus: none !important;-moz-user-select: none !important;display: -moz-box !important;box-sizing: border-box !important;pointer-events: none !important;margin: 0 !important;padding: 0 !important;width: 100% !important;height: 100% !important;border: none !important;box-shadow: none !important;overflow: hidden !important;background: none !important;opacity: 0.9 !important;position: fixed !important;z-index: 2147483647 !important; display: inline !important;'; this.xdTrailArea.appendChild(canvas); gBrowser.selectedBrowser.parentNode.insertBefore(this.xdTrailArea, gBrowser.selectedBrowser.nextSibling); } if (this.xdTrailAreaContext) { this.hideFireContext = true; this.xdTrailAreaContext.strokeStyle = '#0065FF'; this.xdTrailAreaContext.lineJoin = 'round'; this.xdTrailAreaContext.lineCap = 'round'; this.xdTrailAreaContext.lineWidth = 3; this.xdTrailAreaContext.beginPath(); this.xdTrailAreaContext.moveTo(this.lastX - gBrowser.selectedBrowser.screenX, this.lastY - gBrowser.selectedBrowser.screenY); this.xdTrailAreaContext.lineTo(event.screenX - gBrowser.selectedBrowser.screenX, event.screenY - gBrowser.selectedBrowser.screenY); this.xdTrailAreaContext.closePath(); this.xdTrailAreaContext.stroke(); this.lastX = event.screenX; this.lastY = event.screenY; } if (direction != this.directionChain.charAt(this.directionChain.length - 1)) { this.directionChain += direction; StatusPanel._label = this.GESTURES[this.directionChain] ? '手势: ' + this.directionChain + ' ' + this.GESTURES[this.directionChain].name : '手势未定义:' + this.directionChain; } } break; case 'mouseup': if (this.isMouseDownR && event.button == 2) { if (this.directionChain) this.shouldFireContext = false; this.isMouseDownR = false; this.directionChain && this.stopGesture(); } break; case 'contextmenu': if (this.isMouseDownR || this.hideFireContext) { this.shouldFireContext = true; this.hideFireContext = false; event.preventDefault(); event.stopPropagation(); } break; case 'DOMMouseScroll': if (this.isMouseDownR) { this.shouldFireContext = false; this.hideFireContext = true; this.directionChain = 'W' + (event.detail > 0 ? '+' : '-'); this.stopGesture(); } break; } }, stopGesture: function() { if (this.GESTURES[this.directionChain]) this.GESTURES[this.directionChain].cmd(); if (this.xdTrailArea) { this.xdTrailArea.parentNode.removeChild(this.xdTrailArea); this.xdTrailArea = null; this.xdTrailAreaContext = null; } this.directionChain = ''; setTimeout(() => StatusPanel._label = '', 2000); this.hideFireContext = true; } }; ucjsMouseGestures.init(); })(); |
|
2楼#
发布于:2022-03-08 13:56
不用搞这么复杂。直接到about:config里面把ui.context_menus.after_mouseup改成true,就是在松开右键时才弹菜单了
|
|
3楼#
发布于:2022-03-08 14:08
|
|
4楼#
发布于:2022-03-11 11:56
mark
|
|