From 5c232197f576a9992266c3681bfb25719792b845 Mon Sep 17 00:00:00 2001 From: Raju Choudhary Date: Tue, 5 Mar 2024 16:23:33 +0545 Subject: [PATCH] Fixed Icon8 Update --- src/scripts/iconify-main.js | 76 +++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/src/scripts/iconify-main.js b/src/scripts/iconify-main.js index c56a1c7..fc00319 100644 --- a/src/scripts/iconify-main.js +++ b/src/scripts/iconify-main.js @@ -159,10 +159,17 @@ window.addEventListener("load", function (){ observer.observe(targetNode, config); // Add download SVG button in Icons8 modal after clicking the original available download button - let icons8DownloadButton = '
'; - $(document).on("click", ".app-accordion2__main-buttons .i8-button--primary.i8-button--large.i8-button", function (e) { - let downloadModalFooterElement = $(document).find(".dim__footer"); - downloadModalFooterElement.after(icons8DownloadButton); + let icons8DownloadButton ='' + + ''; + $(document).on("click", ".app-grid-icon", function (e) { + let downloadModalFooterElement = $(document).find(".app-accordion2__main-buttons"); + let existingButton = $(document).find(".download-svg-ry"); + if(existingButton.length < 1) + { + downloadModalFooterElement.prepend(icons8DownloadButton) + } }); // Download SVG from Fontawesome @@ -191,33 +198,44 @@ window.addEventListener("load", function (){ try { let clickedButtonElement = $(this); - let idElement = $("#dim__preview .dim__preview-icons .dim__preview-icon-wrapper"); - let value = idElement.attr("id"); - if(value) + let idElement = $(document).find(".i8-link.app-accordion2__name.app-accordion2__name"); + let str = idElement.attr("href"); + if(str) { - value = value.substring(1); - value = value.substring(0, value.lastIndexOf("-")); - $.ajax({ - url : `https://api-icons.icons8.com/siteApi/icons/icon?id=${value}&info=true&language=en-US&svg=true`, - method : "GET", - dataType : "JSON", - beforeSend : function (){ - clickedButtonElement.html(LOADING_ICON); - }, - success : function (response){ - const iconName = response.icon.name ?? value; - const svg = response.icon.svg ?? ""; - if(svg.length > 0) - { - downloadIcon(atob(svg), iconName); - } - else - { - Snackbar.show({ text : "Icon / Asset is not available in SVG format."}); + + let value; + const regex = /\/icon\/([^\/]+)/; + const match = str.match(regex); + + if (match) { + value = match[1]; + } else { + value = ""; + } + if(value) + { + $.ajax({ + url : `https://api-icons.icons8.com/siteApi/icons/icon?id=${value}&info=true&language=en-US&svg=true`, + method : "GET", + dataType : "JSON", + beforeSend : function (){ + clickedButtonElement.html(LOADING_ICON); + }, + success : function (response){ + const iconName = response.icon.name ?? value; + const svg = response.icon.svg ?? ""; + if(svg.length > 0) + { + downloadIcon(atob(svg), iconName); + } + else + { + Snackbar.show({ text : "Icon / Asset is not available in SVG format."}); + } + clickedButtonElement.html('
Iconify Download SVG') } - clickedButtonElement.html('
Download') - } - }) + }) + } } } catch(e)