IconFont-阿里巴巴矢量图标库一键加入购物车

IconFont-阿里巴巴矢量图标库提供一键加入购物车功能

目前为 2019-03-14 提交的版本。查看 最新版本

// ==UserScript==
// @name         IconFont-阿里巴巴矢量图标库一键加入购物车
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  IconFont-阿里巴巴矢量图标库提供一键加入购物车功能
// @author       devifish
// @license      MIT
// @match        *://www.iconfont.cn/collections/detail*
// @match        *://iconfont.cn/collections/detail*
// @require      https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @run-at	     document-end
// @grant        unsafeWindow
// ==/UserScript==

(function() {
  "use strict";

  const icon_id_prefix = "J_icon_id_";
  const icons_save_name = "__iconfont_car_icons__";

  const $ = window.$;
  const body = document.body;
  const observer = new MutationObserver(records => {
    for (var record of records) {
      let target = record.target;

      if (target.querySelector(".block-radius-btn-group")) {
        observer.disconnect();

        const add_all_btn = `
          <span class="radius-btn radius-btn-share" title="一键添加到购物车" style="background: #2274d5">
            <span class="iconfont icon-gouwuche1" style="font-size: 27px;"></span>
          </span>
        `;
        let $add_all_btn = $(add_all_btn);
        let $btn_group = $(target).find(".block-radius-btn-group");
        let $icons = $(".collection-detail .block-icon-list li");

        $add_all_btn.click(async () => {
          let data = [];

          $.each($icons, (i, icon) => {
            let $icon = $(icon);
            data.push({
              id: $icon.attr("class").replace(icon_id_prefix, ""),
              name: $icon.find(".icon-name").text(),
              projectId: -1,
              show_svg: $icon.find(".icon-twrap").html()
            })
          });
          localStorage.setItem(icons_save_name, JSON.stringify(data));
          alert(`已将该页面 ${$icons.length} 个图标添加到了购物车`);
          location.reload();
        }).prependTo($btn_group);;
        
        break;
      }
    }
  });

  observer.observe(body, { childList: true });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址