summaryrefslogtreecommitdiff
path: root/src/main/resources/META-INF
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-12 06:20:05 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-12 06:20:05 +0100
commit35e14e4f5e98719d5db1ac9cba46cdeefc3d3f00 (patch)
treeb40fe3155e6562b838b5cfd1bd9f0763ca950aa1 /src/main/resources/META-INF
parent22f623c810297467da2d8662c5d4b90ae8e84dae (diff)
Bookmark submission: Fetch page info through back end.
CORS prevents us from fetch the target page directly. This patch makes the front end use the back end to fetch it instead. Change-Id: I2d33a68d00b6ce1bb7a7b8dfcb7687f0bd1fdebd
Diffstat (limited to 'src/main/resources/META-INF')
-rw-r--r--src/main/resources/META-INF/resources/bookmarks/bookmarkList.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js b/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
index 11c4b10..4c8287a 100644
--- a/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
+++ b/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
@@ -1,5 +1,6 @@
document.addEventListener('DOMContentLoaded', () => {
- let bookmarkSubmissionPane = document.getElementById('bookmark-submission-pane');
+ 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');
@@ -9,7 +10,10 @@ document.addEventListener('DOMContentLoaded', () => {
uriInput.addEventListener('blur', async () => {
uriSpinner.hidden = false;
uriSpinner.playing = true;
- let r = await fetch(uriInput.value);
+ let searchParams = new URLSearchParams({'uri': uriInput.value});
+ console.log(`/bookmarks/page-info?${searchParams}`);
+ let fetchUrl = new URL(`/bookmarks/page-info?${searchParams}`, document.URL);
+ let r = await fetch(fetchUrl);
uriSpinner.hidden = true;
uriSpinner.playing = false;
@@ -17,14 +21,8 @@ document.addEventListener('DOMContentLoaded', () => {
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;
+ let pageInfo = await r.json();
+ titleInput.value = pageInfo.title;
});
});