-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
104 lines (95 loc) · 3.59 KB
/
popup.html
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
<!doctype html>
<html>
<head>
<script>
var bg = chrome.extension.getBackgroundPage();
function callback_get_data(data) {
var list = document.getElementById("current");
var old_list = document.getElementById("pattern_list");
if (old_list != null)
list.removeChild(old_list);
var ul = document.createElement("ul");
ul.setAttribute("id", "pattern_list");
for (var entry in data) {
var li = document.createElement("li");
for (var ms_index in data[entry]["seconds"])
li.innerHTML += data[entry]["seconds"][ms_index] + ",";
li.innerHTML += data[entry]["inputtext"];
ul.appendChild(li);
}
list.appendChild(ul);
console.log(data);
}
function add_written_data() {
var inputtext = document.register_form.inputtext.value;
var milliseconds = [];
var ms1 = document.register_form.ms1.value;
if (ms1 != "") milliseconds.push(ms1 - 0);
var ms2 = document.register_form.ms2.value;
if (ms2 != "") milliseconds.push(ms2 - 0);
var ms3 = document.register_form.ms3.value;
if (ms3 != "") milliseconds.push(ms3 - 0);
var ms4 = document.register_form.ms4.value;
if (ms4 != "") milliseconds.push(ms4 - 0);
var ms5 = document.register_form.ms5.value;
if (ms5 != "") milliseconds.push(ms5 - 0);
var ms6 = document.register_form.ms6.value;
if (ms6 != "") milliseconds.push(ms6 - 0);
if (milliseconds.length != 0 && inputtext != "") {
// It adds a data.
bg.add_data(milliseconds, inputtext, function () {
document.register_form.inputtext.value = "";
document.register_form.ms1.value = "";
document.register_form.ms2.value = "";
document.register_form.ms3.value = "";
document.register_form.ms4.value = "";
document.register_form.ms5.value = "";
document.register_form.ms6.value = "";
bg.get_data(callback_get_data);
} );
}
}
function clear_data() {
// It creates a clear tapping data file.
bg.create_or_clear_data(function () {
bg.get_data(callback_get_data);
});
}
</script>
</head>
<body>
<h1>Tap text</h1>
<div style="border: 1px solid; margin: 1em; padding: 1em">
<form name="register_form">
<div id="milliseconds">
<input type="text" id="ms1" name="ms1" size="4"></input>
<input type="text" id="ms2" name="ms2" size="4"></input>
<input type="text" id="ms3" name="ms3" size="4"></input>
<input type="text" id="ms4" name="ms4" size="4"></input>
<input type="text" id="ms5" name="ms5" size="4"></input>
<input type="text" id="ms6" name="ms6" size="4"></input>
</div>
<input type="text" id="inputtext" name="inputtext" size="80"></input>
<input type="button" value="Register" onclick="add_written_data()"></input>
<input type="button" value="Clear All" onclick="clear_data()"></input>
</form>
</div>
<div id="current"></div>
<script>
console.log("doing");
chrome.browserAction.setIcon({path:"icon.png"});
// It gets registered data from the saved file.
bg.get_data(callback_get_data);
if (bg.getInputPattern() != null) {
document.getElementById("inputtext").value = bg.getInputValue();
if(bg.getInputPattern().length > 0) document.getElementById("ms1").value = bg.getInputPattern()[0];
if(bg.getInputPattern().length > 1) document.getElementById("ms2").value = bg.getInputPattern()[1];
if(bg.getInputPattern().length > 2) document.getElementById("ms3").value = bg.getInputPattern()[2];
if(bg.getInputPattern().length > 3) document.getElementById("ms4").value = bg.getInputPattern()[3];
if(bg.getInputPattern().length > 4) document.getElementById("ms5").value = bg.getInputPattern()[4];
if(bg.getInputPattern().length > 5) document.getElementById("ms6").value = bg.getInputPattern()[5];
}
console.log("done");
</script>
</body>
</html>