Quickadd feature for link saving
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Save link</title>
|
||||
<link rel="icon" href="/_/favicon.ico" />
|
||||
<link rel="stylesheet" href="/_/style.css" />
|
||||
<style>
|
||||
body { padding: 0.8rem; }
|
||||
.qa-form { display: flex; flex-direction: column; gap: 0.5rem; }
|
||||
.qa-row { display: flex; flex-direction: column; gap: 0.1rem; }
|
||||
.qa-label { font-size: 0.7rem; }
|
||||
.qa-value { word-break: break-all; font-size: 0.85rem; }
|
||||
.qa-comment {
|
||||
width: 100%;
|
||||
padding: 0.35rem;
|
||||
background: var(--bg-panel);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--bg-panel-hover);
|
||||
font: inherit;
|
||||
}
|
||||
.qa-actions { display: flex; gap: 1rem; }
|
||||
.qa-status { min-height: 1em; font-size: 0.85rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form id="qa-form" class="qa-form"
|
||||
data-to="{{.To}}" data-url="{{.URL}}" data-title="{{.Title}}">
|
||||
<div class="qa-row">
|
||||
<span class="qa-label muted">Save to</span>
|
||||
<span class="qa-value">{{.To}}</span>
|
||||
</div>
|
||||
<div class="qa-row">
|
||||
<span class="qa-label muted">Title</span>
|
||||
<span class="qa-value">{{.Title}}</span>
|
||||
</div>
|
||||
<div class="qa-row">
|
||||
<span class="qa-label muted">URL</span>
|
||||
<span class="qa-value">{{.URL}}</span>
|
||||
</div>
|
||||
<div class="qa-row">
|
||||
<label class="qa-label muted" for="qa-comment">Comment</label>
|
||||
<input id="qa-comment" name="comment" type="text" class="qa-comment" autofocus />
|
||||
</div>
|
||||
<div class="qa-actions">
|
||||
<button type="submit" class="btn">SAVE</button>
|
||||
<button type="button" class="btn" id="qa-cancel">CANCEL</button>
|
||||
</div>
|
||||
<div id="qa-status" class="qa-status muted"></div>
|
||||
</form>
|
||||
<script>
|
||||
(function () {
|
||||
const form = document.getElementById("qa-form");
|
||||
const status = document.getElementById("qa-status");
|
||||
const comment = document.getElementById("qa-comment");
|
||||
document
|
||||
.getElementById("qa-cancel")
|
||||
.addEventListener("click", () => window.close());
|
||||
form.addEventListener("submit", async (ev) => {
|
||||
ev.preventDefault();
|
||||
status.classList.remove("danger");
|
||||
status.classList.add("muted");
|
||||
status.textContent = "Saving…";
|
||||
const body = new URLSearchParams();
|
||||
body.set("url", form.dataset.url);
|
||||
body.set("title", form.dataset.title);
|
||||
body.set("comment", comment.value);
|
||||
try {
|
||||
const res = await fetch(form.dataset.to + "?append", {
|
||||
method: "POST",
|
||||
body,
|
||||
credentials: "same-origin",
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = (await res.text()).trim();
|
||||
status.classList.remove("muted");
|
||||
status.classList.add("danger");
|
||||
status.textContent = text || "HTTP " + res.status;
|
||||
return;
|
||||
}
|
||||
status.textContent = "Saved ✓";
|
||||
setTimeout(() => window.close(), 1000);
|
||||
} catch (e) {
|
||||
status.classList.remove("muted");
|
||||
status.classList.add("danger");
|
||||
status.textContent = (e && e.message) || "Network error";
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user