Skip to content

Commit

Permalink
Update to the 'Add New Bookmark' behaviour
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lscambo13 committed Dec 25, 2023
1 parent 7cae159 commit 4b8b176
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
});
}
</script> -->
<link rel="manifest" href="manifest.json?v=1703513727022">
<link rel="manifest" href="manifest.json?v=1703513727023">
<title>Search &bull; Casa Mia</title>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<meta name="theme-color" content="black">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light only">
<link rel="stylesheet" href="./style.css?v=1703513727022" />
<script src="./index.js?v=1703513727022" type="module"></script>
<link rel="stylesheet" href="./style.css?v=1703513727023" />
<script src="./index.js?v=1703513727023" type="module"></script>
<link rel="preconnect" href="https://raw.githubusercontent.com" crossorigin />
<link rel="preconnect" href="https://fonts.bunny.net">
<link
Expand Down
53 changes: 33 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,43 @@ window.hideWallpapers = (str, event) => {
};

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) => {
Expand Down

0 comments on commit 4b8b176

Please sign in to comment.