This repository has been archived by the owner on Feb 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.html
175 lines (174 loc) · 6.81 KB
/
options.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" charset="utf-8" href="css/options.css"/>
<title>Frodio Player Settings</title>
<script type="text/javascript" charset="utf-8">
function onLoad() {
window.main = chrome.extension.getBackgroundPage();
scrobble.checked = main.opt_scrobble;
notification.checked = main.opt_notification;
seconds.value = main.opt_seconds;
p_seconds.className = main.opt_notification ? '' : 'hidden';
// on change
scrobble.onchange = function() {
main.storage.set('scrobble', this.checked);
if (main.played) main.cookie.set('paused', this.checked ? '0' : '1');
main.opt_scrobble = this.checked;
}
notification.onchange = function() {
main.storage.set('notification', this.checked)
main.opt_notification = this.checked;
p_seconds.className = main.opt_notification ? '' : 'hidden';
}
seconds.oninput = function() {
if (this.value && this.value < 61 && this.value > 0) {
main.storage.set('seconds', this.value)
main.opt_seconds = this.value;
}
}
// shortcut
window.shortcuts = [shortcut_play, shortcut_stop, shortcut_random];
window.current_id = 0;
window.specialKeys = { 19: "Pause", 32: "Space", 33: "PageUp", 34: "PageDown",
35: "End", 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down",
45: "Insert", 46: "Del", 106: "Num *", 107: "Num +", 109: "Num -",
110: "Num .", 111 : "Num /", 112: "F1", 113: "F2", 114: "F3", 115: "F4",
116: "F5", 117: "F6", 118: "F7", 119: "F8", 120: "F9", 121: "F10", 122: "F11",
123: "F12", 188: ",", 190: ".", 191: "/", 192: "~", 186: ";", 222: "'",
220: "\\", 219: "[", 221: "]", 189: "-", 187: "=", 173: "Mute", 174: "VolDown",
175: "VolUp", 176: "Next", 177: "Prev", 178: "Stop", 179: "Play", 181: "Media"
}
for (var i = 0; i < 3; i++) setShortcut(i);
}
function delKeyListenter(){
document.onkeydown = null;
document.onkeyup = null;
}
function edit(id) {
if (id.type) id = current_id;
else {
current_id = id;
document.onkeydown = getShortcut;
document.onkeyup = arguments.callee;
shortcuts[id].children[1].className = "edit";
}
shortcuts[id].children[1].innerText = chrome.i18n.getMessage('press_key');
}
function del(id) {
delKeyListenter();
main.shortcuts[id] = null;
main.storage.set('shortcuts', main.shortcuts);
setShortcut(id);
}
function getShortcut(e) {
var mod = "";
var key = keyName(e.keyCode);
if (e.altKey || e.keyCode == 18) mod += 'Alt + ';
if (e.ctrlKey || e.keyCode == 17) mod += 'Ctrl + ';
if (e.metaKey || e.keyCode == 224) mod += 'Meta + ';
if (e.shiftKey || e.keyCode == 16) mod += 'Shift + ';
if (key) {
main.shortcuts[current_id] = { 'alt': e.altKey, 'ctrl': e.ctrlKey, 'meta': e.metaKey, 'shift': e.shiftKey, 'code': e.keyCode }
delKeyListenter();
if (shortcuts_equivalent(0,1) && shortcuts_equivalent(0,2)) {
main.shortcuts[2] = null;
setShortcut(2);
if (current_id == 2) {
main.storage.set('shortcuts', main.shortcuts);
return false;
}
}
main.storage.set('shortcuts', main.shortcuts);
} else if (e.keyCode != 18 && e.keyCode != 17 && e.keyCode != 16 && e.keyCode != 224 ) {
delKeyListenter();
setShortcut(current_id);
return;
}
shortcuts[current_id].children[1].innerText = mod + (key ? key : '');
return false;
}
function keyName(code) {
if (code >= 48 && code <= 90) return String.fromCharCode(code);
if (code >= 96 && code <= 105) return 'Num ' + String.fromCharCode(code - 48);
if (specialKeys[code]) return specialKeys[code];
}
function setShortcut(id) {
if (main.shortcuts[id] == null) {
shortcuts[id].children[1].className = "edit empty";
shortcuts[id].children[1].innerText = "";
} else {
var key = '';
if (main.shortcuts[id].alt) key += 'Alt + ';
if (main.shortcuts[id].ctrl) key += 'Ctrl + ';
if (main.shortcuts[id].meta) key += 'Meta + ';
if (main.shortcuts[id].shift) key += 'Shift + ';
key += keyName(main.shortcuts[id].code);
shortcuts[id].children[1].className = "edit";
shortcuts[id].children[1].innerText = key;
}
}
function shortcuts_equivalent(id1, id2){
return main.shortcuts[id1] && main.shortcuts[id2] &&
main.shortcuts[id1].alt == main.shortcuts[id2].alt &&
main.shortcuts[id1].ctrl == main.shortcuts[id2].ctrl &&
main.shortcuts[id1].meta == main.shortcuts[id2].meta &&
main.shortcuts[id1].shift == main.shortcuts[id2].shift &&
main.shortcuts[id1].code == main.shortcuts[id2].code;
}
function resetStations() {
main.stop();
main.storage.clear('stations');
main.storage.clear('order');
main.storage.clear('station');
main.init();
main.customNotify('','', chrome.i18n.getMessage('doneResetStations'));
}
function resetAll() {
main.stop();
main.storage.clearAll();
main.init();
main.customNotify('','', chrome.i18n.getMessage('doneResetAll'));
location.reload();
}
</script>
</head>
<body onload="onLoad();">
<header>
Frodio Player
</header>
<div>
<h1 id="options"></h1>
<p>
<label for="scrobble"></label>
<input type="checkbox" id="scrobble"/>
</p>
<p>
<label for="notification"></label>
<input type="checkbox" id="notification"/>
</p>
<p id="p_seconds" class="hidden">
<label for="seconds"></label>
<input type="number" value="3" min="1" max="60" id="seconds"/>
</p>
<h1 id="keys"></h1>
<p id="shortcut_play">
<a class="del after" onclick="del(0);"></a><a class="edit empty" onclick="edit(0);"></a>
</p>
<p id="shortcut_stop">
<a class="del after" onclick="del(1);"></a><a class="edit empty" onclick="edit(1);"></a>
</p>
<p id="shortcut_random">
<a class="del after" onclick="del(2);"></a><a class="edit empty" onclick="edit(2);"></a>
</p>
<p class="note">
</p>
<h1 id="problem"></h1>
<p>
<a id="resetAll" class="reset after" onclick="resetAll();"></a>
<a id="resetStations" class="reset after" onclick="resetStations();"></a>
</p>
</div>
</body>
</html>