forked from seths10/Quotes-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (109 loc) · 2.85 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Quotes Generator</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="icons/favicon-32x32.png"
/>
<link rel="stylesheet" href="styles/style.css" />
<link rel="stylesheet" href="styles/popup.css" />
<script src="https://cdn.jsdelivr.net/npm/text-image/dist/text-image.js"></script>
</head>
<body>
<div id="mode">
<i class="far fa-lightbulb" id="modeIcon"></i>
<p id="modeText">Light Mode</p>
</div>
<div class="container">
<div class="header">
<h2>Quote Generator</h2>
</div>
<div class="main-content">
<div class="text-area">
<span class="quote"
>"Life is what happens when you're busy making other plans"</span
>
</div>
<div class="writer">-John Lennon</div>
<div class="button-area">
<div>
<button id="Qbtn" class="allBtn">Generate</button>
<button id="Tbtn" class="allBtn" title="Tweet This!">
<i class="fab fa-twitter"></i>
Tweet This
</button>
<button id="Cbtn" class="allBtn" title="Copy This!">
<i class="fas fa-clipboard"></i>
Copy to Clipboard
</button>
</div>
<div>
<button
id="Cbtn"
class="allBtn"
title="Download This!"
onclick="downloadImage()"
>
<i class="fas fa-clipboard"></i>
Download Image
</button>
</div>
</div>
</div>
</div>
<div class="container-bot">
<div id="snackbar">Copied to clipboard</div>
</div>
<script src="js/quotes.js"></script>
<script src="js/script.js"></script>
<script>
const downloadImage = () => {
let text = document.querySelector('.quote').innerText;
let writer = String(document.querySelector('.writer').innerText);
// Add a line break after 10 words
let words = text.split(' ');
if (words.length > 10) {
let newWords = [];
let line = '';
for (let i = 0; i < words.length; i++) {
if (i % 10 === 0 && i !== 0) {
newWords.push(line);
line = '';
}
line += words[i] + ' ';
}
newWords.push(line);
text = newWords.join('\n');
}
var style = {
font: "'Helvetica Neue'",
align: 'center',
color: 'rgba(0, 0, 0, 1)',
size: 16,
background: 'rgba(255, 255, 255, 1)',
stroke: 0,
strokeColor: 'rgba(0, 0, 255, 1)',
lineHeight: '1.6em',
bold: false,
italic: false,
};
var textImage = TextImage(style);
var data = textImage.toDataURL(text + '\n' + writer, 'image/png', 0.8);
var link = document.createElement('a');
link.download = `${writer
.substring(1, writer.length)
.toLowerCase()}-quote.png`;
link.href = data;
link.click();
};
</script>
</body>
</html>