1
1
var defaultKey = {
2
- togglePlayAndPauseKeyCode : 'p' ,
3
- jumpToBeginningKeyCode : 'h' ,
4
- jumpToEndKeyCode : 'e' ,
5
- rewindTimeKeyCode : 'a' ,
6
- advanceTimeKeyCode : 's' ,
7
- speedDownKeyCode : 'd' ,
8
- speedUpKeyCode : 'u' ,
9
- resetSpeedKeyCode : 'r' ,
10
- toggleFullscreenKeyCode : 'f' ,
11
- partialLoopKeyCode : 'l' ,
12
- partialLoopPrecision : 100 ,
13
- skipTimeAmount : 5 ,
14
- scrollToPlayerChecked : false ,
15
- rememberPlaybackSpeedChecked : true ,
16
- alwaysShowProgressBarChecked : false ,
2
+ togglePlayAndPauseKeyCode : 'p' ,
3
+ jumpToBeginningKeyCode : 'h' ,
4
+ jumpToEndKeyCode : 'e' ,
5
+ rewindTimeKeyCode : 'a' ,
6
+ advanceTimeKeyCode : 's' ,
7
+ speedDownKeyCode : 'd' ,
8
+ speedUpKeyCode : 'u' ,
9
+ resetSpeedKeyCode : 'r' ,
10
+ toggleFullscreenKeyCode : 'f' ,
11
+ partialLoopKeyCode : 'l' ,
12
+ partialLoopPrecision : 100 ,
13
+ skipTimeAmount : 5 ,
14
+ playOrPauseWhenLoadingSelect : 'default' ,
15
+ scrollToPlayerChecked : false ,
16
+ rememberPlaybackSpeedChecked : true ,
17
+ alwaysShowProgressBarChecked : false ,
17
18
} ;
18
19
19
20
$ ( function ( ) {
@@ -39,6 +40,7 @@ $(function() {
39
40
40
41
function loadOptions ( ) {
41
42
chrome . storage . sync . get ( defaultKey , function ( storage ) {
43
+ // key
42
44
updateInputText ( 'toggle-play-and-pause' , storage . togglePlayAndPauseKeyCode ) ;
43
45
updateInputText ( 'jump-to-beginning' , storage . jumpToBeginningKeyCode ) ;
44
46
updateInputText ( 'jump-to-end' , storage . jumpToEndKeyCode ) ;
@@ -49,8 +51,15 @@ function loadOptions() {
49
51
updateInputText ( 'reset-speed' , storage . resetSpeedKeyCode ) ;
50
52
updateInputText ( 'toggle-fullscreen' , storage . toggleFullscreenKeyCode ) ;
51
53
updateInputText ( 'partial-loop' , storage . partialLoopKeyCode ) ;
54
+
55
+ // numeric
52
56
document . getElementById ( 'partial-loop-precision' ) . value = storage . partialLoopPrecision ;
53
57
document . getElementById ( 'skip-time-amount' ) . value = storage . skipTimeAmount ;
58
+
59
+ // select menu
60
+ document . getElementById ( 'play-or-pause-when-loading' ) . value = storage . playOrPauseWhenLoadingSelect ;
61
+
62
+ // check box
54
63
document . getElementById ( 'scroll-to-player' ) . checked = storage . scrollToPlayerChecked ;
55
64
document . getElementById ( 'remember-playback-speed' ) . checked = storage . rememberPlaybackSpeedChecked ;
56
65
document . getElementById ( 'always-show-progress-bar' ) . checked = storage . alwaysShowProgressBarChecked ;
@@ -75,6 +84,7 @@ function saveOptions() {
75
84
var partialLoopKeyCode = document . getElementById ( 'partial-loop' ) . value ;
76
85
var partialLoopPrecision = document . getElementById ( 'partial-loop-precision' ) . value ;
77
86
var skipTimeAmount = document . getElementById ( 'skip-time-amount' ) . value ;
87
+ var playOrPauseWhenLoadingSelect = document . getElementById ( 'play-or-pause-when-loading' ) . value ;
78
88
var scrollToPlayerChecked = document . getElementById ( 'scroll-to-player' ) . checked ;
79
89
var rememberPlaybackSpeedChecked = document . getElementById ( 'remember-playback-speed' ) . checked ;
80
90
var alwaysShowProgressBarChecked = document . getElementById ( 'always-show-progress-bar' ) . checked ;
@@ -92,9 +102,10 @@ function saveOptions() {
92
102
validateFlag [ 9 ] = checkValidate ( 'partial-loop' ) ;
93
103
validateFlag [ 10 ] = checkValidateNumeric ( 'partial-loop-precision' ) ;
94
104
validateFlag [ 11 ] = checkValidateNumeric ( 'skip-time-amount' ) ;
95
- validateFlag [ 12 ] = checkValidateChecked ( 'scroll-to-player' ) ;
96
- validateFlag [ 13 ] = checkValidateChecked ( 'remember-playback-speed' ) ;
97
- validateFlag [ 14 ] = checkValidateChecked ( 'always-show-progress-bar' ) ;
105
+ validateFlag [ 12 ] = checkValidateSelect ( 'play-or-pause-when-loading' , [ 'default' , 'play' , 'pause' ] ) ;
106
+ validateFlag [ 13 ] = checkValidateChecked ( 'scroll-to-player' ) ;
107
+ validateFlag [ 14 ] = checkValidateChecked ( 'remember-playback-speed' ) ;
108
+ validateFlag [ 15 ] = checkValidateChecked ( 'always-show-progress-bar' ) ;
98
109
99
110
// when some input is wrong.
100
111
for ( var i = 0 ; i < validateFlag . length ; i ++ ) {
@@ -116,6 +127,7 @@ function saveOptions() {
116
127
partialLoopKeyCode : partialLoopKeyCode ,
117
128
partialLoopPrecision : partialLoopPrecision ,
118
129
skipTimeAmount : skipTimeAmount ,
130
+ playOrPauseWhenLoadingSelect : playOrPauseWhenLoadingSelect ,
119
131
scrollToPlayerChecked : scrollToPlayerChecked ,
120
132
rememberPlaybackSpeedChecked : rememberPlaybackSpeedChecked ,
121
133
alwaysShowProgressBarChecked : alwaysShowProgressBarChecked
@@ -234,4 +246,25 @@ function checkValidateChecked(inputID) {
234
246
} else {
235
247
$ ( inputID ) . css ( 'border' , '1px solid #cccccc' ) ;
236
248
}
249
+
250
+ // return value: true -> save the options, false -> do not save.
251
+ if ( errorFlag === true ) {
252
+ return false ;
253
+ } else {
254
+ return true ;
255
+ }
256
+ }
257
+
258
+ function checkValidateSelect ( inputID , menu ) {
259
+ var inputID = '#' + inputID ;
260
+ $ ( inputID ) . parent ( ) . children ( '.invalid-value' ) . remove ( ) ;
261
+ if ( menu . includes ( $ ( inputID ) . val ( ) ) ) {
262
+ $ ( inputID ) . css ( 'border' , '1px solid #cccccc' ) ;
263
+ return true ;
264
+ }
265
+ else {
266
+ $ ( inputID ) . css ( 'border' , '1px solid red' ) ;
267
+ $ ( inputID ) . parent ( ) . append ( '<div class="invalid-value">Invalid value</div>' ) ;
268
+ return false ;
269
+ }
237
270
}
0 commit comments