🏠 Home 

Flaticon Free SVG Download

Enables the SVG download for free. Requires to be Logged In


Install this script?
  1. // ==UserScript==
  2. // @name Flaticon Free SVG Download
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.flaticon.com/free-icon/*
  5. // @grant none
  6. // @version 1.0.1
  7. // @author Der_Floh
  8. // @description Enables the SVG download for free. Requires to be Logged In
  9. // @license MIT
  10. // @icon https://images.g2crowd.com/uploads/product/image/large_detail/large_detail_e7b8a53bf9ee1f0023a60ce6644dd5f8/flaticon.jpg
  11. // @homepageURL https://greasyfork.org/de/scripts/475726-flaticon-free-svg-download
  12. // @supportURL https://greasyfork.org/de/scripts/475726-flaticon-free-svg-download/feedback
  13. // ==/UserScript==
  14. // jshint esversion: 8
  15. window.addEventListener("load", () => {
  16. const downloadContainer = document.getElementById("download");
  17. const downloadSvgButton = downloadContainer.querySelector('a[class*="btn-svg"]');
  18. const spanElem = downloadSvgButton.querySelector("span");
  19. spanElem.textContent = "Download SVG Free";
  20. const premiumIcon = downloadSvgButton.querySelector('i[class*="icon"]');
  21. premiumIcon.parentNode.removeChild(premiumIcon);
  22. downloadSvgButton.onclick = startDownloadSvg;
  23. });
  24. async function startDownloadSvg() {
  25. const editButton = document.getElementById("detail_edit_icon");
  26. editButton.click();
  27. const detailContainer = await waitForElementToExistId("detail");
  28. const iconHolder = await waitForElementToExistQuery(detailContainer, 'div[class*="icon-holder"]');
  29. if (detailContainer.querySelector('div[class="alert warning free_user_warning"]')) {
  30. console.warn("You need to Log in to download SVG for Free");
  31. return;
  32. }
  33. const svgElem = await waitForElementToExistQuery(iconHolder, "svg");
  34. const filename = getLastURLPart(window.location.toString()) + ".svg";
  35. downloadSvg(svgElem, filename);
  36. const backButton = detailContainer.querySelector('button[class*="bj-button"]');
  37. backButton.click();
  38. }
  39. async function waitForElementToExistQuery(baseNode, query) {
  40. return new Promise(async (resolve) => {
  41. async function checkElement() {
  42. const element = baseNode.querySelector(query);
  43. if (element !== null)
  44. resolve(element);
  45. else
  46. setTimeout(checkElement, 100);
  47. }
  48. await checkElement();
  49. });
  50. }
  51. async function waitForElementToExistId(elementId) {
  52. return new Promise(async (resolve) => {
  53. async function checkElement() {
  54. const element = document.getElementById(elementId);
  55. if (element !== null)
  56. resolve(element);
  57. else
  58. setTimeout(checkElement, 100);
  59. }
  60. await checkElement();
  61. });
  62. }
  63. function downloadSvg(svg, filename) {
  64. const content = new XMLSerializer().serializeToString(svg);
  65. const type = "image/svg+xml";
  66. const url = URL.createObjectURL(new Blob([content], {type}));
  67. const a = document.createElement('a');
  68. a.href = url;
  69. a.download = filename || 'vector-image.svg';
  70. a.style.display = 'none';
  71. document.body.appendChild(a);
  72. a.click();
  73. document.body.removeChild(a);
  74. window.URL.revokeObjectURL(url);
  75. }
  76. function getLastURLPart(url) {
  77. const parsedURL = new URL(url);
  78. const pathname = parsedURL.pathname;
  79. const segments = pathname.split('/');
  80. const filteredSegments = segments.filter(segment => segment !== '');
  81. const lastSegment = filteredSegments.pop();
  82. return lastSegment || '';
  83. }