@@ -45,14 +45,28 @@ class StickerRenderer {
45
45
storeURL : 'https://store.line.me/stickershop/' ,
46
46
noIcon : true ,
47
47
} ) ;
48
- this . stickerContainer . appendChild ( favoritesDiv ) ;
49
- this . setUpDraggableFavorites ( favoritesDiv ) ;
48
+ if ( favoritesDiv ) {
49
+ this . stickerContainer . appendChild ( favoritesDiv ) ;
50
+ this . setUpDraggableFavorites ( favoritesDiv ) ;
51
+ }
52
+
53
+ // set click to scroll to pack on icon for most-used and favorite
54
+ const icons = [ 'most-used' , 'favorites' ] ;
55
+ for ( const icon of icons ) {
56
+ const iconDiv = document . getElementById ( `${ icon } -icon` ) ;
57
+ iconDiv . addEventListener ( 'click' , ( e ) => {
58
+ const stickerPackDiv = document . getElementById ( `sticker-pack-container-${ icon } ` ) ;
59
+ stickerPackDiv . scrollIntoView ( { behavior : 'instant' } ) ;
60
+ } ) ;
61
+ }
50
62
51
63
for ( const stickerPackID of this . stickerPacksOrder ) {
52
64
const stickerPack = this . stickerPacksMap [ stickerPackID ] ;
53
65
54
66
const stickerPackDiv = this . makeAndSetUpStickerPack ( stickerPackID , stickerPack ) ;
55
- this . stickerContainer . appendChild ( stickerPackDiv ) ;
67
+ if ( stickerPackDiv ) {
68
+ this . stickerContainer . appendChild ( stickerPackDiv ) ;
69
+ }
56
70
}
57
71
58
72
// Scroll sticker pack icons list when scrolling sticker packs
@@ -174,47 +188,54 @@ class StickerRenderer {
174
188
175
189
// Sticker main icon
176
190
if ( ! noIcon ) {
177
- const stickerIconDiv = document . createElement ( 'div' ) ;
178
- stickerIconDiv . classList . add ( 'sticker-pack-icon-wrapper' ) ;
179
- stickerIconDiv . dataset . packID = stickerPackID ;
191
+ // Don't add icon if it already exists
192
+ if ( ! document . getElementById ( `sticker-pack-icon-${ stickerPackID } ` ) ) {
193
+ const stickerIconDiv = document . createElement ( 'div' ) ;
194
+ stickerIconDiv . classList . add ( 'sticker-pack-icon-wrapper' ) ;
195
+ stickerIconDiv . dataset . packID = stickerPackID ;
196
+ stickerIconDiv . id = `sticker-pack-icon-${ stickerPackID } ` ;
180
197
181
- const stickerIconImg = document . createElement ( 'img' ) ;
182
- stickerIconImg . src = mainIcon ;
183
- stickerIconDiv . appendChild ( stickerIconImg ) ;
184
- this . stickerPackListDiv . appendChild ( stickerIconDiv ) ;
198
+ const stickerIconImg = document . createElement ( 'img' ) ;
199
+ stickerIconImg . src = mainIcon ;
200
+ stickerIconDiv . appendChild ( stickerIconImg ) ;
201
+ this . stickerPackListDiv . appendChild ( stickerIconDiv ) ;
185
202
186
- // Scroll to sticker pack on hover
187
- stickerIconDiv . addEventListener ( 'mouseover' , ( e ) => {
188
- stickerPackDiv . scrollIntoView ( { behavior : 'instant' } ) ;
189
- // remove active from all sticker pack icons
190
- document . querySelectorAll ( '.active' ) . forEach ( ( el ) => el . classList . remove ( 'active' ) ) ;
191
- // add active to current sticker pack icon
192
- if ( ! this . sorting ) {
193
- e . currentTarget . classList . add ( 'active' ) ;
194
- }
195
- } ) ;
203
+ // Scroll to sticker pack on hover
204
+ stickerIconDiv . addEventListener ( 'mouseover' , ( e ) => {
205
+ const stickerPackDiv = document . getElementById ( `sticker-pack-container-${ stickerPackID } ` ) ;
206
+ stickerPackDiv . scrollIntoView ( { behavior : 'instant' } ) ;
207
+ // remove active from all sticker pack icons
208
+ document . querySelectorAll ( '.active' ) . forEach ( ( el ) => el . classList . remove ( 'active' ) ) ;
209
+ // add active to current sticker pack icon
210
+ if ( ! this . sorting ) {
211
+ e . currentTarget . classList . add ( 'active' ) ;
212
+ }
213
+ } ) ;
214
+ }
196
215
}
197
216
198
- // Sticker pack
199
- const stickerPackDiv = document . createElement ( 'div' ) ;
200
- stickerPackDiv . classList . add ( 'sticker-pack' ) ;
201
- stickerPackDiv . dataset . packID = stickerPackID ;
202
- stickerPackDiv . id = `sticker-pack-container-${ stickerPackID } ` ;
217
+ // Make sticker pack if it doesn't exist
218
+ if ( ! document . getElementById ( `sticker-pack-container-${ stickerPackID } ` ) ) {
219
+ const stickerPackDiv = document . createElement ( 'div' ) ;
220
+ stickerPackDiv . classList . add ( 'sticker-pack' ) ;
221
+ stickerPackDiv . dataset . packID = stickerPackID ;
222
+ stickerPackDiv . id = `sticker-pack-container-${ stickerPackID } ` ;
203
223
204
- const stickerPackHeader = createElementFromHTML ( /* html */ `
224
+ const stickerPackHeader = createElementFromHTML ( /* html */ `
205
225
<div class="sticker-pack-header">
206
226
<a class="sticker-pack-title" href="${ storeURL } " target="_blank">${ title } </a>
207
227
<a class="sticker-pack-author" href="${ authorURL } " target="_blank">${ author } </a>
208
228
</div>
209
229
` ) ;
210
- stickerPackDiv . appendChild ( stickerPackHeader ) ;
230
+ stickerPackDiv . appendChild ( stickerPackHeader ) ;
211
231
212
- // loop through stickers
213
- for ( const sticker of stickers ) {
214
- stickerPackDiv . appendChild ( this . createSticker ( sticker ) ) ;
215
- }
232
+ // loop through stickers
233
+ for ( const sticker of stickers ) {
234
+ stickerPackDiv . appendChild ( this . createSticker ( sticker ) ) ;
235
+ }
216
236
217
- return stickerPackDiv ;
237
+ return stickerPackDiv ;
238
+ }
218
239
}
219
240
/**
220
241
* Fetches and updates the most used sticker pack section
@@ -231,7 +252,11 @@ class StickerRenderer {
231
252
mostUsedDiv . innerHTML = '' ;
232
253
233
254
api . getMostUsed ( ) . then ( ( mostUsed ) => {
234
- const newDiv = this . makeAndSetUpStickerPack ( 'most-used' , {
255
+ // delete old most used
256
+ this . stickerContainer . removeChild (
257
+ document . getElementById ( 'sticker-pack-container-most-used' )
258
+ ) ;
259
+ const mostUsedDiv = this . makeAndSetUpStickerPack ( 'most-used' , {
235
260
title : '<span class="material-symbols-outlined">history</span> Most Used' ,
236
261
author : '' ,
237
262
stickers : mostUsed . map ( ( { PackID, StickerID } ) => {
@@ -243,10 +268,11 @@ class StickerRenderer {
243
268
storeURL : 'https://store.line.me/stickershop/' ,
244
269
noIcon : true ,
245
270
} ) ;
246
- // reinsert most used at the top
247
- this . stickerContainer . insertBefore ( newDiv , mostUsedDiv ) ;
248
- // delete old most used
249
- this . stickerContainer . removeChild ( mostUsedDiv ) ;
271
+ // reinsert most used before favorites div
272
+ this . stickerContainer . insertBefore (
273
+ mostUsedDiv ,
274
+ document . getElementById ( 'sticker-pack-container-favorites' )
275
+ ) ;
250
276
} ) ;
251
277
}
252
278
/**
@@ -376,7 +402,6 @@ class StickerRenderer {
376
402
* Gets and refreshes all sticker packs
377
403
*/
378
404
refreshStickerPacks ( ) {
379
- this . stickerContainer . innerHTML = '' ;
380
405
this . populateStickerPacks ( ) ;
381
406
}
382
407
}
0 commit comments