Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Flucy.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
<button onclick="a()">导入</button>
<button onclick="b()">导出</button>
</div>
<div class="right" id="translate">
<!--<textarea name="" cols="30" rows="30"></textarea>-->
</div>
<div class="right" id="translate"></div>
</section>
</body>
<script src="index.js"></script>
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

- [x] 增加JSON校验错误提示
- [x] 增加控制台版本报告
- [ ] 增加控制台`issue`提交路径信息
- [ ] 增加`markdown`格式支持,可能要定制语法,防止`<pre>`标签
- [x] 增加控制台`issue`提交路径信息
- [x] 增加`markdown`格式支持,可能要定制语法,防止`<pre>`标签
- [ ] 增加json文件直接导入功能
- [ ] 增加json文件直接导出功能,生成前再校验一次
- [ ] 增加页面重置功能,避免刷新,重置前提示用户
- [ ] 增加tests翻译功能
- [ ] 调整页面按钮文案,避免和新功能混淆
- [x] 增加页面重置功能,避免刷新,重置前提示用户
- [x] 增加tests翻译功能
- [x] 调整页面按钮文案,避免和新功能混淆
- [ ] 增加翻译提示功能,及语言转换选项
- [ ] 增加description语言分支选择功能,多语言版本
- [ ] 增加description语言分支选择功能,多语言版本

## 已知bug - 覆盖测试下

1. basic-bonfires.json / basic-ziplines.json / front-end-development-certificate.json / gear-up-for-success.json / data-visualization-certificate.json / api-projects.json / back-end-development-certificate.json /里导出或导入错误,它的discription里面还有数组,我把它扁平化了
2. front-end-development-certificate.json / chromedevtools.json / bigonotation.json / computer-basics.json / dom.json / jslingo.json没用断言,用的别的,上面的有些也是这个原因
3. basic-js.json 中后几个断言中没有message字段
6 changes: 6 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ body, section, div {
}
.container div textarea {
width: 100%;
}
.mainText {
color: black;
}
.testsText {
color: blue;
}
109 changes: 94 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,129 @@ var str ='';
var obj = {
challenges: []
};
console.log("Flucy~v0.1.3");

String.prototype.markdown2Html = function markdown2Html() {
var parten = {
strong: {
exp: /(?:\*\*)(.+?)(?:\*\*)/gi,
html: [" <strong>", "</strong> "]
},
code: {
exp: /(?:\`)(.+?)(?:\`)/gi,
html: [" <code>", "</code> "]
}
}
var result = this.toString();
for (currentParten in parten) {
if (parten.hasOwnProperty(currentParten)) {
result = result.replace(parten[currentParten].exp, function () {
console.log(arguments);
return parten[currentParten].html[0] + arguments[1] + parten[currentParten].html[1];
})
}
}
return result
}
console.log("Flucy~ v0.1.5 @KevinHu-1024");
console.log("bug反馈地址:https://github.com/KevinHu-1024/Flucy/issues");
console.log("本工具来自FreeCodeCamp中文社区翻译组:https://github.com/huluoyang/freecodecamp.cn/wiki");
console.log("FreeCodeCamp中文社区:https://freecodecamp.cn");
function a() {
if (translate.innerHTML != '') {
var con = confirm("导入时会重置右侧内容!");
if (!con) {
return
}
}
source.disabled = 'disabled';
translate.innerHTML = '';
json = null;
str ='';
obj = {
challenges: []
};
try {
json = JSON.parse(source.value);
} catch (error) {
alert("JSON格式有误,请检查控制台错误信息");
console.log(error);
return
}
var main = document.createElement('h3');
main.innerHTML = json.name;
main.style = "color:red;";
translate.appendChild(main);
var link = document.createElement('a');
link.innerHTML = title;
link.href = "https://github.com/KevinHu-1024/Flucy/releases/";
link.style = "text-align:right;font-size:12px;color:grey;text-decoration:none;";
translate.appendChild(link);
var frg = document.createDocumentFragment();
for(var i = 0; i < json.challenges.length; i++) {
var cur = json.challenges[i];
str += "<h4 style='color:green;text-decoration:underline'>" + (i+1) + "." + cur.title +"</h4>"
var ti = document.createElement('h4');
ti.style = "color:green;text-decoration:underline";
ti.innerHTML = (i+1) + "." + cur.title;
frg.appendChild(ti);
obj.challenges.push({
dis:[]
dis:[],
tes:[]
})
for (var j = 0; j < cur.description.length; j ++) {
str += "<textarea rows='5'>"+cur.description[j]+"</textarea>";
var tex = document.createElement('textarea');
tex.value = cur.description[j];
tex.className = "mainText";
tex.rows = 5;
frg.appendChild(tex);
tex = null;
obj.challenges[i].dis.push(cur.description[j]);
}
for (var n = 0; n < cur.tests.length; n++) {
var tesTex = document.createElement('textarea');
// console.log(n, cur.tests[n]);
tesTex.value = /(?:\'message\:)(.+)(?:\'\))/gi.exec(cur.tests[n])[1];
tesTex.className = "testsText";
tesTex.rows = 5;
frg.appendChild(tesTex);
tesTex = null;
obj.challenges[i].tes.push(cur.tests[n]);
}
}
console.log(json);
console.log(obj);
translate.innerHTML = "<h3 style='color:red'>" + json.name +"</h3>" + "<a href='https://github.com/KevinHu-1024' style='text-align:right;font-size:12px;color:grey;text-decoration:none'>" + title + "</a>" + str;
translate.appendChild(frg);
}
function b() {
var collection = translate.getElementsByTagName("textarea");
if (source.value != '') {
var con = confirm("导出时会重置左侧内容!");
if (!con) {
return
}
}
source.value = '';
var mainTextCollection = translate.getElementsByClassName("mainText");
var testsTextCollection = translate.getElementsByClassName("testsText");
var i = 0;
// console.log(collection);
var h = 0;
for (var m = 0; m < obj.challenges.length; m++) {
var tar = obj.challenges[m];
for (var j = 0; j < tar.dis.length; j++) {
tar.dis[j] = collection[i].value.replace(/(\<code\>)(\s\s)/gi, '$1&nbsp;&nbsp;').replace(/(\<br\>)(\s\s)/gi, '$1&nbsp;&nbsp;');
tar.dis[j] = mainTextCollection[i].value.markdown2Html();
i ++;
}
for (var n = 0; n < tar.tes.length; n++) {
tar.tes[n] = testsTextCollection[h].value.markdown2Html() + "');";
h ++;
}
}
console.log(obj);
for (var k = 0; k < obj.challenges.length; k++) {
json.challenges[k].description = obj.challenges[k].dis;
for (var t = 0; t < obj.challenges[k].tes.length; t++) {
obj.challenges[k].tes[t] = /^(assert)(.+)(?:'message:)/gi.exec(json.challenges[k].tests[t])[0] + obj.challenges[k].tes[t];
json.challenges[k].tests[t] = obj.challenges[k].tes[t];
}
}
console.log(json);
source.value = JSON.stringify(json, null, 2);
}
// 提取tests中某项的message:
// /(?:\'message\:)(.+)(?:\))/gi.exec("assert((function(){var testCar = new Car(3,1,2); return testCar.wheels === 3 && testCar.seats === 1 && testCar.engines === 2;})(), 'message: Calling <code>new Car(3,1,2)</code> should produce an object with a <code>wheels</code> property of <code>3</code>, a <code>seats</code> property of <code>1</code>, and an <code>engines</code> property of <code>2</code>.');")[1]
//转义
//"<code> return valorAnterior - valorActual;</code>".replace(/(\<code\>)(\s\s)/gi, '$1&nbsp;&nbsp;')
//"<br> return valorAnterior - valorActual;</br>".replace(/(\<br\>)(\s\s)/gi, '$1&nbsp;&nbsp;')
source.value = JSON.stringify(json, null, 2) + "\n";
}