From 4b8b1763e47fcaf0d9e28b74997a9d1ef98bc20b Mon Sep 17 00:00:00 2001 From: lscambo13 Date: Mon, 25 Dec 2023 20:40:22 +0530 Subject: [PATCH] Update to the 'Add New Bookmark' behaviour new: We now read the clipboard to autofill any link you have cpoied (It will only be filled if it is valid link) new: We allow bookmark name to be four characters long, rather than three new: We no longer force bookmark name to be capitalized fix: Better error handling when user does not input a bookmark name --- index.html | 6 +++--- index.js | 53 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index a4954c8..5ac22ce 100644 --- a/index.html +++ b/index.html @@ -18,14 +18,14 @@ }); } --> - + Search • Casa Mia - - + + { }; window.createNewBookmark = () => { - let link = prompt('Type link'); - if (link == null) return; - while (!isUrlValid(link)) { - alert('Please type a website link'); - link = prompt('Type link'); - } + let clipboardText = 'https://www.' + navigator.clipboard.readText().then((res) => { + if (isUrlValid(res)) clipboardText = res + getDetailsForNewBookmark() + }).catch(err => { + console.log(err) + getDetailsForNewBookmark() + }); - let name = prompt('Type name'); - if (name == null) return; - if (name == '') { - name = link.replace('www.', ''); - if (name.includes('//')) { - name = name.split('//')[1]; + const getDetailsForNewBookmark = () => { + let link = prompt('Please type or paste a website address', clipboardText); + if (link == null) return; + while (!isUrlValid(link)) { + alert('The entered address does not seem to be valid'); + link = prompt('Please type or paste a website address', clipboardText); } - } - name = name.substring(0, 3).toUpperCase(); + let name = prompt('Type the bookmark name\n(Maximum four letters are allowed)'); + if (name == null) return; + while (name == '') { + alert('The entered name does not seem to be valid'); + name = prompt('Please type the bookmark name\n(Maximum four letters are allowed)'); + } + // if (name == '') { + // name = link.replace('www.', ''); + // if (name.includes('//')) { + // name = name.split('//')[1]; + // } + // } + name = name.substring(0, 4); + if (!link.includes('http')) { + link = 'https://' + link; + } + const id = Date.now(); - if (!link.includes('http')) { - link = 'https://' + link; + addBookmarkToHTML(link, name, id); + saveBookmarks(link, name, id); } - const id = Date.now(); - - addBookmarkToHTML(link, name, id); - saveBookmarks(link, name, id); }; window.changeWallpaper = (event) => {