<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta charset="utf-8" /> <title>与 draw.io 语言包对比,自动生成 mxgrap 的语言包</title> </head> <body> </body> </html>
var lg = { asKey: function (txt) { var obj = {}; txt.split('\n').forEach(function (row) { if (row[0] != "#") { var items = row.split('='); obj[items[0]] = items[1] } }) return obj; }, diff: function (key1, key2) { var htm = [], isnull = [], isen = []; for (var i in key1) { if (i != "") { var val = key2[i]; htm.push(i + "=" + (val || "")) if (!val) { isnull.push(i + "=" + (key1[i] || "")) } if (/^[a-zA-Z]+$/.test(val)) { isen.push(i + "=" + val); } } } var ta = document.createElement('textarea'); ta.style.cssText = 'width:100%;height:500px'; ta.value = htm.join('\n') + '\n\n空值:\n' + isnull.join('\n') + '\n\n英文:\n' + isen.join('\n') document.body.appendChild(ta); console.log(ta.value); }, fetch: function (src, fn) { fetch(src).then(x => x.text()).then(fn) }, run: function () { var txt1, txt2; lg.fetch('https://jgraph.github.io/mxgraph/javascript/examples/grapheditor/www/resources/grapheditor.txt', function (txt) { txt1 = txt; }) var lgsrc = "https://www.draw.io/resources/dia_zh.txt"; lg.fetch(lgsrc, function (txt) { txt2 = txt; }) lg.si = setInterval(function () { if (txt1 && txt2) { lg.dc = { txt1, txt2 }; window.clearInterval(lg.si) var key1 = lg.asKey(txt1); var key2 = lg.asKey(txt2); lg.diff(key1, key2); } }, 100) }, init: function () { let domTitle = document.createElement("h4"); domTitle.innerHTML = document.title; document.body.appendChild(domTitle); var btn = document.createElement('button'); btn.innerHTML = "Run"; btn.onclick = function () { lg.run(); } document.body.appendChild(btn); } } lg.init();