Greasy Fork

Greasy Fork is available in English.

iconfont 免登录下载

免登录下载 iconfont 的icon

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         iconfont 免登录下载
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  免登录下载 iconfont 的icon
// @author       You
// @match        https://www.iconfont.cn/collections/*
// @match        https://www.iconfont.cn/search/*
// @icon         https://www.google.com/s2/favicons?domain=iconfont.cn
// @grant        none
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js
// ==/UserScript==

(function () {
    'use strict';

    async function sleep(time) {
        return new Promise(function (resolve) {
            setTimeout(resolve, time);
        })
    }

    async function run() {
        let $div = document.querySelector(".block-bar-right .block-radius-btn-group.clearfix");
        if (!$div || $div.querySelector('.icon-xiazai')) {
            return;
        }
        let $icon = document.createElement("span");
        $icon.setAttribute('class', 'radius-btn radius-btn-like');
        $icon.innerHTML = ('<span class="icon-xiazai  iconfont"></span>')
        $div.prepend($icon);
        $icon.addEventListener('click', function () {
            var zip = new JSZip();
            Array.from(document.body.querySelectorAll('.icon-twrap')).map(function (icon) {
                let svg = icon.innerHTML;
                let name = icon.nextElementSibling.innerText
                zip.file("icons/" + name + ".svg", svg);
            })
            zip.generateAsync({type: "blob"}).then(content => {
                let $a = document.createElement("a");
                let $title = document.body.querySelector(".right-content span.title");
                $a.href = URL.createObjectURL(content);
                $a.download = ($title ? $title.innerText : 'icon') + ".zip";
                $a.click();
            })
        });
    }

    new Promise(async function () {
        while (true) {
            await sleep(1000);
            console.log("run")
            await run();
            Array.from(document.querySelectorAll('span.icon-xiazai[data-login]')).forEach(e => {
                e.removeAttribute("data-login");
            });
        }
    }).finally()
    // Your code here...
})();