-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (35 loc) · 1.28 KB
/
script.js
File metadata and controls
44 lines (35 loc) · 1.28 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
const boldBtn = document.querySelector("#bold-btn")
const underlineBtn = document.querySelector("#underline-btn")
const italicBtn = document.querySelector("#italic-btn")
const colorBtn = document.querySelector("#color-btn")
const newBtn = document.querySelector("#new-btn")
const txtBtn = document.querySelector("#txt-btn")
const pdfBtn = document.querySelector("#pdf-btn")
const content = document.querySelector("#content")
const filename = document.querySelector("#filename-input")
boldBtn.addEventListener("click", () => {
document.execCommand("bold")
})
underlineBtn.addEventListener("click", () => {
document.execCommand("underline")
})
italicBtn.addEventListener("click", () => {
document.execCommand("italic")
})
colorBtn.addEventListener("input", () => {
document.execCommand("forecolor", false, colorBtn.value)
})
newBtn.addEventListener("click", () => {
content.innerHTML = ""
})
txtBtn.addEventListener("click", () => {
const a = document.createElement("a")
const blob = new Blob([content.innerText])
const dataUrl = URL.createObjectURL(blob)
a.href = dataUrl
a.download = filename.value + ".txt"
a.click()
})
pdfBtn.addEventListener('click', () => {
html2pdf().from(content).save(filename.value)
})