paul_guo
小狐狸
小狐狸
  • UID45016
  • 注册日期2014-03-13
  • 最后登录2024-04-11
  • 发帖数44
  • 经验52枚
  • 威望0点
  • 贡献值46点
  • 好评度1点
阅读:2237回复:8

求教一下这个鼠标手势脚本怎么去掉轨迹显示呢?

楼主#
更多 发布于:2018-01-10 15:22

尝试着修改了一下,发现不知道怎么去掉轨迹显示,来求教一下,谢谢大家

// ==UserScript==
// @name                 Mousegestures.uc.js
// @namespace            Mousegestures@gmail.com
// @description          自定义鼠标手势,自用 DIY版
// @author               紫云飞&黒仪大螃蟹
// @homepageURL          http://www.cnblogs.com/ziyunfei/archive/2011/12/15/2289504.html
// @include              chrome://browser/content/browser.xul
// @charset              UTF-8
// ==/UserScript==
(() => {
    'use strict';
    let ucjsMouseGestures = {
        lastX: 0,
        lastY: 0,
        directionChain: '',
        isMouseDownL: false,
        isMouseDownR: false,
        hideFireContext: false,
        shouldFireContext: false,
        GESTURES: {
            'L': {name: '后退', cmd: () => getWebNavigation().canGoBack && getWebNavigation().goBack()},
            'R': {name: '前进', cmd: () => getWebNavigation().canGoForward && getWebNavigation().goForward()},


            'U': {name: '向上滚动', cmd: () => goDoCommand('cmd_scrollPageUp')},
            'D': {name: '向下滚动', cmd: () => goDoCommand('cmd_scrollPageDown')},


            'UD': {name: '刷新当前页面', cmd: function() {document.getElementById("Browser:Reload").doCommand();}},



            'LU': {name: '转到页首', cmd: () => goDoCommand('cmd_scrollTop')},
            'LD': {name: '转到页尾', cmd: () => goDoCommand('cmd_scrollBottom')},
        },


        init: function() {
            let self = this;
            ['mousedown', 'mousemove', 'mouseup', 'contextmenu', 'DOMMouseScroll'].forEach(type => {
                gBrowser.mPanelContainer.addEventListener(type, self, true);
            });
            gBrowser.mPanelContainer.addEventListener('unload', () => {
                ['mousedown', 'mousemove', 'mouseup', 'contextmenu', 'DOMMouseScroll'].forEach(type => {
                    gBrowser.mPanelContainer.removeEventListener(type, self, true);
                });
            }, false);
        },
        handleEvent: function(event) {
            switch (event.type) {
            case 'mousedown':
                if (event.button == 2) {
                    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.createElement('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;';
                        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.boxObject.screenX, this.lastY - gBrowser.selectedBrowser.boxObject.screenY);
                        this.xdTrailAreaContext.lineTo(event.screenX - gBrowser.selectedBrowser.boxObject.screenX, event.screenY - gBrowser.selectedBrowser.boxObject.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;
                        XULBrowserWindow.statusTextField.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(() => XULBrowserWindow.statusTextField.label = '', 2000);
            this.hideFireContext = true;
        }
    };
    ucjsMouseGestures.init();
})();
taoww
非常火狐
非常火狐
  • UID39284
  • 注册日期2013-03-18
  • 最后登录2024-04-15
  • 发帖数625
  • 经验571枚
  • 威望0点
  • 贡献值110点
  • 好评度99点
1楼#
发布于:2018-01-10 16:28
最简单的改法,把
if (!this.xdTrailArea) {
改成
if (!this.xdTrailArea && false) {
paul_guo
小狐狸
小狐狸
  • UID45016
  • 注册日期2014-03-13
  • 最后登录2024-04-11
  • 发帖数44
  • 经验52枚
  • 威望0点
  • 贡献值46点
  • 好评度1点
2楼#
发布于:2018-01-11 08:54
taoww:最简单的改法,把
if (!this.xdTrailArea) {
改成
if (!this.xdTrailArea && false) {
回到原帖
尝试了一下,这么改似乎是没用的、、、
taoww
非常火狐
非常火狐
  • UID39284
  • 注册日期2013-03-18
  • 最后登录2024-04-15
  • 发帖数625
  • 经验571枚
  • 威望0点
  • 贡献值110点
  • 好评度99点
3楼#
发布于:2018-01-11 14:28
paul_guo:尝试了一下,这么改似乎是没用的、、、回到原帖
修改不是即时生效的喔,你要重启firefox才行
paul_guo
小狐狸
小狐狸
  • UID45016
  • 注册日期2014-03-13
  • 最后登录2024-04-11
  • 发帖数44
  • 经验52枚
  • 威望0点
  • 贡献值46点
  • 好评度1点
4楼#
发布于:2018-01-11 23:06
taoww:修改不是即时生效的喔,你要重启firefox才行回到原帖
显然我是知道这个的。。。
paul_guo
小狐狸
小狐狸
  • UID45016
  • 注册日期2014-03-13
  • 最后登录2024-04-11
  • 发帖数44
  • 经验52枚
  • 威望0点
  • 贡献值46点
  • 好评度1点
5楼#
发布于:2018-01-12 08:51
taoww:修改不是即时生效的喔,你要重启firefox才行回到原帖
查明白了,有用,但是需要删除startupCache再启动才可以
视线之外
小狐狸
小狐狸
  • UID51003
  • 注册日期2015-08-25
  • 最后登录2023-08-30
  • 发帖数4
  • 经验8枚
  • 威望0点
  • 贡献值14点
  • 好评度0点
6楼#
发布于:2022-01-12 10:16
taoww:最简单的改法,把
if (!this.xdTrailArea) {
改成
if (!this.xdTrailArea && false) {
回到原帖
改了之后,会导致一些手势失效,该怎么办啊?
edit_check
小狐狸
小狐狸
  • UID57451
  • 注册日期2020-02-02
  • 最后登录2022-10-22
  • 发帖数3
  • 经验3枚
  • 威望0点
  • 贡献值0点
  • 好评度2点
7楼#
发布于:2022-01-13 01:29
// @include              chrome://browser/content/browser.xul



Seeing that, what version of firefox are you using ? that script is for a very old version.


I can not check (i have the last version of firefox), but maybe you need to do some like, remove:


if (!this.xdTrailArea) {
    this.xdTrailArea = document.createElement('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;';
    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.boxObject.screenX, this.lastY - gBrowser.selectedBrowser.boxObject.screenY);
    this.xdTrailAreaContext.lineTo(event.screenX - gBrowser.selectedBrowser.boxObject.screenX, event.screenY - gBrowser.selectedBrowser.boxObject.screenY);
    this.xdTrailAreaContext.closePath();
    this.xdTrailAreaContext.stroke();
    this.lastX = event.screenX;
    this.lastY = event.screenY;
}
and remove
if (this.xdTrailArea) {
                this.xdTrailArea.parentNode.removeChild(this.xdTrailArea);
                this.xdTrailArea = null;
                this.xdTrailAreaContext = null;
            }
fire/fox
火狐狸
火狐狸
  • UID32624
  • 注册日期2010-04-21
  • 最后登录2024-04-14
  • 发帖数172
  • 经验169枚
  • 威望0点
  • 贡献值182点
  • 好评度9点
  • 社区居民
  • 忠实会员
8楼#
发布于:2022-01-14 14:06
我倒是喜欢轨迹显示,画起来感觉有交互性
游客

返回顶部