Created
February 19, 2019 06:43
-
-
Save jianyun8023/d6c5651df3e2dbf98abfe67c7201a481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment