processon 导出

支持脑图文本导出

As of 29.11.2019. See апошняя версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         processon 导出
// @namespace    http://akoala.me/
// @version      0.1
// @description  支持脑图文本导出
// @author       akoala.me
// @match  *://www.processon.com/*
// @grant        none
// @require      https://cdn.bootcss.com/FileSaver.js/2014-11-29/FileSaver.min.js
// ==/UserScript==

//
var timeout = 300;

(function () {
    setTimeout(function () {
        // Your code here...
        
        // 导航
        var $nav = $(".vital")
        // 是否为脑图
        var $mind_designer = $(".mind-designer")
        // 大纲
        var $outline_dlg = $(".outline-dlg")
        var $title = $(".outline-tittle");
        var $content = $("#outline-container")

        addBtn();
        bindExport();

        // 是否为脑图
        function isMindView() {
            return !!($mind_designer[0])
        }

        // 添加导出按钮
        function addBtn() {
            if (isMindView()) {
                $nav.prepend(`<button id="exportIt">导出</button>`)
            } else {
                $nav.prepend(`<button disable>非脑图,不支持导出</button>`)
            }
        }

        // 获取结果
        function getResult(){
           // debugger
           var cld = []
           var els = $content.children(".node-element")
           for (let i = 0; i < els.length; i++) {
               cld.push(getContent(els[i]))
           }
            return {
                title: getTitle(),
                children: cld
            }
        }

        // 获取标题
        function getTitle() {
            return $title.html()
        }

        // 获取内容,param->node-element
        function getContent(node) {
             debugger;
            if(!node) return null;
            var $node = $(node)
            var obj = {};
            var children = [];
            obj.title = $node.find(".node-self .node-title").html();

            var $children = $node.children(".node-children").children(".node-element")
            if ($children.length > 0) {
                for (let i = 0; i < $children.length; i++) {
                    children.push(getContent($children[i]))
                }
                obj.children = children;
            }

            return obj;

        }

        // 导出
        function exportIt() {
            // 切换为大纲
            $(".item.abstract").click();

            var result = getResult();
            console.log(result)
            exportTxt(result)
        }

        // 绑定事件
        function bindExport(){
            $nav.on("click","#exportIt", exportIt)
        }

        // 导出json文件
        function exportJson(result){
             var blob = new Blob([JSON.stringify(result,"", "\t")], {type: "text/plain;charset=utf-8"});
             saveAs(blob, "mind.json");
        }

        /**导出txt文件 start*/
        var uSpan = "\t"
        var uLine = "\n"
        function getNode(json, span) {
            // debugger
            if (!json) return ""
            var txt = span + json.title + uLine;

            if (json.children) {
                for (let i = 0; i < json.children.length; i++) {
                    txt += getNode(json.children[i], span + uSpan)
                }
            }
            return txt;
        }

        function exportTxt(result){
             var blob = new Blob([getNode(result, "")], {type: "text/plain;charset=utf-8"});
             saveAs(blob, getTitle()+".txt");
        }
         /**导出txt文件 end*/
    }, timeout);
})();