vectorizer.io free download

vectorizer.io svg preview and free download

  1. // ==UserScript==
  2. // @name vectorizer.io free download
  3. // @version 0.0.1
  4. // @description vectorizer.io svg preview and free download
  5. // @icon https://www.vectorizer.io/icon.svg
  6.  
  7. // @author You
  8. // @namespace http://tampermonkey.net/
  9. // @license MIT
  10.  
  11. // @match https://www.vectorizer.io/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. /* eslint-env jquery */
  16.  
  17. (function() {
  18. 'use strict';
  19. function toURL() {
  20. const svg = $('#outputsvg')[0];
  21. const content = new XMLSerializer().serializeToString(svg);
  22. const type = 'image/svg+xml';
  23. const url = URL.createObjectURL(new Blob([content], {type}));
  24. return url;
  25. }
  26.  
  27. $('#downloadbtn').off('click').on('click', function(event) {
  28. event.preventDefault();
  29. const a = document.createElement('a');
  30. a.download = this.href.split('/').pop();
  31. a.href = toURL();
  32. document.body.appendChild(a);
  33. a.click();
  34. document.body.removeChild(a);
  35. });
  36.  
  37. const btn = $('<button class="btn btn-secondary">Preview</button>');
  38. btn.on('click', function(event) {
  39. open(toURL());
  40. });
  41. $('#downloadbtn').after(btn);
  42.  
  43. })();