-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
72 lines (59 loc) · 2.29 KB
/
main.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
/**
* identicon 2.0.0
* http://github.com/Rajveer2009/identicon/
*
* Libraries
* elrumordelaluz/svgson, mathiasbynens/utf8.js,
* mathiasbynens/base64, stewartlord/identicon.js
*
* Copyright (c) 2022 Rajveer Singh Saggu, https://rajveer2009.github.io/ <rajveersinghsaggu2009@proton.me>
* Released under the MIT license
* https://rajveer2009.github.io/LICENSE/
*/
function Genrate() {
// Random "hash"
hash = String(Math.floor(Math.random() * 10000000000000000));
// Options for the Identicon
var options = {
background: [240, 240, 240, 255],
margin: 0.2,
size: 420,
format: 'svg'
};
// Genrate the Identicon
var data = new Identicon(hash, options).toString();
// Decode the base64 ecoded svg data of the Identicon to get the color value
var bytes = base64.decode(data);
var text = utf8.decode(bytes);
svgson.parse(String(text)).then((json) => {
style = json.children[0].attributes.style
var myArr = String(style).split("").map((style) => {
return String(style)
})
if (myArr[21] == ")") {
color = myArr[10] + myArr[11] + myArr[12] + myArr[13] + myArr[14] + myArr[15] + myArr[16] + myArr[17] + myArr[18] + myArr[19] + myArr[20]
}
else {
color = myArr[10] + myArr[11] + myArr[12] + myArr[13] + myArr[14] + myArr[15] + myArr[16] + myArr[17] + myArr[18] + myArr[19] + myArr[20] + myArr[21]
}
// Logging the values of the "Seeed" and Color in the Console
console.log("seeed: " + hash);
console.log("color: rgba[" + color + "]");
// Setting the Color value and "Hash" value to a paragraph tag
document.write('<a href="javascript:location.reload()" style="text-decoration: none; font-size:16px; color: rgb(' + color + ')">' + hash + '</a>');
});
// Writing the Identicon to an image
document.write('<img width=420px height=420px onclick="copy()" src="data:image/svg+xml;base64,' + data + '">');
document.write('<br>');
}
function copy() {
// Defining the variable for the text field
var copyText = hash;
// Copy the text inside the text field
navigator.clipboard.writeText(copyText).then(
function() {
window.location = "convert.html"
}
)
}
Genrate()