summaryrefslogtreecommitdiff
path: root/src/main/resources/META-INF
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-12 05:54:53 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-12 05:54:53 +0100
commit22f623c810297467da2d8662c5d4b90ae8e84dae (patch)
tree5ae88d8279a0c389305a6f06e69139a749e9b0d0 /src/main/resources/META-INF
parent8b7cfaaac98a815195a17b5e28111a65be0791ab (diff)
Bookmark submission: Automatically fetch title after URI input.
Change-Id: Ieea258e076d1dbaeba2520e583b590822dfdcab8
Diffstat (limited to 'src/main/resources/META-INF')
-rw-r--r--src/main/resources/META-INF/resources/bookmarks/bookmarkList.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js b/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
index eab07f5..11c4b10 100644
--- a/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
+++ b/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
@@ -1,5 +1,30 @@
document.addEventListener('DOMContentLoaded', () => {
let bookmarkSubmissionPane = document.getElementById('bookmark-submission-pane');
+ let titleInput = document.getElementById('title-input');
let uriInput = document.getElementById('uri-input');
+ let uriSpinner = document.getElementById('uri-spinner');
+
bookmarkSubmissionPane.addEventListener('opened', () => uriInput.focus());
-}); \ No newline at end of file
+
+ uriInput.addEventListener('blur', async () => {
+ uriSpinner.hidden = false;
+ uriSpinner.playing = true;
+ let r = await fetch(uriInput.value);
+ uriSpinner.hidden = true;
+ uriSpinner.playing = false;
+
+ if (!r.ok) {
+ return;
+ }
+
+ let html = await r.text();
+ let parser = new DOMParser();
+ let doc = parser.parseFromString(html, "text/html");
+ let titles = doc.getElementsByTagName('title');
+ if (titles.length <= 0) {
+ return;
+ }
+ titleInput.value = titles[0].innerText;
+ });
+});
+