1- const RESIZE_PREFIX = "resize-" ;
2-
31function updateMenuWithPresets ( )
42{
53 let getPresets = browser . storage . local . get ( "presets" ) ;
64 getPresets . then ( ( obj ) => {
75 if ( obj != undefined )
86 {
9- let menu = document . querySelector ( "#presets " ) ;
7+ let list = document . querySelector ( "#presetsList " ) ;
108
119 let presets = obj . presets ;
1210 for ( let i = 0 ; i < presets . length ; i ++ )
1311 {
12+ let linkText = presets [ i ] . width + "x" + presets [ i ] . height + " " + presets [ i ] . name ;
13+ let numberText = " " ;
14+ if ( i < 9 )
15+ {
16+ numberText = ( i + 1 ) + ": " ;
17+ }
18+
19+ let tr = document . createElement ( "tr" ) ;
20+
21+ let tdN = document . createElement ( "td" ) ;
22+ tr . className = "presetIndex" ;
23+ tdN . appendChild ( document . createTextNode ( numberText ) ) ;
24+ tr . appendChild ( tdN ) ;
25+
26+ let tdL = document . createElement ( "td" ) ;
27+
1428 let a = document . createElement ( "a" ) ;
1529 a . href = "#" ;
16- a . id = RESIZE_PREFIX + presets [ i ] . width + "x" + presets [ i ] . height ;
17- a . appendChild ( document . createTextNode ( presets [ i ] . width + "x" + presets [ i ] . height + " " + presets [ i ] . name ) ) ;
18- menu . appendChild ( a ) ;
30+ a . id = PRESET_PREFIX + presets [ i ] . id ;
31+ a . appendChild ( document . createTextNode ( linkText ) ) ;
32+ tdL . appendChild ( a ) ;
33+
34+ tr . appendChild ( tdL ) ;
1935
20- let br = document . createElement ( "br" ) ;
21- menu . appendChild ( br ) ;
36+ list . appendChild ( tr ) ;
2237 }
2338 }
2439 } ) ;
25-
2640}
2741
2842function doMenuClick ( e )
@@ -33,19 +47,10 @@ function doMenuClick(e)
3347 {
3448 browser . runtime . openOptionsPage ( ) ;
3549 }
36- else if ( myId . startsWith ( RESIZE_PREFIX ) )
50+ else if ( myId . startsWith ( PRESET_PREFIX ) )
3751 {
38- let xPos = myId . indexOf ( "x" , RESIZE_PREFIX . length ) ;
39- let newWidth = parseInt ( myId . substring ( RESIZE_PREFIX . length , xPos ) ) ;
40- let newHeight = parseInt ( myId . substring ( xPos + 1 ) ) ;
41- let updateInfo = {
42- "width" : newWidth ,
43- "height" : newHeight
44- } ;
45-
46- browser . windows . getCurrent ( ) . then ( ( currentWindow ) => {
47- browser . windows . update ( currentWindow . id , updateInfo ) ;
48- } ) ;
52+ let presetId = myId . substring ( PRESET_PREFIX . length ) ;
53+ applyPreset ( presetId ) ;
4954 }
5055
5156 e . preventDefault ( ) ;
0 commit comments