提交 57963777 编写于 作者: C CodFrm

本地题库导入&检索

上级 ae8f4a3b
......@@ -181,4 +181,10 @@ export function switchTask() {
next.nextElementSibling.getElementsByTagName('a')[0].firstElementChild.className = 'currents';
console.log('next task');
return true;
}
export function dealRegx(str, topic) {
str = str.replace('{topic}', '[\\s\\S]*?' + topic + '[\\s\\S]*?');
str = str.replace('{answer}', '(\\S+?)');
return str;
}
\ No newline at end of file
......@@ -9,7 +9,56 @@
<%= htmlWebpackPlugin.options.title %>
</title>
</head>
<style>
body {
padding: 0 20%;
}
h4 {
margin: 8px 0;
}
.content {
width: 100%;
min-height: 400px;
padding: 4px 8px;
font-size: 14px;
}
.bor {
box-sizing: border-box;
outline: none;
border: 1px solid #eee;
}
.bor:focus,
.bor:hover {
border: 1px solid #a5d7ff;
}
.ipt-text {
padding: 4px;
width: 100%;
font-size: 14px;
}
.sub-btn {
margin-left: calc(100% - 80px);
width: 80px;
margin-top: 8px;
}
</style>
<body>
<h4>题库内容:</h4>
<textarea id="content" class="content bor"></textarea>
<br>
<input id="regx" class="ipt-text bor" type="text" value="" placeholder="正则表达式,题目用 {topic} 代替">
<button id="submit" class="sub-btn">确定</button>
<h4>匹配测试</h4>
<input id="topic" class="ipt-text bor" type="text" value="" placeholder="题目标题">
<button id="test" class="sub-btn">测试</button>
<div id="result" style="width: 100%;">结果</div>
</body>
</html>
\ No newline at end of file
const common = require('./common');
chrome.storage.local.get([
'topic_regx',
'topics',
'topic_time'
], function (items) {
//读取题库信息
document.getElementById('regx').value=items.topic_regx;
document.getElementById('content').value=items.topics;
});
document.getElementById('submit').onclick = function () {
chrome.storage.local.set({
'topic_regx': document.getElementById('regx').value,
'topics': document.getElementById('content').value,
'topic_time': Date.parse(new Date())
}, function () {
alert('保存成功');
});
}
document.getElementById('test').onclick = function () {
var reg = new RegExp(common.dealRegx(document.getElementById('regx').value, document.getElementById('topic').value));
console.log(reg);
var str = document.getElementById('content').value;
var arr = reg.exec(str);
if (arr.length > 0) {
document.getElementById('result').innerHTML = '匹配内容:<br />' + arr[0];
document.getElementById('result').innerHTML += '<br /><br /><span style="color:red;">匹配答案:' + (arr.length >= 2 ? arr[1] : '') + '</span>';
}
}
\ No newline at end of file
......@@ -61,6 +61,8 @@
<label for="interval" title="播放(题目)完成后n分钟再继续下一个任务">间隔时间:</label>
<input type="text" id="interval" style="font-size: 10px;width: 30%" placeholder="分钟" />
</div>
<br>
<a href="import.html" target="_black">题库导入</a>
</div>
<div>
<h4>其他说明:</h4>
......
......@@ -10,13 +10,29 @@ window.onload = function () {
return;
}
}
injected(document, 'mooc.js');
document.head.setAttribute('chrome-url', chrome.extension.getURL(''));
chrome.storage.sync.get(['rand_answer','interval','auto'], function (items) {
chrome.storage.sync.get([
'rand_answer',
'interval',
'auto'
], function (items) {
//设置一下配置
document.head.setAttribute('rand-answer', items.rand_answer);
localStorage['config'] =JSON.stringify(items);
localStorage['config'] = JSON.stringify(items);
});
chrome.storage.local.get([
'topic_regx',
'topics',
'topic_time'
], function (items) {
//读取题库信息
if (localStorage['topic_time'] == undefined || localStorage['topic_time'] < items.topic_time) {
localStorage['topic_regx'] = items.topic_regx;
localStorage['topics'] = items.topics;
localStorage['topic_time'] = items.topic_time;
}
});
injected(document, 'mooc.js');
})
}
......
......@@ -6,7 +6,8 @@ module.exports = {
start: __dirname + '/src/cxmooc-tools/start.js',
action: __dirname + '/src/cxmooc-tools/action.js',
background: __dirname + '/src/cxmooc-tools/background.js',
popup: __dirname + '/src/cxmooc-tools/popup.js'
popup: __dirname + '/src/cxmooc-tools/popup.js',
import: __dirname + '/src/cxmooc-tools/import.js'
},
output: {
path: __dirname + '/build/cxmooc-tools/src',
......@@ -26,12 +27,12 @@ module.exports = {
new htmlWebpackPlugin({
filename: __dirname + '/build/cxmooc-tools/src/import.html',
template: __dirname + '/src/cxmooc-tools/import.html',
inject: 'head',
inject: 'body',
title: '导入页面',
minify: {
removeComments: true
},
chunks: ['popup']
chunks: ['import']
})
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册