Tianwenw
小狐狸
小狐狸
  • UID56833
  • 注册日期2019-01-16
  • 最后登录2025-01-20
  • 发帖数4
  • 经验5枚
  • 威望0点
  • 贡献值4点
  • 好评度0点
  • 社区居民
阅读:315回复:1

从 133 升级到 134,手势脚本 Mousegestures.uc.js 不能用了

楼主#
更多 发布于:2025-01-20 23:03
昨天从 133 升级到 134,鼠标手势完全没反应,连轨迹都不显示,请大佬指点!

Mousegestures.uc.js 脚本如下:
// ==UserScript==
// @name                 Mousegestures.uc.js
// @namespace            Mousegestures@gmail.com
// @description          自定义鼠标手势
// @author               紫云飞&黒仪大螃蟹
// @homepageURL          http://www.cnblogs.com/ziyunfei/archive/2011/12/15/2289504.html
// @include              chrome://browser/content/browser.xhtml
// @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: () => document.getElementById("Browser:Back").doCommand()},
            'R': {name: '前进', cmd: () => document.getElementById("Browser:Forward").doCommand()},
 
            'U': {name: '转到页首', cmd: () => goDoCommand('cmd_scrollTop')},
            'D': {name: '转到页尾', cmd: () => goDoCommand('cmd_scrollBottom')},
 
            'UD': {name: '刷新当前页面', cmd: function() {document.getElementById("Browser:Reload").doCommand();}},
            'UDU': {name: '跳过缓存刷新当前页面', cmd: function() {document.getElementById("Browser:ReloadSkipCache").doCommand();}},
            'UDUD':{name: ' 刷新所有页面 ', cmd: function () {gBrowser.visibleTabs.forEach (tab => {try {gBrowser.getBrowserForTab (tab).reload ();} catch (e){}});}},
            'DU': {name: '添加/移除书签', cmd:  function() {document.getElementById("Browser:AddBookmarkAs").doCommand(); } },
         
            'RU': {name: '网址根目录', cmd:  function() { gBrowser.loadURI("javascript:document.location.href=window.location.origin?window.location.origin+'/':window.location.protocol+'/'+window.location.host+'/'", { triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), });},},
            'LD': {name: '恢复刚关闭的标签页', cmd:  function() { try {  document.getElementById('History:UndoCloseTab').doCommand();} catch (ex) {if ('undoRemoveTab' in gBrowser) gBrowser.undoRemoveTab();    else throw "Session Restore feature is disabled."}  } },
         
          'DL': {name: '关闭左边的标签页', cmd: function(event) {   for (let i = gBrowser.selectedTab._tPos - 1; i >= 0; i--) if (!gBrowser.tabs[i].pinned){ gBrowser.removeTab(gBrowser.tabs[i], {animate: true});}}},
          'DR': {name: '关闭右边的标签页', cmd: function(event) {gBrowser.removeTabsToTheEndFrom(gBrowser.selectedTab); }},
           
            'UL': {name: '复制当前标签页标题和地址',  cmd: function() {var gClipboardHelper = Components.classes['@mozilla.org/widget/clipboardhelper;1'].getService(Components.interfaces.nsIClipboardHelper); var txt="";var url=gBrowser.currentURI.spec;var title=gBrowser.contentTitle;txt+=title+"\n"+url+"\n";gClipboardHelper.copyString(txt);}},
            'UR': {name: '打开WebScrapBook文件夹',  cmd: function(event) {FileUtils.getDir('ProfD',['WebScrapBook']).launch();}},
            'URU': {name: '打开书签工具栏',  cmd: function(event) {    var bar = document.getElementById("PersonalToolbar"); setToolbarVisibility(bar, bar.collapsed); }},
 
      'LDR': {name: '关闭其他标签页', cmd: function(event) {gBrowser.removeAllTabsBut(gBrowser.selectedTab);   }},
      'RDLD': {name: '关闭当前标签', cmd: function(event) {gBrowser.removeCurrentTab();}},
      'RDL': {name: '关闭当前标签且不提示', cmd: function(event) {gBrowser.removeCurrentTab({ skipPermitUnload: true });}},     
 
      'LDL': {name: '关闭所有标签页', cmd:  function(event) {gBrowser.removeAllTabsBut(gBrowser.mCurrentTab); gBrowser.removeCurrentTab();}},
 
            'RDR': {name: ' 打开新标签 ', cmd: function (event) {    BrowserCommands.openTab (); }},
             
            'RUL': {name: '添加到稍后阅读',  cmd: function(event) {document.getElementById("pageAction-urlbar-_cd7e22de-2e34-40f0-aeff-cec824cbccac_").click();}},
             
            'URD': {name: '百度站内搜',  cmd: function(event) {gBrowser.loadURI("javascript:var%20Bar=location.host+%22%22;q%20=%20%22%22%20+%20(window.getSelection%20?%20window.getSelection()%20:%20document.getSelection%20?%20document.getSelection()%20:%20document.selection.createRange().text);%20if%20(!q)%20q%20=%20prompt(%22%5Cu8BF7%5Cu8F93%5Cu5165%5Cu641C%5Cu7D22%5Cu7684%5Cu5173%5Cu952E%5Cu8BCD:%22,%20%22%22);%20if%20(q!=null)%20%7Bvar%20qlocation=%22%20%22;qlocation=('http://www.baidu.com/s?&ie=UTF-8&oe=UTF-8&cl=3&rn=100&wd=%20%20'+q+'%20%20%20site:%20'+Bar+'');window.open(qlocation);%7D%20void%200", {triggeringPrincipal: gBrowser.contentPrincipal});}},
            'ULD': {name: '打开本地webui-aria2页面', cmd:  function() {openTrustedLinkIn('file:///D:/Aria2/resources/app/pages/index.html', 'tab');}},
             
            'RDLUR': {name: '重启浏览器', cmd: function(event) {     Services.startup.quit(Services.startup.eAttemptQuit | Services.startup.eRestart);       }}, 
            'RDLUL': {name: '关闭浏览器',  cmd: function(event) {        goQuitApplication();        }},
 
            'LDRU': {name: ' 打开附加组件 ',  cmd: function (event) {    BrowserAddonUI.openAddonsMgr ();    }},
        'RDLU': {name: '打开鼠标手势设置文件',  cmd: function(event) {FileUtils.getDir('UChrm',['userChromeJS', 'MouseGestures.uc.js']).launch();}},
 
        },
 
 
 
        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);
        },
        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: 1 !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 = 5;
                        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();
})();
taoww
非常火狐
非常火狐
  • UID39284
  • 注册日期2013-03-18
  • 最后登录2025-04-21
  • 发帖数662
  • 经验607枚
  • 威望0点
  • 贡献值110点
  • 好评度114点
1楼#
发布于:2025-01-22 14:31
直接把这段脚本放到浏览器工具箱里运行是可以工作的
游客

返回顶部