-
Notifications
You must be signed in to change notification settings - Fork 20
/
notification.js
108 lines (97 loc) · 3.14 KB
/
notification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
$(function(){
var word = location.hash.substr(1);
$("#word").append(word).click(function(){
chrome.tabs.create({
url:'main.html#'+word
});
window.close();
return false;
});
// $("body").click(function(){
// console.log(event.which);
// return false;
// });
// $("#pron_button").click(function(){
// // console.log(word);
// // chrome.extension.sendRequest(word);
// }).on("contextmenu",function(){
// });
$(document.body).mousedown(function(){
if(event.which==2)
window.close();
});
$("#toggle_example").click(function(){
var example = $("#example").toggleClass("hide");
if(example.hasClass("hide")){
localStorage.shownotificationexample="false";
}else{
delete localStorage.shownotificationexample;
}
return false;
});
$("#toggle_chn").click(function(){
var example = $("#chn").toggleClass("hide");
if(example.hasClass("hide")){
localStorage.shownotificationchn="false";
}else{
delete localStorage.shownotificationchn;
}
return false;
});
if(localStorage.shownotificationexample=="false"){
$("#example").toggleClass("hide");
}
if(localStorage.shownotificationchn=="false"){
$("#chn").toggleClass("hide");
}
$("#chn").addClass("hide");
pron_audio.src="http://www.gstatic.com/dictionary/static/sounds/de/0/%s.mp3".format(word);
pron_audio2.src="http://www.gstatic.com/dictionary/static/sounds/de/0/%[email protected]".format(word);
db.sql('SELECT * FROM oald7 WHERE headword=?',[word],function(tx,result){
var content = result.rows.item(0)['content'];
$("#pron").append($(content).find("span.oa_i_phon:first"));
$("#chn").append($(content).find("span.oa_d span.oa_chn,span.oa_ud span.oa_chn").slice(0,3));
var tmpexample = $($(content).find("span.oa_x")[0].childNodes).get();
tmpexample.pop();
tmpexample = tmpexample.map(function(e){
// console.log(e);
return $(e).text();
});
// $("#example").append($(tmpexample).text());
$("#example").append(tmpexample.join(" "));
});
db.sql('SELECT * FROM vocabulary WHERE word=?',[word],function(tx,result){
var time = new Date(result.rows.item(0)['time']);
$("#time").append(time.toSimpleTime2()+"("+timeAgo(new Date()-time)+")");
});
$("#pron_button,body").click(function(){
pron_audio.play();
pron_audio2.play();
});
//设置字体
//中文字体
$("<style>*[class*=chn],button{font-family:%s;}</style>".format(localStorage.chn_fonts),{}).appendTo(document.head);
//英文字体
if(localStorage.eng_font_customize!=undefined&&localStorage.eng_font_customize!=""){
console.log("customize");
setEngFont(localStorage.eng_font_customize);
}else if(localStorage.eng_fonts){
console.log("eng...");
setEngFont(localStorage.eng_fonts);
}else{
console.log("default");
setEngFont("Kotta One");
}
function setEngFont(font){
$("<style>@import url(http://fonts.googleapis.com/css?family=%s);\nhtml,body,button{font-family:'%s';}</style>".format(font.replace(/ /ig,"+"),font)).appendTo(document.head);
}
});
function timeAgo(duration){
if(duration<60*60*1000){
return Math.round(duration/60000)+"分钟前";
}
if(duration<24*60*60*1000){
return Math.round(duration/3600000)+"小时前";
}
return Math.round(duration/86400000)+"天前";
}