Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fetch JSZip and FileSaver.js dependencies
- Promise.all([
- 'https://unpkg.com/jszip@3.1.4/dist/jszip.min.js',
- 'https://unpkg.com/file-saver@1.3.3/FileSaver.min.js',
- ].map(src => new Promise((resolve, reject) => {
- const script = document.createElement('script');
- script.src = src;
- script.onload = resolve;
- script.onerror = reject;
- document.body.appendChild(script);
- }))).then(() => {
- // Swap *-off line directions
- const oldLine = {x1: 1, y1: 1, x2: 23, y2: 23};
- const newLine = {x1: 23, y1: 1, x2: 1, y2: 23};
- const icons = Array.from(document.querySelectorAll('svg.feather'));
- icons
- .filter(icon => icon.getAttribute('class').includes('-off'))
- .map(icon => icon.querySelector('line'))
- .filter(line => Object.entries(oldLine)
- .reduce((acc, [attr, value]) => line.getAttribute(attr) == value), false)
- .map(line => Object.entries(newLine)
- .forEach(([attr, val]) => line.setAttribute(attr, val)));
- // Generate zip file
- const zip = new JSZip();
- icons.forEach(icon => zip.file(
- icon.getAttribute('class').replace('feather feather-', '') + '.svg',
- icon.outerHTML
- ));
- // Save zip file
- zip.generateAsync({type:'blob'})
- .then(content => saveAs(content, 'feather.zip'));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement