@@ -5,7 +5,7 @@ async function initPassword() {
55 const { t } = await import ( "../popup/helpers/lang.js" ) ;
66 const { Storage } = await import ( "./helpers/utils.js" ) ;
77
8- let pass = await Storage . get ( passStorageKey ) ;
8+ let pass = await getCurPass ( ) ;
99 if ( pass ) return true ;
1010
1111 const { value : newPass } = await Swal . fire ( {
@@ -29,20 +29,28 @@ async function initPassword() {
2929 return false ;
3030}
3131
32- async function checkPass ( ) {
33- const { t } = await import ( "../popup/helpers/lang.js" ) ;
32+ async function getCurPass ( ) {
3433 const { Storage } = await import ( "./helpers/utils.js" ) ;
34+ let curPass = await Storage . get ( passStorageKey ) ;
35+ return curPass ;
36+ }
3537
36- let passToOpenManager = await Storage . get ( passStorageKey ) ;
37- if ( passToOpenManager == null ) return "not init" ;
38+ export async function checkPass ( reason ) {
39+ const { t } = await import ( "../popup/helpers/lang.js" ) ;
40+
41+ let curPass = await getCurPass ( ) ;
42+ if ( curPass == null ) return "not init" ;
3843
3944 const { value : pass } = await Swal . fire ( {
4045 title : t ( {
46+ vi : "Nhập mật khẩu" + t ( reason ) ,
47+ en : "Enter password" + t ( reason ) ,
48+ } ) ,
49+ input : "password" ,
50+ inputPlaceholder : t ( {
4151 vi : "Nhập mật khẩu" ,
4252 en : "Enter password" ,
4353 } ) ,
44- input : "password" ,
45- inputPlaceholder : t ( { vi : "Nhập mật khẩu" , en : "Enter your password" } ) ,
4654 inputAttributes : {
4755 autocapitalize : "off" ,
4856 autocorrect : "off" ,
@@ -58,7 +66,7 @@ async function checkPass() {
5866 } ,
5967 } ) ;
6068
61- if ( pass === passToOpenManager ) return true ;
69+ if ( pass === curPass ) return true ;
6270 if ( pass != null ) {
6371 await Swal . fire (
6472 t ( { vi : "Sai mật khẩu" , en : "Wrong password!" } ) ,
@@ -93,13 +101,12 @@ export default {
93101 } ,
94102
95103 infoLink : async function openManager ( ) {
96- let res = await checkPass ( ) ;
97- if ( res === "not init" ) {
98- res = await initPassword ( ) ;
104+ let curPass = await getCurPass ( ) ;
105+ if ( curPass == null ) {
106+ curPass = await initPassword ( ) ;
99107 }
100-
101- if ( res ) {
102- window . open ( "/scripts/auto_lockWebsite.html" , "_blank" ) ;
108+ if ( curPass ) {
109+ window . open ( "/scripts/auto_lockWebsite.html" , "_self" ) ;
103110 }
104111 } ,
105112
@@ -110,7 +117,10 @@ export default {
110117 } ,
111118 onDisable : async ( ) => {
112119 const { Storage } = await import ( "./helpers/utils.js" ) ;
113- let res = await checkPass ( ) ;
120+ let res = await checkPass ( {
121+ vi : " để tắt chức năng" ,
122+ en : " to disable feature" ,
123+ } ) ;
114124 if ( res === true ) {
115125 await Storage . remove ( passStorageKey ) ;
116126 await Storage . remove ( lockedWebsiteKey ) ;
0 commit comments