javascript Processon下载脑图油猴脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Processon下载脑图油猴脚本相关的知识,希望对你有一定的参考价值。
// ==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);
}
})();
以上是关于javascript Processon下载脑图油猴脚本的主要内容,如果未能解决你的问题,请参考以下文章