-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathoptions.js
More file actions
49 lines (41 loc) · 1.2 KB
/
options.js
File metadata and controls
49 lines (41 loc) · 1.2 KB
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
/*jslint browser: true, es5: true, indent: 4, plusplus: true*/
/*global localStorage */
"use strict";
var swap = document.getElementById('swap'),
itag = document.getElementById('itag'),
auto = document.getElementById('auto'),
fmts = document.getElementById('fmts');
swap.addEventListener('change', function () {
var s = this.options[this.selectedIndex].value;
if (parseInt(s, 10)) {
fmts.removeAttribute('hidden');
} else {
fmts.setAttribute('hidden');
}
localStorage.swap = s;
});
itag.addEventListener('change', function () {
localStorage.itag = this.options[this.selectedIndex].value;
});
auto.addEventListener('change', function () {
localStorage.auto = this.options[this.selectedIndex].value;
});
function init(name, el) {
var i = 0,
s = localStorage[name];
if (!s) {
localStorage[name] = el.options[el.selectedIndex].value;
} else {
for (i = 0; i < el.options.length; ++i) {
if (el.options[i].value === s) {
el.selectedIndex = i;
}
}
}
}
init("swap", swap);
init("itag", itag);
init("auto", auto);
if (parseInt(localStorage.swap, 10)) {
fmts.removeAttribute('hidden');
}