File tree 1 file changed +0
-25
lines changed
1 file changed +0
-25
lines changed Original file line number Diff line number Diff line change 3
3
// Define browser for cross-browser compatibility
4
4
var browser = ( typeof browser !== 'undefined' ) ? browser : chrome ;
5
5
6
- function migrateLocalStorageToBrowserStorage ( ) {
7
- // Check if localStorage is not null and contains any keys
8
- if ( ! localStorage || Object . keys ( localStorage ) . length === 0 ) {
9
- console . log ( 'No localStorage data to migrate.' ) ;
10
- return ;
11
- }
12
-
13
- // Get all localStorage keys
14
- const localStorageKeys = Object . keys ( localStorage ) ;
15
- const dataToMigrate = { } ;
16
-
17
- localStorageKeys . forEach ( ( key ) => {
18
- dataToMigrate [ key ] = localStorage . getItem ( key ) ;
19
- } ) ;
20
-
21
- // Store data in broswer.storage
22
- browser . storage . local . set ( dataToMigrate , ( ) => {
23
- console . log ( 'Data migrated to browser.storage' , dataToMigrate ) ;
24
-
25
- // Clear localStorage after migration
26
- localStorage . clear ( ) ;
27
- } ) ;
28
- }
29
-
30
6
browser . runtime . onInstalled . addListener ( function ( details ) {
31
7
if ( details . reason === 'install' ) {
32
8
// Handle installation logic
33
9
console . log ( 'Extension installed' ) ;
34
10
} else if ( details . reason === 'update' ) {
35
11
console . log ( 'previousVersion' , details . previousVersion ) ;
36
12
// Handle update logic
37
- migrateLocalStorageToBrowserStorage ( ) ;
38
13
}
39
14
} ) ;
40
15
You can’t perform that action at this time.
0 commit comments