我制作了一个脚本来注册拇指滚轮事件(如果您想知道,MX Master 2S)。但是,该脚本在 Chrome 中运行得非常好,但在 Firefox (Quantum) 中却没有。为什么呢?
var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
var regex = new RegExp(expression);
var elements = document.getElementsByClassName('pagination'); // get the elements
var search = (elements[0].innerHTML.match(regex));
//alert(search);
if(document.addEventListener){
document.addEventListener("mousewheel", MouseWheelHandler, false);
document.addEventListener("DOMMouseScroll", MouseWheelHandler, false);
} else {
document.attachEvent("onmousewheel", MouseWheelHandler);
}
function MouseWheelHandler(e) {
var e = window.event || e;
var ret = true;
if (e.wheelDelta) {
// Tilt to the left
if (e.wheelDeltaX < 0) {
str = window.location.toString();
strsplit = str.split('/');
preloc=Number(strsplit[4])+1;
if (preloc > 0) {
window.location.replace("https://somepage.com/page/"+preloc);}
prelocstr=preloc.toString();
if (prelocstr == "NaN") {
window.location.replace(search[0]); }
ret = false;
}
// Tilt to the right
if (e.wheelDeltaX > 0) {
str = window.location.toString();
strsplit = str.split('/');
preloc=Number(strsplit[4])-1;
if (preloc > 0) {
window.location.replace("https://somepage.com/page/"+preloc);}
ret = false;
}
}
event.returnValue = ret;
}
这个脚本是在 Tampermonkey 中制作的。谁能指出我的错误?提前致谢!