-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
114 lines (105 loc) · 3.1 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
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create a link to your Obsidian vault</title>
<style>
body {
margin: 40px auto;
max-width: 650px;
line-height: 1.6;
font-size: 18px;
color: #444;
padding: 0 10px;
}
h1, h2, h3 {
line-height: 1.2;
}
h1 {
font-size: 2.5rem;
}
form {
display: flex;
flex-direction: column;
gap: 1rem;
}
label {
font-weight: 600;
}
input {
padding: 0.5rem;
font-size: 1rem;
}
button {
padding: 0.5rem 1rem;
font-size: 1rem;
background-color: #333;
color: white;
border: none;
cursor: pointer;
}
#result {
margin-top: 1rem;
padding: 1rem;
background-color: #f5f5f5;
border-radius: 4px;
word-wrap: break-word;
}
</style>
</head>
<body>
<h1>Create a link to your Obsidian vault</h1>
<form id="linkForm">
<div>
<div>
<label for="vaultName">Vault</label>
</div>
<input type="text" id="vaultName" required>
</div>
<div>
<div>
<label for="noteName">Note</label>
</div>
<input type="text" id="noteName" required>
</div>
<div>
<button type="submit">Create Link</button>
</div>
</form>
<div id="result"></div>
<script>
// Function to set focus on note input if vault is already set
function setFocusBasedOnVault() {
const savedVault = localStorage.getItem('obsidianVault');
const vaultInput = document.getElementById('vaultName');
const noteInput = document.getElementById('noteName');
if (savedVault) {
vaultInput.value = savedVault;
noteInput.focus();
} else {
vaultInput.focus();
}
}
// Set initial focus when page loads
window.addEventListener('load', setFocusBasedOnVault);
document.getElementById('linkForm').addEventListener('submit', function(e) {
e.preventDefault();
const vaultName = document.getElementById('vaultName').value;
const noteName = document.getElementById('noteName').value;
// Save vault name to localStorage
localStorage.setItem('obsidianVault', vaultName);
const encodedVault = encodeURIComponent(vaultName);
const encodedNote = encodeURIComponent(noteName);
const url = `https://${encodedVault}.obsidian.name/${encodedNote}`;
document.getElementById('result').innerHTML = `
<p>Your Obsidian link:</p>
<a href="${url}" target="_blank">${url}</a>
`;
// Clear note input for next use, keeping vault name
document.getElementById('noteName').value = '';
document.getElementById('noteName').focus();
});
</script>
</body>
</html>