1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
import '~/styles/main.scss';
import './misc/i18n';
import React from 'react';
import { createRoot } from 'react-dom/client';
import Modal from 'react-modal';
import App from './App';
import * as swRegistration from './swRegistration';
const rootEl = document.getElementById('app');
const root = createRoot(rootEl);
Modal.setAppElement(rootEl);
root.render(<App />);
swRegistration.register();
// eslint-disable-next-line no-console
console.log('Checkout the repo: https://github.com/MetaCubeX/yacd');
// eslint-disable-next-line no-console
console.log('Version:', __VERSION__);
window.onload = function startup() {
const el = document.getElementById('app');
el.addEventListener('touchstart', onTouchStart, { passive: true });
el.addEventListener('touchmove', onTouchMove, false);
el.addEventListener('touchend', onTouchEnd, false);
};
const touchData = { touching: false, trace: [] };
function onTouchStart(evt) {
if (evt.touches.length !== 1) {
touchData.touching = false;
touchData.trace = [];
return;
}
touchData.touching = true;
touchData.trace = [{ x: evt.touches[0].screenX, y: evt.touches[0].screenY }];
}
function onTouchMove(evt) {
if (!touchData.touching) return;
touchData.trace.push({
x: evt.touches[0].screenX,
y: evt.touches[0].screenY,
});
}
function onTouchEnd() {
if (!touchData.touching) return;
const trace = touchData.trace;
touchData.touching = false;
touchData.trace = [];
handleTouch(trace); //判断touch类型并调用适当回调
}
function handleTouch(trace) {
const tags = ['/', '/proxies', '/rules', '/connections', '/configs', '/logs'];
const start = trace[0];
const end = trace[trace.length - 1];
const tag = window.location.hash.slice(1);
const index = tags.indexOf(tag);
console.log(index, tag, tags.length);
if (index === 3) return;
if (end.x - start.x > 200 && index > 0) {
window.location.hash = tags[index - 1];
} else if (end.x - start.x < -200 && index < tags.length - 1) {
window.location.hash = tags[index + 1];
if (index === -1) {
window.location.hash = tags[index + 2];
}
}
}
|