Greasy Fork

来自缓存

Greasy Fork is available in English.

SVG Download

给字统提供下载 SVG 按钮

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SVG Download
// @namespace    http://tampermonkey.net/
// @description  给字统提供下载 SVG 按钮
// @author       Basic 低手
// @license      MIT
// @version      3.1
// @match        https://zi.tools/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zi.tools
// @grant        none
// ==/UserScript==

function waitForElm(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
                observer.disconnect();
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}
waitForElm('.links').then((Links) => {
    var c=document.title.split(":")[0];
    var s="⿰⿲⿱⿳⿸⿺⿹⿽⿵⿷⿶⿼⿴⿻⿾⿿㇯";
    console.log(s.indexOf(c[0]));
    if(s.indexOf(c[0])>=0){
        var pcOnly=document.getElementsByClassName("pc-only")[0];
        var SVG=pcOnly.getElementsByTagName("svg")[0].cloneNode(true);
        SVG.style="";
        SVG.setAttribute("width", "200");
        SVG.setAttribute("height", "200");
        SVG.setAttribute("viewBox", "");
        var dash=SVG.children[0];
        SVG.removeChild(dash);
        var btnDown=document.createElement("button");
        btnDown.innerText="下载 SVG 文件";
        btnDown.onclick=function(){
            // 定义触发事件的DOM
            var text=SVG.outerHTML;
            var filename=pcOnly.innerText.replace(":",":")+".svg";
            var element = document.createElement('a');
            element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
            element.setAttribute('download', filename);

            element.style.display = 'none';
            document.body.appendChild(element);

            element.click();

            document.body.removeChild(element);
        }

        Links.appendChild(btnDown);
    }
//}
//},false);
});