-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
165 lines (151 loc) · 4.24 KB
/
demo.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Kindle Direct Publishing Cover Generator</title>
<style>
#svgOutput {
display: block;
width: 400px;
height: 200px;
}
#saveButton {
display: block;
width: 115px;
height: 25px;
background: #3086b9;
text-align: center;
border-radius: 5px;
color: white;
font-weight: bold;
margin: 10px;
padding: 10px 10px 5px 10px;
display: inline-block;
border-radius: 4px;
text-decoration: none;
font-family: arial;
}
div {
padding: 2px;
}
a {
text-decoration: none;
color: #3086b9;
font-family: arial;
}
h1 {
margin: 4px 0;
font-size: 20px;
}
body {
font-family: arial;
}
</style>
<script src=cover_maker.js></script>
</head>
<body>
<h1><a href=https://github.com/nmrugg/cover>Kindle Direct Publishing SVG cover generator</a></h1>
<div>
<label>
Page Width (in): <input type=text id=pw title="Page width in inches">
</label>
<label>
Page Height (in): <input type=text id=ph title="Page height in inches">
</label>
<label>
Page Count: <input type=text id=pc>
</label>
<label>
Page Type:
<select id=pt>
<option value=white>White</option>
<option value=cream>Cream</option>
<option value=color>Color</option>
</select>
</label>
</div>
<div>
<input type=button id=generate value=Generate>
</div>
<div id=output></div>
</body>
<script>
var pwEl = document.getElementById("pw");
var phEl = document.getElementById("ph");
var pcEl = document.getElementById("pc");
var ptEl = document.getElementById("pt");
var outputEl = document.getElementById("output");
var genEl = document.getElementById("generate");
var params = getParams();
function getParams()
{
var sep1 = location.search.split(/\&|\?/g),
sep2,
params = {},
i,
len;
len = sep1.length;
if (len > 1) {
///NOTE: Skip the first empty element (it's empty because URL's start with a slash).
for (i = 1; i < len; i += 1) {
sep2 = sep1[i].split(/=/);
sep2[0] = decodeURIComponent(sep2[0]);
if (sep2[1]) {
sep2[1] = decodeURIComponent(sep2[1]);
}
if (typeof params[sep2[0]] === "undefined") {
params[sep2[0]] = sep2[1];
} else {
if (typeof params[sep2[0]] !== "object") {
params[sep2[0]] = [params[sep2[0]]];
}
params[sep2[0]].push(sep2[1]);
}
}
}
return params;
}
function gen()
{
var code;
var el;
if (pwEl.value && phEl.value && pcEl.value) {
code = generate(pwEl.value, phEl.value, pcEl.value, ptEl.value);
outputEl.innerHTML = "";
el = document.createElement("a");
el.id = "saveButton";
el.textContent = "Download";
el.href= "data:image/svg+xml;utf8," + code;
el.download = "cover-" + [pwEl.value, phEl.value, pcEl.value, ptEl.value].join("-") + ".svg";
outputEl.appendChild(el);
el = document.createElement("div");
el.textContent = "SVG text:"
outputEl.appendChild(el);
el = document.createElement("textarea");
el.id = "svgOutput";
el.value = code;
outputEl.appendChild(el);
}
}
pwEl.oninput = gen;
phEl.oninput = gen;
pcEl.oninput = gen;
ptEl.oninput = gen;
genEl.onclick = gen;
if (params.pw) {
pwEl.value = params.pw;
}
if (params.ph) {
phEl.value = params.ph;
}
if (params.pc) {
pcEl.value = params.pc;
}
if (params.pt) {
ptEl.value = params.pt;
}
if (params.pw && params.ph && params.pc) {
gen();
}
</script>
</html>