Skip to content

Commit e97d58c

Browse files
committed
.
1 parent 7f11e10 commit e97d58c

File tree

3 files changed

+104
-15
lines changed

3 files changed

+104
-15
lines changed

scripts/auto_lockWebsite.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,39 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Useful Scripts - Auto lock websites</title>
88

9+
10+
<link rel="stylesheet" href="../popup/libs/swal2.dark.css">
11+
<script src="../popup/libs/swal2.min.js"></script>
12+
913
<style>
14+
html {
15+
display: flex;
16+
justify-content: center;
17+
width: 400px;
18+
height: 500px;
19+
}
20+
1021
body {
1122
width: 400px;
1223
height: 500px;
1324
background-color: #333;
1425
color: #eee;
26+
display: flex;
27+
justify-content: center;
28+
align-items: center;
29+
flex-direction: column;
30+
}
31+
32+
.sites-container {
33+
width: 100%;
34+
}
35+
36+
.site {
37+
display: flex;
38+
flex-direction: row;
39+
justify-content: space-between;
40+
align-items: center;
41+
width: 100%;
1542
}
1643
</style>
1744
</head>

scripts/auto_lockWebsite.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

scripts/auto_lockWebsite_main.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { t } from "../popup/helpers/lang.js";
2+
import { Storage } from "./helpers/utils.js";
3+
import { checkPass } from "./auto_lockWebsite.js";
4+
5+
const passStorageKey = "auto_lock_website_manager_password";
6+
const lockedWebsiteKey = "auto_lock_website_lockedWebsites";
7+
8+
async function renderSites() {
9+
let sites = await Storage.get(lockedWebsiteKey, []);
10+
11+
sites.forEach((site) => {
12+
let div = document.createElement("div");
13+
div.classList.add("sites-container");
14+
div.innerHTML = `
15+
<div class="site">
16+
<p>${site}</p>
17+
<button class="removeBtn">Remove</button>
18+
</div>
19+
`;
20+
let removeBtn = div.querySelector(".removeBtn");
21+
removeBtn.addEventListener("click", async () => {
22+
let { isConfirmed } = await Swal.fire({
23+
title: t({
24+
vi: "Mở khoá trang web " + site + "?",
25+
en: "Unlock " + site + "?",
26+
}),
27+
showCancelButton: true,
28+
confirmButtonText: t({ vi: "Mở khoá", en: "Unlock" }),
29+
cancelButtonText: t({ vi: "Huỷ", en: "Cancel" }),
30+
});
31+
if (isConfirmed) {
32+
let index = sites.indexOf(site);
33+
sites.splice(index, 1);
34+
await Storage.set(lockedWebsiteKey, sites);
35+
div.remove();
36+
}
37+
});
38+
document.body.appendChild(div);
39+
});
40+
}
41+
42+
checkPass().then((res) => {
43+
if (res === true) {
44+
renderSites();
45+
} else {
46+
if (window.history.length) {
47+
window.history.back();
48+
} else {
49+
window.close();
50+
}
51+
}
52+
});

0 commit comments

Comments
 (0)