Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- IconScout Added 3D Icon Support [ PNG ]
  • Loading branch information
MrJukeman committed Mar 28, 2024
1 parent c320d01 commit a7c13b1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
74 changes: 70 additions & 4 deletions src/scripts/iconify-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 ()
{
Expand Down Expand Up @@ -152,9 +180,20 @@ window.addEventListener("load", function (){
// Replace the download button with SVG download button in Iconscout
let iconScoutPremiumDownloadButton =
$(`<button type="button" class="btn btn-primary has-icon w-100 btn-lg download-icon">Download</button>`).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)
Expand Down Expand Up @@ -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())
{
Expand All @@ -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);
Expand Down Expand Up @@ -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");
}
}
}
});
Expand Down

0 comments on commit a7c13b1

Please sign in to comment.