diff --git a/src/manifest.json b/src/manifest.json index 4ea6bc8..857ee2d 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,6 +1,6 @@ { "name" : "Iconify", - "version" : "1.0.4", + "version" : "1.0.5", "description" : "Upgrade your designs with our browser extension! Download premium SVG icons and stickers.", "manifest_version": 3, "icons": { diff --git a/src/scripts/iconify-main.js b/src/scripts/iconify-main.js index df0ef6e..d85088d 100644 --- a/src/scripts/iconify-main.js +++ b/src/scripts/iconify-main.js @@ -69,6 +69,19 @@ const downloadIcon = function (text = "", downloadAbleName = "", extension = "sv document.body.removeChild(newAnchorElement); } +async function downloadPNG(imageSrc,name) { + const image = await fetch(imageSrc) + const imageBlog = await image.blob() + const imageURL = URL.createObjectURL(imageBlog) + + const link = document.createElement('a') + link.href = imageURL + link.download = name; + document.body.appendChild(link) + link.click() + document.body.removeChild(link) +} + // Create download json const downloadJson = function (data = {}, downloadAbleName = "", extension = "json"){ let jsonString = JSON.stringify(data, null, 2); @@ -95,6 +108,21 @@ const copyToClipBoard = function (text, clickedButtonElement, replacer) clickedButtonElement.html(replacer); } +//GET UUID +const getUUIDFroIconScout = function () +{ + const se = localStorage.getItem("__user_traits"); + if (se) + { + const userData = JSON.parse(se); + if (userData && userData.uuid) + { + return userData.uuid; + } + } + return 0; +} + // Check user logged in state const checkLoggedInStatus = function () { @@ -152,9 +180,20 @@ window.addEventListener("load", function (){ // Replace the download button with SVG download button in Iconscout let iconScoutPremiumDownloadButton = $(``).text("Download").removeAttr("href"); + const button = $("button[class*='btn'][class*='dropdown-toggle'][class*='btn-primary'][class*='w-100'][class*='btn-lg'][class*='has-icon'][class*='dropdown-toggle-no-caret']"); + const button2 = $("#modalItemPreview main").find("button[class='btn btn-primary has-icon w-100 btn-lg']"); button.next("ul").remove(); - button.replaceWith(iconScoutPremiumDownloadButton); + if(button) + { + button.replaceWith(iconScoutPremiumDownloadButton); + + } + else + { + button2.replaceWith(iconScoutPremiumDownloadButton); + + } }); // Options for the observer (which mutations to observe) @@ -260,7 +299,7 @@ $(document).on("click", function (){ initFontAwesome(); }) -// Download SVG from Iconscout +// Download SVG from IconScout $(document).on("click", ".download-icon, .copyToClipboardIScout", function(e){ if(!checkLoggedInStatus()) { @@ -269,11 +308,15 @@ $(document).on("click", ".download-icon, .copyToClipboardIScout", function(e){ } let product_id = 0; + let product_url = 0; let clickedButtonElement = $(this); clickedButtonElement.html(LOADING_ICON); $('meta[data-n-head="ssr"][property="og:product_id"]').each(function(){ product_id = $(this).attr("content"); }) + $('meta[data-n-head="ssr"][property="product:product_link"]').each(function(){ + product_url = $(this).attr("content"); + }) if(product_id) { let propColorEditor = $(document).find("#pdpColorEditor-" + product_id); @@ -309,8 +352,31 @@ $(document).on("click", ".download-icon, .copyToClipboardIScout", function(e){ } else { - Snackbar.show({text : "Unsupported format or icon !"}) - clickedButtonElement.html("Download"); + //The Icon is 3d + let uuid = getUUIDFroIconScout(); + try + { + if(uuid && product_url) + { + const parts = product_url.split("/"); + const p_id = parts[parts.length - 1]; + if(p_id) + { + fetch(`https://iconscout.com/api/v2/new-items/${p_id}?extra_fields=true&items=true&token=${uuid}`).then(response => response.json() ).then( data => { + if(data) + { + downloadPNG(data.response.item.urls.original, product_id + ".png").then(() => { + clickedButtonElement.html("Download"); + }); + } + }); + } + } + }catch (e) + { + Snackbar.show({ text : "Something went wrong while downloading the icon, Hot reload the page." }); + clickedButtonElement.html("Download"); + } } } });