22
33var browser = browser || chrome ; //for Chrome
44
5- // Don't need to listen preference change, the user should do it manually. Navigate between panels/tabs autohide popups
5+ function createPanelListItem ( label ) {
6+ // insertAdjacentHTML is considered unsafe by AMO when concatenated with variables
7+ /*
8+ <div class="panel-list-item">
9+ <div class="text">${label}</div>
10+ </div>`
11+ */
12+ let root = document . createElement ( "div" ) ;
13+ root . classList . add ( "panel-list-item" ) ;
14+ let text = document . createElement ( "div" ) ;
15+ text . classList . add ( "text" ) ;
16+ text . textContent = label ;
17+ root . appendChild ( text ) ;
18+
19+ return root ;
20+ }
621
722/**
823 * Create all context menu for the given bookmarklet tree
@@ -24,9 +39,7 @@ function createAllContextMenuItems(bookmarklets, flat = false){
2439 let bookmarkletsRoot = bookmarklets [ 0 ] ;
2540 // If no bookmarklets
2641 if ( ! bookmarkletsRoot || bookmarkletsRoot instanceof backgroundWindow . BookmarkletFolder && bookmarkletsRoot . children . length == 0 ) {
27- parent . insertAdjacentHTML ( "beforeend" , `<div class="panel-list-item">
28- <div class="text">${ browser . i18n . getMessage ( "contextMenuItemEmpty" ) } </div>
29- </div>` ) ;
42+ parent . appendChild ( createPanelListItem ( browser . i18n . getMessage ( "contextMenuItemEmpty" ) ) ) ;
3043 return ;
3144 }
3245
@@ -53,9 +66,7 @@ function createContextMenuItems(bookmarklet, parentContextMenu, flat = false){
5366
5467 if ( ! flat ) {
5568 // TODO, add panel?
56- parentContextMenu . insertAdjacentHTML ( "beforeend" , `<div class="panel-list-item">
57- <div class="text">${ bookmarklet . title } </div>
58- </div>` ) ;
69+ parentContextMenu . appendChild ( createPanelListItem ( bookmarklet . title ) ) ;
5970 parent = parentContextMenu . lastChild ;
6071 }
6172
@@ -64,9 +75,7 @@ function createContextMenuItems(bookmarklet, parentContextMenu, flat = false){
6475 return ;
6576 }
6677
67- parentContextMenu . insertAdjacentHTML ( "beforeend" , `<div class="panel-list-item">
68- <div class="text">${ bookmarklet . title } </div>
69- </div>` ) ;
78+ parentContextMenu . appendChild ( createPanelListItem ( bookmarklet . title ) ) ;
7079 parentContextMenu . lastChild . addEventListener ( "click" , contextMenuItemClick . bind ( null , bookmarklet ) ) ;
7180}
7281
0 commit comments