-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
79 lines (53 loc) · 1.98 KB
/
popup.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
function Message(type,value){
this.type = type;
this.value = value;
}
function update_index(response){
// update current index and total number in popup.html
}
function key_change(event){
//send key word as message to content script
var key = event.currentTarget.value;
var msg = new Message("key",key);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, msg, update_index);
console.log("sending message:" + msg);
});
}
function search_click(event){
//send message to current active tab
var action = event.currentTarget.name;
var msg = new Message("search_action",action);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, msg, update_index);
console.log("sending message:" + msg);
});
}
function case_sensitive(event){
var isChecked = event.currentTarget.checked;
var msg = new Message("case_sensitive",isChecked);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, msg, update_index);
console.log("sending message:" + msg);
});
}
function words_filter(event){
var isChecked = event.currentTarget.checked;
var msg = new Message("words",isChecked);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, msg, update_index);
console.log("sending message:" + msg);
});
}
document.addEventListener("DOMContentLoaded",function(){
var key = document.getElementById("search-key");
key.addEventListener("change",key_change);
var up = document.getElementById("up-search");
up.addEventListener("click",search_click);
var down = document.getElementById("down-search");
down.addEventListener("click",search_click);
var casesen = document.getElementById("case-sensitive");
casesen.addEventListener("click",case_sensitive);
var words = document.getElementById("words");
words.addEventListener("click",words_filter);
});