-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·81 lines (71 loc) · 3.33 KB
/
main.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
var window_id = "";
var obj= {};
var state_text;
var timer_min;
$(document).ready(function(){
// window idを取る
chrome.windows.getCurrent(function(win){
window_id = win.id;
obj[window_id] ={
"id": window_id,
"state_text": "",
"timer_min": ""
};
console.log(window_id);
chrome.storage.local.get(window_id.toString(10), function(items) {
console.log("データ取る" );
console.log(items[window_id]);
if(items[window_id]){
state_text = items[window_id].state_text;
timer_min = items[window_id].timer_min;
if(state_text){
$("#state").text(state_text);
}
if(timer_min){
$("#timer_min").val(timer_min);
}
}
});
});
$("#exec").on('click',function(){
timer_min = $("#timer_min").val();
if(timer_min == 0 ){
$("#state").append("時間を設定してください");
return;
}
obj[window_id].state_text = "実行中";
obj[window_id].timer_min = timer_min;
chrome.storage.local.set(obj,function(){
$("#state").text("実行中");
exec();
});
});
$("#stop").on('click', function(){
console.log("stop");
obj[window_id].state_text = "停止中";
chrome.storage.local.set(obj,function(){
$("#state").text("停止中");
stop();
}
);
});
});
/*
* バックグラウンドによる自動タブ遷移を開始
*/
function exec() {
chrome.runtime.sendMessage({
"action": "start",
"params": {
id: window_id,
timer_min: obj[window_id].timer_min
}
},
function(response) {}
);
}
function stop(){
chrome.runtime.sendMessage({"action": "stop", "params": obj},
function(response) {}
);
}