-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
71 lines (62 loc) · 1.86 KB
/
scripts.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
function selectSkill(element) {
if (element.classList.contains("selected-tech")) {
element.classList.remove("selected-tech");
} else {
element.classList.add("selected-tech");
}
}
function generateReadme() {
logo = document.getElementById("logo-path").value
title = document.getElementById("title").value
description = document.getElementById("description").value
techList = document.querySelectorAll(".selected-tech")
githubRepo = "https://afsharsharifi.github.io/GithubReadmeGenerator/icons/"
arrIMG = new Array()
for (let index = 0; index < techList.length; index++) {
const element = techList[index];
item = element.firstElementChild
item.width = 40
image_name = item.src.split("/").slice(-1)[0]
new_src = githubRepo + image_name
item.src = new_src
// image = item.outerHTML
// console.log(image);
arrIMG.push(item.outerHTML)
}
let result = `
<div align="center">
<a href="#">
<img src="${logo}" alt="Logo" width="80" height="80">
</a>
<h1>${title}</h1>
</div>
<!-- Project Description -->
<div>
<pre align="center">
${description}
</pre>
</div>
<br>
<br>
<!-- Project Details -->
<div align="center">
<h2>Technologies: </h2>
${arrIMG.slice(Math.max(arrIMG.length - 5, 0)).join(" ")}
</div>
`
return result
}
function copyToClipboard(text) {
const elem = document.createElement('textarea');
elem.value = text;
document.body.appendChild(elem);
elem.select();
document.execCommand('copy');
document.body.removeChild(elem);
}
document.getElementById("update-preview").onclick = function() {
document.getElementById("preview").innerHTML = generateReadme()
}
document.getElementById("copy-preview").onclick = function() {
copyToClipboard(generateReadme())
}