|
@@ -3,20 +3,26 @@
|
|
|
* @Version 1.0 (2019-04-21)
|
|
|
* @License MIT
|
|
|
*/
|
|
|
-var bg;
|
|
|
+var bg,delWord;
|
|
|
$(function(){
|
|
|
$('.loading').addClass('on').find('p').text('词库读取中,请稍后...');
|
|
|
chrome.runtime.getBackgroundPage(function(background){
|
|
|
bg = background;
|
|
|
- buildNormalList();
|
|
|
buildStarList();
|
|
|
$('.showTimeSets input').val(bg.setting.timerMin);
|
|
|
});
|
|
|
|
|
|
chrome.runtime.onMessage.addListener(function(msg){
|
|
|
+ if(msg=="updateList") buildNormalList();
|
|
|
if(msg=="updateStarList") buildStarList();
|
|
|
})
|
|
|
|
|
|
+ chrome.notifications.onButtonClicked.addListener(function(e,index){
|
|
|
+ if(e!='deleteword') return;
|
|
|
+ if(index==0) bg.deleteWord(delWord);
|
|
|
+ delWord = null;
|
|
|
+ })
|
|
|
+
|
|
|
$('.tabContent .list').on('click','li a.info',function(){
|
|
|
var word = $(this).parents('li').data('word');
|
|
|
bg.showWordInfo(word);
|
|
@@ -31,6 +37,13 @@ $(function(){
|
|
|
$(this).html('<i class="fa fa-star'+(toType==1?'':'-o')+'"></i>');
|
|
|
|
|
|
});
|
|
|
+ $('.tabContent .list').on('click','li a.del',function(){
|
|
|
+ delWord = $(this).parents('li').data('word');
|
|
|
+ chrome.notifications.create('deleteword',{iconUrl:'../asset/img/logo@x128.png',message:'确定从词库中删除['+delWord+']单词么?',type:'basic',title:'移除单词!',buttons:[{title:'Yes'},{title:'No'}]});
|
|
|
+ // if(confirm('确定从词库中删除['+word+']单词么?')){
|
|
|
+ // bg.deleteWord(word);
|
|
|
+ // }
|
|
|
+ });
|
|
|
$('.title a.minimize').click(function(){
|
|
|
chrome.app.window.current().minimize();
|
|
|
});
|
|
@@ -50,32 +63,14 @@ $(function(){
|
|
|
$("#my_file").trigger('click');
|
|
|
})
|
|
|
$("#my_file").on('change',function(){
|
|
|
+ if($('#my_file')[0].files.length==0) return;
|
|
|
$('.loading').addClass('on').find('p').text('词库导入中,请稍后...');
|
|
|
- var wordCount = 0;
|
|
|
var file = $('#my_file')[0].files[0];
|
|
|
var reader = new FileReader();
|
|
|
reader.readAsText(file, "utf-8");
|
|
|
reader.onload = function (e) {
|
|
|
var tmpArr = e.target.result.split("\n");
|
|
|
- var word;
|
|
|
- if(tmpArr.length>0){
|
|
|
- for(var i = 0;i<tmpArr.length;i++){
|
|
|
- word = (tmpArr[i]).toLowerCase();
|
|
|
- if(!bg.wordDataObj[word]){
|
|
|
- wordCount++;
|
|
|
- bg.wordDataObj[word] = {testCount:0}
|
|
|
- bg.wordDataArr.push(word);
|
|
|
- }
|
|
|
- // wordsObj[word] = {testCount:0}
|
|
|
- };
|
|
|
- if(wordCount>0) bg.wordDataArr.sort();
|
|
|
- }
|
|
|
- chrome.storage.local.set({wordsArr:bg.wordDataArr,wordsObj:bg.wordDataObj},function(e){
|
|
|
- chrome.notifications.create('importNotifi'+(new Date().getTime()),{iconUrl:'../asset/img/logo@x128.png',message:'词库导入成功\n本次共导入['+wordCount+']个新单词',type:'basic',title:'导入完成!'});
|
|
|
- $('.loading').removeClass('on');
|
|
|
- // console.log('导入完成',e);
|
|
|
- buildNormalList();
|
|
|
- })
|
|
|
+ bg.importWord(tmpArr);
|
|
|
}
|
|
|
});
|
|
|
$('.settings a.save').click(function(){
|
|
@@ -88,6 +83,25 @@ $(function(){
|
|
|
$('.loading').removeClass('on');
|
|
|
})
|
|
|
});
|
|
|
+ $('.settings button#importWord').click(function(){
|
|
|
+ chrome.app.window.create('windows/import.html', {
|
|
|
+ id:'import',
|
|
|
+ resizable:false,
|
|
|
+ alwaysOnTop:true,
|
|
|
+ innerBounds:{width:300,height:400},
|
|
|
+ // hidden:true,
|
|
|
+ frame:{type:'none'}
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.importForm .ok').click(function(){
|
|
|
+ var list = $('.importForm textarea').val().split('\n');
|
|
|
+ bg.importWord(list);
|
|
|
+ chrome.app.window.current().close();
|
|
|
+ });
|
|
|
+ $('.importForm .cancel').click(function(){
|
|
|
+ chrome.app.window.current().close();
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
function buildNormalList(listIndex){
|