11import { BADGES } from "./helpers/badge.js" ;
22import { md5 } from "./libs/crypto/md5.js" ;
3+ import { Storage } from "./helpers/utils.js" ;
34
45const managerBtn = '<i class="fa-solid fa-unlock-keyhole"></i>' ;
56
@@ -82,7 +83,7 @@ export default {
8283 contentScript : {
8384 onDocumentStart : async ( ) => {
8485 const pass = await locker . password . get ( ) ;
85- if ( pass != null ) {
86+ if ( pass ) {
8687 const sites = await locker . sites . get ( ) ;
8788 if ( sites . length > 0 ) {
8889 let hostname = location . hostname ;
@@ -94,7 +95,7 @@ export default {
9495 onClick : async ( ) => {
9596 try {
9697 const pass = await locker . password . get ( ) ;
97- if ( pass == null ) return ;
98+ if ( ! pass ) return ;
9899
99100 lockCurrentWebsite ( pass ) ;
100101 locker . sites . add ( location . hostname ) ;
@@ -105,63 +106,47 @@ export default {
105106 } ,
106107} ;
107108
108- export const _storage = {
109- async get ( key , defaultValue ) {
110- let data = await chrome . storage . local . get ( [ key ] ) ;
111- let pass = data ?. [ key ] ;
112- return pass ?? defaultValue ;
113- } ,
114- async set ( key , value ) {
115- await chrome . storage . local . set ( { [ key ] : value } ) ;
116- return true ;
117- } ,
118- async remove ( key ) {
119- await chrome . storage . local . remove ( key ) ;
120- return true ;
121- } ,
122- } ;
123-
124109export const locker = {
125110 password : {
126111 storageKey : "auto_lock_website_manager_password" ,
127112 async compare ( pass ) {
128- return md5 ( pass ) === ( await _storage . get ( this . storageKey ) ) ;
113+ return pass && md5 ( pass ) === ( await Storage . get ( this . storageKey ) ) ;
129114 } ,
130115 async has ( ) {
131- return ( await _storage . get ( this . storageKey ) ) != null ;
116+ return ( await Storage . get ( this . storageKey ) ) != null ;
132117 } ,
133118 get ( ) {
134- return _storage . get ( this . storageKey ) ;
119+ return Storage . get ( this . storageKey ) ;
135120 } ,
136121 set ( pass ) {
137- return _storage . set ( this . storageKey , md5 ( pass ) ) ;
122+ return Storage . set ( this . storageKey , md5 ( pass ) ) ;
138123 } ,
139124 remove ( ) {
140- return _storage . remove ( this . storageKey ) ;
125+ return Storage . remove ( this . storageKey ) ;
141126 } ,
142127 } ,
143128 sites : {
144129 storageKey : "auto_lock_website_lockedWebsites" ,
145130 get ( ) {
146- return _storage . get ( this . storageKey , [ ] ) ;
131+ return Storage . get ( this . storageKey , [ ] ) ;
147132 } ,
148133 async add ( site ) {
149134 let currentSites = await this . get ( ) ;
150135 if ( currentSites . includes ( site ) ) return false ;
151136 currentSites . unshift ( site ) ;
152- await _storage . set ( this . storageKey , currentSites ) ;
137+ await Storage . set ( this . storageKey , currentSites ) ;
153138 return true ;
154139 } ,
155140 async remove ( site ) {
156141 let key = this . storageKey ;
157142 let currentSites = await this . get ( ) ;
158143 if ( ! currentSites . includes ( site ) ) return false ;
159144 currentSites = currentSites . filter ( ( s ) => s !== site ) ;
160- await _storage . set ( key , currentSites ) ;
145+ await Storage . set ( key , currentSites ) ;
161146 return true ;
162147 } ,
163148 async clear ( ) {
164- await _storage . remove ( this . storageKey ) ;
149+ await Storage . remove ( this . storageKey ) ;
165150 } ,
166151 } ,
167152} ;
0 commit comments