Giter VIP home page Giter VIP logo

iconfont's People

Contributors

dongxinmario avatar

Watchers

 avatar  avatar

iconfont's Issues

【improve】可以直接从接口层进行实现

/**
 * iconfont批量打包下载脚本,
 * 使用Chrome内核浏览器,
 * F12打开控制台,在console一栏中粘贴后回车,
 * 稍等片刻即可打包下载
 */

(() => {
  // 这里指定要批量下载的图标库ID
  const ID = 20331;
  const loadJS = (url, implementationCode, location) => {
    const scriptTag = document.createElement('script');
    scriptTag.src = url;
    scriptTag.onload = implementationCode;
    scriptTag.onreadystatechange = implementationCode;
    location.appendChild(scriptTag);
  };
  const callback = () => {
    console.log('[iconfont-zipper] 依赖脚本加载完成,获取数据中...');
    fetch(`https://www.iconfont.cn/api/collection/detail.json?id=${ID}`).then(async resp => {
      const { data } = await resp.json();
      const { icons } = data;
      const zip = new JSZip();
      icons.forEach(icon => {
        const { name, show_svg: content } = icon;
        zip.file(`${name}.svg`, content);
      });
      zip.generateAsync({ type: 'blob' }).then(content => {
        const filename = `${ID}.zip`;
        const eleLink = document.createElement('a');
        eleLink.download = filename;
        eleLink.style.display = 'none';
        eleLink.href = URL.createObjectURL(content);
        document.body.appendChild(eleLink);
        eleLink.click();
        document.body.removeChild(eleLink);
        console.log(`[iconfont-zipper] 成功获取${icons.length}个svg,正在保存到${filename}文件`);
      });
    });
  };
  console.log('[iconfont-zipper] 依赖脚本加载中...');
  loadJS('https://cdn.bootcss.com/jszip/3.2.2/jszip.min.js', callback, document.body);
})();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.