-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
131 lines (127 loc) · 7.57 KB
/
client.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var canvasEl = document.getElementById("colorCanvas");
var canvasContext = canvasEl.getContext("2d");
function initColorPicker() {
canvasContext.clearRect(0, 0, canvasEl.width, canvasEl.height);
image = new Image(250, 250);
image.onload = () =>
canvasContext.drawImage(image, 0, 0, image.width, image.height);
image.src =
"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHCA0HBw0IBwcHBw0HBwcHBw8ICQcNFREWFhURExMYHSggGBolGxMTITEhMSkrLi4uFx8zODMtNygtLjcBCgoKDQ0NFQ0NFzcZFRkrKysrKystLSsrKysrLS0rKysrKysrKysrKys3NysrKysrKysrKysrKysrKystKysrLf/AABEIAOEA4QMBIgACEQEDEQH/xAAaAAACAwEBAAAAAAAAAAAAAAACAwAEBQEG/8QAHxAAAwACAwEBAQEAAAAAAAAAAAECAwQREiExgSIy/8QAGwEAAgMBAQEAAAAAAAAAAAAABAUCAwYAAQf/xAAeEQEAAgMBAQEBAQAAAAAAAAAAAQIDBBIhETEiQf/aAAwDAQACEQMRAD8A85pv4bmm/hgaj+G3pv4ZHYh9S2rPQ6dfDc06+HntOjb06+CPYqze1L0GtX8/gGahetX8/gGaxXFf6ZvbIzUUM1FjNRRzUGY6sruR+q+aip29HZqKnb0Pwx7DLbVfVmaHTRUmhs0aTTj8AWqtzQ6aKk0NmjVaf+KLVBuUYW5Rr7dGJuM0evI3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O7E7CexOx67k10cbF9jnYl9e8jbBbOcnOT369+OkOckPekhcneQOScnnT36ZyTkDknJ31LofJOQOSckfr3oXJOQeSckXdC5IDyQ747oJCEPVaEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5yEIQ5z/9k=";
}
//
let mouss = document.getElementById("cur");
el = document.body.getBoundingClientRect();
function eventx(x, y) {
mouss.style.left = x - 6 + "px";
mouss.style.top = y - 6 + "px";
}
eventx(canvasEl.offsetLeft + 240, canvasEl.offsetTop + 40);
// check if mouse pressed
let mEnter = false;
let clik = false;
let touch = false;
canvasEl.onmouseover = function () {
mEnter = false;
};
canvasEl.onmouseenter = function () {
mEnter = true;
};
canvasEl.onmousedown = function (mouseEvent) {
clik = true;
eventx(mouseEvent.clientX, mouseEvent.clientY);
var imgData = canvasContext.getImageData(
mouseEvent.offsetX,
mouseEvent.offsetY,
1,
1
);
var rgba = imgData.data;
let color = "rgb(" + rgba[0] + "," + rgba[1] + "," + rgba[2] + ")";
inner(color);
};
canvasEl.onmouseup = function () {
clik = false;
};
window.onmouseup = function () {
clik = false;
};
canvasEl.onmousemove = function (mouseEvent) {
if (clik && mEnter) {
eventx(mouseEvent.clientX, mouseEvent.clientY);
var imgData = canvasContext.getImageData(
mouseEvent.offsetX,
mouseEvent.offsetY,
1,
1
);
var rgba = imgData.data;
let color = "rgb(" + rgba[0] + "," + rgba[1] + "," + rgba[2] + ")";
inner(color);
}
};
//touth
canvasEl.ontouchstart = function (mouseEvent) {
touch = true;
eventx(mouseEvent.touches[0].clientX, mouseEvent.touches[0].clientY);
var imgData = canvasContext.getImageData(
mouseEvent.touches[0].clientX - canvasEl.offsetLeft,
mouseEvent.touches[0].clientY - canvasEl.offsetTop,
1,
1
);
var rgba = imgData.data;
let color = "rgb(" + rgba[0] + "," + rgba[1] + "," + rgba[2] + ")";
inner(color);
};
canvasEl.ontouchend = function () {
touch = false;
};
canvasEl.ontouchmove = function (mouseEvent) {
if (touch) {
eventx(mouseEvent.touches[0].clientX, mouseEvent.touches[0].clientY);
var imgData = canvasContext.getImageData(
mouseEvent.touches[0].clientX - canvasEl.offsetLeft,
mouseEvent.touches[0].clientY - canvasEl.offsetTop,
1,
1
);
var rgba = imgData.data;
let color = "rgb(" + rgba[0] + "," + rgba[1] + "," + rgba[2] + ")";
inner(color);
}
};
function print(msg) {
console.log(msg);
}
initColorPicker();
function inner(color) {
console.log(typeof color, color.toString())
var hexReplacing = color.slice(3).split("(")[1].split(")")[0]
var hexColor = "#" + hexReplacing.split(",").map((x) => {
const j = parseInt(x).toString(16)
return (j.length==1) ? "0"+ j : j
}).join("");
console.log(hexReplacing)
document.getElementById("text").value = hexColor;
document.getElementById("text").style.backgroundColor = color;
document.getElementById("copy").style.backgroundColor = color;
document.getElementById("vars").innerHTML = ` :root{
--colorMain:${color};
}`;
}
function copyz() {
document.getElementById("text").select();
document.execCommand("copy");
sconfirm();
}
function sconfirm() {
let div = document.getElementById("pop");
div.className = "active";
setTimeout(() => {
div.className = "pop";
}, 600);
}
window.addEventListener("resize", function () {
eventx(canvasEl.offsetLeft + 240, canvasEl.offsetTop + 40);
inner("rgb(215,0,41)");
});