Advertisement
Guest User

Fix feather *-off icons

a guest
Aug 26th, 2017
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Fetch JSZip and FileSaver.js dependencies
  2. Promise.all([
  3.   'https://unpkg.com/jszip@3.1.4/dist/jszip.min.js',
  4.   'https://unpkg.com/file-saver@1.3.3/FileSaver.min.js',
  5. ].map(src => new Promise((resolve, reject) => {
  6.   const script = document.createElement('script');
  7.   script.src = src;
  8.   script.onload = resolve;
  9.   script.onerror = reject;
  10.   document.body.appendChild(script);
  11. }))).then(() => {
  12.   // Swap *-off line directions
  13.   const oldLine = {x1: 1, y1: 1, x2: 23, y2: 23};
  14.   const newLine = {x1: 23, y1: 1, x2: 1, y2: 23};
  15.   const icons = Array.from(document.querySelectorAll('svg.feather'));
  16.   icons
  17.     .filter(icon => icon.getAttribute('class').includes('-off'))
  18.     .map(icon => icon.querySelector('line'))
  19.     .filter(line => Object.entries(oldLine)
  20.       .reduce((acc, [attr, value]) => line.getAttribute(attr) == value), false)
  21.     .map(line => Object.entries(newLine)
  22.       .forEach(([attr, val]) => line.setAttribute(attr, val)));
  23.  
  24.   // Generate zip file
  25.   const zip = new JSZip();
  26.   icons.forEach(icon => zip.file(
  27.     icon.getAttribute('class').replace('feather feather-', '') + '.svg',
  28.     icon.outerHTML
  29.   ));
  30.  
  31.   // Save zip file
  32.   zip.generateAsync({type:'blob'})
  33.     .then(content => saveAs(content, 'feather.zip'));
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement