-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
115 lines (107 loc) · 3.19 KB
/
index.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="./favicon.ico" />
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<title>Draw N Guess Tools by Vitech</title>
<link rel="stylesheet" href="./assets/style.css">
</head>
<body>
<div class="main">
<div id="zoom"></div>
</div>
</body>
<script>
var ipc = require('electron').ipcRenderer;
(function () {
const { BrowserWindow } = require("@electron/remote");
function initPaste() {
var scale = 1,
panning = false,
pointX = 0,
pointY = 0,
start = { x: 0, y: 0 },
zoom = document.getElementById("zoom");
function setTransform() {
zoom.style.transform = "translate(" + pointX + "px, " + pointY + "px) scale(" + scale + ")";
}
document.addEventListener("paste", (e) => {
var cbd = e.clipboardData;
for (var i = 0; i < cbd.items.length; i++) {
var item = cbd.items[i];
if (item.kind == "file") {
var lastTarget = document.querySelector("#target");
if (lastTarget !== null) {
lastTarget.remove();
}
var blob = item.getAsFile();
if (blob.size === 0) {
return;
}
var reader = new FileReader();
var imgs = new Image();
imgs.id = "target"
imgs.file = blob;
reader.onload = (function (aImg) {
return function (e) {
aImg.src = e.target.result;
};
})(imgs);
reader.readAsDataURL(blob);
document.querySelector("#zoom").appendChild(imgs);
}
}
},
false
);
zoom.addEventListener("mousedown", (e) => {
e.preventDefault();
start = { x: e.clientX - pointX, y: e.clientY - pointY };
panning = true;
});
zoom.addEventListener("mouseup", (e) => {
panning = false;
});
zoom.addEventListener("wheel", (e) => {
e.preventDefault();
var xs = (e.clientX - pointX) / scale,
ys = (e.clientY - pointY) / scale,
delta = (e.wheelDelta ? e.wheelDelta : -e.deltaY);
(delta > 0) ? (scale *= 1.2) : (scale /= 1.2);
pointX = e.clientX - xs * scale;
pointY = e.clientY - ys * scale;
setTransform();
});
zoom.addEventListener("mousemove", (e) => {
e.preventDefault();
if (!panning) {
return;
}
pointX = (e.clientX - start.x);
pointY = (e.clientY - start.y);
setTransform();
});
}
document.onreadystatechange = function () {
if (document.readyState == "complete") {
initPaste();
}
};
ipc.on('asynchronous-reply', (event, arg) => {
let res = JSON.parse(arg)
console.log(res)
switch (res.type) {
case 'changeStatus':
let status = res.data
if (status === 1) {
document.title = '[已锁定]Draw N Guess Tools by Vitech'
} else {
document.title = 'Draw N Guess Tools by Vitech'
}
break;
}
});
})();
</script>
</html>