diff --git a/scripts/main.js b/scripts/main.js index 87f312f..0d95d3d 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -9,13 +9,14 @@ async function getJson() { const imageResponse = await fetch(`https://api.unsplash.com/search/photos?query=motivational&client_id=${apiKey}`); const imageData = await imageResponse.json(); const image = imageData.results[randomQuoteIndex]; - - quote = `
Are you sure to delete this website?
", + html: "Are you sure to delete this website?
", background: "#353535", color: "white", confirmButtonText: "Delete", showCancelButton: true, animation: "slide-from-top", - filter: 'blur(10px)', allowOutsideClick: false, }).then((result) => { if (result.isConfirmed) { - const tabLink = $(this).attr('data-name'); - const tab = $(this).attr('data-tab'); $(this).remove(); deleteTab(tab, tabLink); } @@ -260,13 +261,13 @@ const setupEventListeners = () => { }; // Handle site link click -const handleSiteLinkClick = () => { +const handleSiteLinkClick = function () { const tab = $(this).attr('data-link'); OpenInNew(min, tab); }; // Handle video gallery click -const handleVideoGalleryClick = () => { +const handleVideoGalleryClick = function () { if (count == 0) { OpenInNew(min, tab, "video"); count = 1; @@ -274,7 +275,7 @@ const handleVideoGalleryClick = () => { }; // Handle URL click -const handleUrlClick = () => { +const handleUrlClick = function () { if (isUrlValid()) { if (count == 0) { customUrl(); @@ -291,34 +292,36 @@ const handleUrlClick = () => { }; // Handle time button click -const handleTimeButtonClick = () => { - $(".time-button").each(function (i, hello) { - $(hello).removeClass("clicked"); - }); +const handleTimeButtonClick = function () { + $(".time-button").removeClass("clicked"); $(this).addClass("clicked"); }; // Handle notification click -const handleNotificationClick = () => { +const handleNotificationClick = function () { Lockr.set('notificationAlert', $(this).is(':checked')); }; // Handle audio alert click -const handleAudioAlertClick = () => { +const handleAudioAlertClick = function () { Lockr.set('audioAlert', $(this).is(':checked')); }; // Function to update sites const updateSites = () => { - $(".rig.columns-6.websites").append( - "
Add Site
+ Add Site
+${siteLabel}
- - `); + `); }, error: function () { $('.rig.columns-6.websites').append(` @@ -346,8 +348,7 @@ const updateSites = () => {
${siteLabel}
- - `); + `); } }); }); @@ -362,33 +363,32 @@ const updateSites = () => { // Function to get site image const getSiteImage = (siteName) => { - if (siteName === 'Youtube') return 'assets/youtube.png'; - if (siteName === 'Netflix') return 'assets/netflix.png'; - if (siteName === 'Facebook') return 'assets/facebook.png'; - if (siteName === 'Instagram') return 'assets/instagram.png'; - if (siteName === 'Reddit') return 'assets/reddit.png'; - return `https://logo.clearbit.com/${siteName.toLowerCase()}.com`; + switch (siteName) { + case 'YouTube': return 'assets/youtube.png'; + case 'Netflix': return 'assets/netflix.png'; + case 'Facebook': return 'assets/facebook.png'; + case 'Instagram': return 'assets/instagram.png'; + case 'Reddit': return 'assets/reddit.png'; + default: return `https://logo.clearbit.com/${siteName.toLowerCase()}.com`; + } }; // Function to add grid element const addGridElement = (siteLabel, siteLink) => { - let newLabel = siteLabel.replace(/\s+/g, ''); - let testLink = `https://logo.clearbit.com/${newLabel.toLowerCase()}.com`; - let newSiteLabel = siteLabel.substring(0 , 14); - newSiteLabel = newSiteLabel.replace(/\s/g, ' '); + let newLabel = siteLabel.replace(/\s+/g, '').toLowerCase(); + let newSiteLabel = siteLabel.substring(0, 14).replace(/\s/g, ' '); $.ajax({ type: 'HEAD', - url: testLink, + url: `https://logo.clearbit.com/${newLabel}.com`, success: function () { $('.rig.columns-6.websites').append(`${newSiteLabel}
${newSiteLabel}
- - `); + `); } }); }; @@ -407,14 +406,11 @@ const addGridElement = (siteLabel, siteLink) => { const deleteTab = (tab, tabLink) => { $("[data-link='" + tabLink + "']").hide(); Lockr.srem('customSites', [tab, tabLink]); - var items = JSON.parse(localStorage.getItem("customSites")); - for (var i = 0; i < items.data.length; i++) { - var name = items.data[i][0]; - if (name == tab) { - items.data.splice(i, 1); - item = JSON.stringify(items); - localStorage.setItem("customSites", item); - return; - } + + const items = Lockr.get('customSites'); + const index = items.findIndex(item => item[0] === tab); + if (index > -1) { + items.splice(index, 1); + Lockr.set('customSites', items); } -}; \ No newline at end of file +};