-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
76 lines (73 loc) · 3.27 KB
/
index.html
File metadata and controls
76 lines (73 loc) · 3.27 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mailto Link Generator</title>
<!-- Add the CSS link to your Tailwind CSS file -->
<link href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100" x-data="mailtoGenerator()">
<div class="container mx-auto px-4 py-8">
<div class="max-w-md mx-auto bg-white rounded-lg shadow-md p-6">
<h2 class="text-2xl font-bold mb-4">Mailto Link Editor</h2>
<div class="mb-4">
<label for="to" class="block font-semibold mb-1">To:</label>
<input x-model="to" id="to" type="text" class="w-full rounded border px-4 py-2 focus:outline-none focus:ring focus:border-blue-300" placeholder="recipient@example.com">
</div>
<div class="mb-4">
<label for="subject" class="block font-semibold mb-1">Subject:</label>
<input x-model="subject" id="subject" type="text" class="w-full rounded border px-4 py-2 focus:outline-none focus:ring focus:border-blue-300" placeholder="Mail Subject">
</div>
<div class="mb-4">
<label for="body" class="block font-semibold mb-1">Body:</label>
<textarea x-model="body" id="body" rows="4" class="w-full rounded border px-4 py-2 focus:outline-none focus:ring focus:border-blue-300" placeholder="Mail Body"></textarea>
</div>
<div class="mb-4">
<label for="mailtoCode" class="block mb-1"><span class="font-bold">Mailto snippet:</span><br><span class="text-xs">Yes, you can paste in mailto's here.</span></label>
<textarea id="mailtoCode" rows="6" class="w-full rounded border px-4 py-2 focus:outline-none focus:ring focus:border-blue-300" x-model="mailtoCode" x-text="mailtoCode" @input="updateFields"></textarea>
</div>
<button class="bg-blue-500 text-white px-4 py-2 rounded" @click="copyMailtoLink">Copy Mailto Link</button>
</div>
</div>
<!-- Add the Alpine.js script -->
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
<script>
function mailtoGenerator() {
return {
to: '',
subject: '',
body: '',
get mailtoCode() {
return `mailto:${encodeURIComponent(this.to)}?subject=${encodeURIComponent(this.subject)}&body=${encodeURIComponent(this.body)}`;
},
set mailtoCode(value) {
const regex = /mailto:(.*?)\?subject=(.*?)&body=(.*)/;
const matches = value.match(regex);
if (matches) {
this.to = decodeURIComponent(matches[1]);
this.subject = decodeURIComponent(matches[2]);
this.body = decodeURIComponent(matches[3]);
} else {
// If the mailto code is invalid, reset the other fields
this.to = '';
this.subject = '';
this.body = '';
}
},
updateFields() {
this.mailtoCode = this.mailtoCode;
},
copyMailtoLink() {
const el = document.createElement('textarea');
el.value = this.mailtoCode;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
},
};
}
</script>
</body>
</html>