您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
将触摸事件转换为鼠标事件
// ==UserScript== // @name 触屏转鼠标事件 // @version 1.0 // @description 将触摸事件转换为鼠标事件 // @author ChatGPT // @match *://*/* // @grant none // @run-at document-end // @namespace http://greasyfork.icu/users/452911 // ==/UserScript== (function() { 'use strict'; // 创建鼠标事件 function createMouseEvent(type, touchEvent) { return new MouseEvent(type, { bubbles: true, // 事件是否应该冒泡 cancelable: true, // 事件是否可以被取消 view: window, // 事件的视图 clientX: touchEvent.clientX, // 触摸点的水平坐标 clientY: touchEvent.clientY // 触摸点的垂直坐标 }); } // 触摸事件转换为鼠标事件 function touchToMouse(e) { const touches = e.changedTouches; for (let i = 0; i < touches.length; i++) { const touch = touches[i]; const mouseEvent = createMouseEvent( e.type === 'touchstart' ? 'mousedown' : e.type === 'touchend' ? 'mouseup' : 'mousemove', touch ); touch.target.dispatchEvent(mouseEvent); } } // 监听触摸事件并转换为鼠标事件 document.addEventListener('touchstart', touchToMouse, false); document.addEventListener('touchend', touchToMouse, false); document.addEventListener('touchmove', touchToMouse, false); })();