Greasy Fork

Greasy Fork is available in English.

Processon下载脑图

导出Processon脑图 km格式

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name    Processon下载脑图
// @namespace    http://www.yihy.cc/
// @version      0.2
// @description  导出Processon脑图 km格式
// @author       yihy
// @match        *://www.processon.com/view/link/*
// @match        *://www.processon.com/view/*
// @require         http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    try {
    function getKmByProcesson(json) {
        console.log(json)
        function fn(json) {
            var d = {
                data: {
                    id: json.id,
                    text: json.title.replace('//g', '\n')
                }
            };
            if (json.note != undefined) {
                d.data.note = json.note;
            }
            if (json.children == null || json.children.length == 0) {
                return d;
            }
            var arr = [];
            json.children.forEach(function (item) {
                arr.push(fn(item));
            });
            d.children = arr;
            return d;
        }
        return {
            root: fn(json)
        };
    }

    function saveKm(fileName, content) {
        var el = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
        if (el) {
            el.href = 'data:text/plain,' + content;
            el.download = fileName;
            var event = document.createEvent('MouseEvents');
            event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            el.dispatchEvent(event);
        }
    }

     $(".controlls>div").last().before('<div id="downloadkm" title_pos="left" title="下载脑图" class="item"><div class="ico_box"><span class="icons"></span></div></div>');
     $("#downloadkm").click(function () {
        $.ajax({
        url: "/diagraming/getdef?tempId=" + tempId,
        type: 'get',
        data: {
            id: chartId
        },
        success: function (c) {
            var definition = JSON.parse(c.def);
            if(!definition.title){
              alert("不支持的格式!");
            }
            var data = getKmByProcesson(definition);
            var fileName = data.root.data.text + '.km';
            saveKm(fileName, JSON.stringify(data));
        },
        fail: function (ex) {
            alert(ex);
        }
    });
    });


} catch (e) {
    alert(e);
}

})();