-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (93 loc) · 2.65 KB
/
index.js
File metadata and controls
93 lines (93 loc) · 2.65 KB
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
let file = document.getElementById("fil");
let img = document.querySelector(".mainImage img");
let butt = document.getElementById("butt");
let ball = document.createElement("div");
let red = new FileReader();
let form = new FormData();
let pl,
filedata,
ret = false,
chakclick = false;
file.addEventListener("input", () => {
filedata = file.files[0];
red.readAsDataURL(filedata);
red.onloadend = () => {
img.src = red.result;
img.style.cssText = "z-index: 2;opacity: 1;";
butt.style.cssText = "opacity: 1;cursor: pointer;";
chakclick = true;
document.querySelector(".upbutt").style.cssText = "opacity: 0;";
};
});
butt.addEventListener("click", () => {
if (chakclick && !ret) {
wait(true);
bakrmov();
} else if (chakclick && ret) {
down();
}
});
function wait(a) {
if (a) {
butt.innerHTML = "Please Wait";
butt.style.cssText = "opacity: 0.2;cursor: not-allowed;";
img.style.cssText = "z-index: 2;opacity: 0;";
ball.classList.add("ball");
let mainIm = document.querySelector(".mainImage");
ball.style.transition = "0.5s";
ball.style.left = `0px`;
ball.style.top = `0px`;
mainIm.appendChild(ball);
chakclick = false;
pl = setInterval(() => {
ball.style.left = `${rand(0, img.clientWidth)}px`;
ball.style.top = `${rand(0, img.clientWidth)}px`;
}, 600);
} else {
clearInterval(pl);
ball.remove();
chakclick = true;
butt.innerHTML = "Download";
img.style.cssText = "z-index: 2;opacity: 1;";
butt.style.cssText = "opacity: 1;cursor: pointer;";
}
}
function rand(min, max) {
max /= 2;
min /= 2;
console.log(Math.floor(Math.random() * (max - min + 1)) + min);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function bakrmov() {
form.append("image_file", filedata);
fetch("https://api.remove.bg/v1.0/removebg", {
method: "POST",
headers: {
"X-Api-Key": "5ifK55bozudfrbVJxCmdjkMJ",
},
body: form,
})
.then((res) => res.blob())
.then((data) => {
red.readAsDataURL(data);
red.onloadend = () => {
img.src = red.result;
img.style.cssText = "z-index: 2;opacity: 1;";
butt.style.cssText = "opacity: 1;cursor: pointer;";
chakclick = true;
ret = true;
wait(false);
};
});
}
function down() {
let fildon = document.createElement("a");
fildon.href = img.src;
fildon.download = "potoA-A-B.png";
console.log("s");
document.body.appendChild(fildon);
fildon.click();
fildon.remove();
}
// key : 5ifK55bozudfrbVJxCmdjkMJ
// add : https://api.remove.bg/v1.0/removebg