Skip to content

Commit a236c10

Browse files
committed
add mouse gesture
1 parent 74f75fd commit a236c10

1 file changed

Lines changed: 57 additions & 8 deletions

File tree

HacgGodTurn/HacgGodTurn.user.js

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
// @include http*://sleazyfork.org/*/scripts/*
7979
// @include http*://greasyfork.org/*/scripts/*
8080
// @include http*://*yfork.org/*/forum/*discussion*
81-
// @version 3.22.05
81+
// @version 3.22.06
8282
// @grant GM_notification
8383
// @grant GM_xmlhttpRequest
8484
// @grant GM_setClipboard
@@ -1422,14 +1422,9 @@
14221422
}
14231423
});
14241424
});
1425-
if(!GM_getValue("hazukashii")){
1426-
p.then(playSound, function(e) {
1427-
console.error(e);
1428-
});
1429-
}
14301425
var command=[72,65,90,85,75,65,83,72,73,73],index=0;//"hazukashii"
14311426
document.addEventListener("keydown", function(e) {
1432-
if(e.keyCode == command[index]) {
1427+
if(e.keyCode==command[index]) {
14331428
if(index==command.length-1){
14341429
index=0;
14351430
var nowValue=GM_getValue("hazukashii");
@@ -1446,6 +1441,60 @@
14461441
index=0;
14471442
}
14481443
});
1449-
GM_notification(notificationDetails);
1444+
1445+
const minLength=256,tg=0.5;
1446+
var lastX, lastY, signs, lastSign;
1447+
function tracer(e) {
1448+
let curX=e.clientX,curY=e.clientY;
1449+
let distanceX=curX-lastX,distanceY=curY-lastY;
1450+
let distance=distanceX*distanceX+distanceY*distanceY;
1451+
if (distance>minLength) {
1452+
lastX=curX;
1453+
lastY=curY;
1454+
let direction="";
1455+
let slope=Math.abs(distanceY/distanceX);
1456+
if(slope>tg){
1457+
if(distanceY>0) {
1458+
direction="↓";
1459+
}else{
1460+
direction="↑";
1461+
}
1462+
}else if(slope<=1/tg) {
1463+
if(distanceX>0) {
1464+
direction="→";
1465+
}else{
1466+
direction="←";
1467+
}
1468+
}
1469+
if(lastSign!=direction) {
1470+
signs+=direction;
1471+
lastSign=direction;
1472+
}
1473+
}
1474+
};
1475+
document.addEventListener("mousedown", function(e) {
1476+
lastX=e.clientX;
1477+
lastY=e.clientY;
1478+
lastSign=signs="";
1479+
document.addEventListener("mousemove", tracer, false);
1480+
}, false);
1481+
document.addEventListener("mouseup", function(e) {
1482+
document.removeEventListener("mousemove", tracer, false);
1483+
if(signs=="↓→↑←"){
1484+
e.stopPropagation();
1485+
e.preventDefault();
1486+
if(window.confirm("\u662f\u5426\u7981\u7528\u7f9e\u803b\u0070\u006c\u0061\u0079\u8bed\u97f3\uff1f")){
1487+
GM_setValue("hazukashii", true);
1488+
}else{
1489+
GM_setValue("hazukashii", false);
1490+
}
1491+
}
1492+
}, false);
1493+
if(!GM_getValue("hazukashii")){
1494+
p.then(playSound, function(e) {
1495+
console.error(e);
1496+
});
1497+
GM_notification(notificationDetails);
1498+
}
14501499
}
14511500
})();

0 commit comments

Comments
 (0)