Watch 1 Star 0 Fork 0

netnr / jcuteJavaScriptMIT

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
Clone or download
builder.html 2.95 KB
Copy Edit Web IDE Raw Blame History
netnr authored 2018-05-19 19:53 . update
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>生成</title>
<style>
.tb {
margin: 15px 0;
border-collapse: collapse;
}
.tb tr th, .tb tr td {
padding: 3px 5px;
border: 1px solid #999;
}
#txtOut {
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<input type="file" id="txtFile" webkitdirectory directory multiple /><button id="btnBuilder">生成</button>
<div id="dirinfo"></div>
<textarea id="txtOut"></textarea>
<script src="src/jcute.all.js"></script>
<script>
var txts = [];
document.getElementById('txtFile').onchange = function () {
var dirinfo = '<table class="tb"><tr><th>file name</th><th>path</th><th>size<th>type</tr>';
for (var i = 0, file; file = this.files[i]; i++) {
if ("jCute.all.js,jCute.js".indexOf(file.name) >= 0 || file.name.indexOf('.js') == -1) {
continue;
}
pick(file);
var fileSize = 0;
if (file.size > 1024 * 1024)
fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
else
fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
dirinfo += '<tr><td>' + file.name + '<td>' + file.webkitRelativePath + '<td>' + fileSize + '<td>' + file.type + '</tr>';
}
dirinfo += '</table>';
document.getElementById('dirinfo').innerHTML = dirinfo;
}
function pick(file) {
var reader = new FileReader(), txts = [];
txts.push('\r\n----------');
txts.push('### [' + file.name + '](https://jcute.netnr.com/view.html?' + file.name.toLowerCase() + ')');
txts.push('```js');
reader.onload = function () {
var notes = [], funcs = [];
this.result.replace(/\/\*\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g, function (value) {
notes.push(value);
}).replace(/jCute\..*{/g, function (value) {
funcs.push(value);
});
console.log(notes, funcs)
if (notes.length == funcs.length) {
for (var i = 0, len = funcs.length; i < len; i++) {
txts.push(notes[i]);
txts.push(funcs[i].replace(' = function ', '').replace(' {', '') + '\r\n');
}
} else {
alert(file.name + ' ,方法必须带注释');
return false;
}
txts.push('```');
document.getElementById('txtOut').value += txts.join('\r\n');
};
reader.readAsText(file);
}
</script>
</body>
</html>

Comment ( 0 )

You need to Sign in for post a comment

Help Search