Skip to content

Commit fc4c318

Browse files
committed
Update searchJumper.user.js
1 parent 60995e9 commit fc4c318

1 file changed

Lines changed: 61 additions & 21 deletions

File tree

SearchJumper/searchJumper.user.js

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,38 @@
10471047
return doc.body || doc.querySelector('body');
10481048
}
10491049

1050+
function clientX(e) {
1051+
if (e.type.indexOf('touch') === 0) {
1052+
return e.changedTouches ? e.changedTouches[0].clientX : 0;
1053+
} else {
1054+
return e.clientX;
1055+
}
1056+
}
1057+
1058+
function clientY(e) {
1059+
if (e.type.indexOf('touch') === 0) {
1060+
return e.changedTouches ? e.changedTouches[0].clientY : 0;
1061+
} else {
1062+
return e.clientY;
1063+
}
1064+
}
1065+
1066+
function pageX(e) {
1067+
if (e.type.indexOf('touch') === 0) {
1068+
return e.changedTouches ? e.changedTouches[0].pageX : 0;
1069+
} else {
1070+
return e.pageX;
1071+
}
1072+
}
1073+
1074+
function pageY(e) {
1075+
if (e.type.indexOf('touch') === 0) {
1076+
return e.changedTouches ? e.changedTouches[0].pageY : 0;
1077+
} else {
1078+
return e.pageY;
1079+
}
1080+
}
1081+
10501082
function getAllElementsByXpath(xpath, contextNode, doc) {
10511083
doc = doc || document;
10521084
contextNode = contextNode || doc;
@@ -2519,6 +2551,7 @@
25192551
color: black;
25202552
white-space: normal;
25212553
max-width: 640px;
2554+
max-width: min(80vw,640px);
25222555
width: max-content;
25232556
line-height: ${35 * this.tipsZoom}px;
25242557
word-break: break-all;
@@ -2529,6 +2562,7 @@
25292562
}
25302563
.search-jumper-tips * {
25312564
max-width: 640px;
2565+
max-width: min(80vw,640px);
25322566
}
25332567
.search-jumper-searchBar>.search-jumper-type {
25342568
padding: 0px;
@@ -3480,7 +3514,7 @@
34803514
bar.classList.remove("initShow");
34813515
};
34823516
let touchHandler = e => {
3483-
if (this.touched) return;
3517+
if (this.touched || this.funcKeyCall) return;
34843518
this.touched = true;
34853519
bar.classList.add('disable-pointer');
34863520
e.stopPropagation();
@@ -9855,7 +9889,18 @@
98559889
}
98569890
}
98579891
}
9892+
let touchend = false;
9893+
ele.addEventListener('touchend', e => {
9894+
if (showTips) {
9895+
touchend = true;
9896+
self.waitForShowTips = true;
9897+
}
9898+
}, false);
98589899
ele.addEventListener('mouseenter', e => {
9900+
if (touchend) {
9901+
touchend = false;
9902+
return;
9903+
}
98599904
showTipsHandler(ele);
98609905
}, false);
98619906
ele.addEventListener('mousemove', e => {
@@ -10375,13 +10420,13 @@
1037510420
let scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
1037610421
let viewHeight = window.innerHeight || document.documentElement.clientHeight;
1037710422
let tileOffset = searchData.prefConfig.tileOffset || 0;
10378-
let clientX = e.pageX - self.bar.clientWidth / 2 - (getComputedStyle(document.documentElement).position !== 'static' ? document.documentElement.offsetLeft : 0);
10423+
let clientX = pageX(e) - self.bar.clientWidth / 2 - (getComputedStyle(document.documentElement).position !== 'static' ? document.documentElement.offsetLeft : 0);
1037910424
if (clientX < 0) clientX = 5;
1038010425
else if (clientX + self.bar.clientWidth > viewWidth + scrollLeft) clientX = viewWidth + scrollLeft - self.bar.clientWidth - 20;
10381-
let clientY = e.pageY;
10382-
if (e.clientY > viewHeight / 5) clientY -= (self.bar.clientHeight + 20 + tileOffset);
10426+
let clientY = pageY(e);
10427+
if (clientY > viewHeight / 5) clientY -= (self.bar.clientHeight + 20 + tileOffset);
1038310428
else clientY += (20 + tileOffset);
10384-
if (e.pageX < viewWidth / 2) {
10429+
if (pageX(e) < viewWidth / 2) {
1038510430
self.bar.style.left = clientX + scrollLeft + "px";
1038610431
self.bar.style.transformOrigin = '0 0';
1038710432
} else {
@@ -11945,22 +11990,6 @@
1194511990
let hideTimer;
1194611991
let touchStart = false;
1194711992

11948-
let clientX = e => {
11949-
if (e.type.indexOf('mouse') === 0) {
11950-
return e.clientX;
11951-
} else {
11952-
return e.changedTouches[0].clientX;
11953-
}
11954-
};
11955-
11956-
let clientY = e => {
11957-
if (e.type.indexOf('mouse') === 0) {
11958-
return e.clientY;
11959-
} else {
11960-
return e.changedTouches[0].clientY;
11961-
}
11962-
};
11963-
1196411993
let mouseUpHandler = e => {
1196511994
clearTimeout(hideTimer);
1196611995
searchBar.bar.classList.remove("grabbing");
@@ -12258,6 +12287,16 @@
1225812287
searchBar.con.classList.add("targetInput");
1225912288
} else searchBar.con.classList.remove("targetInput");
1226012289
}
12290+
if (e.type === "touchend") {
12291+
if (searchData.prefConfig.selectToShow) {
12292+
setTimeout(() => {
12293+
if (getSelectStr()) {
12294+
searchBar.showInPage(true, e);
12295+
} else searchBar.waitForHide(1);
12296+
}, 0);
12297+
}
12298+
return;
12299+
}
1226112300
waitForMouse = true;
1226212301
setTimeout(() => {
1226312302
waitForMouse = false;
@@ -12402,6 +12441,7 @@
1240212441
};
1240312442
document.addEventListener('mousedown', mouseDownHandler);
1240412443
document.addEventListener('dblclick', mouseDownHandler);
12444+
document.addEventListener('touchend', mouseDownHandler);
1240512445
document.addEventListener('contextmenu', e => {
1240612446
if (shown) e.preventDefault();
1240712447
shown = false;

0 commit comments

Comments
 (0)