Skip to content

Commit 4198626

Browse files
committed
fix
1 parent f5826dc commit 4198626

File tree

6 files changed

+50
-46
lines changed

6 files changed

+50
-46
lines changed

popup/index.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
isTitle,
3737
viewScriptSource,
3838
} from "./helpers/utils.js";
39+
import { checkPass } from "../scripts/auto_lockWebsite.js";
3940
// import _ from "../md/exportScriptsToMd.js";
4041

4142
const settingsBtn = document.querySelector(".settings");
@@ -609,16 +610,14 @@ function initSettings() {
609610
// smooth scroll row
610611
const smoothScrollRow = document.createElement("div");
611612
smoothScrollRow.classList.add("row");
612-
smoothScrollRow.setAttribute(
613-
"data-tooltip",
614-
t({
615-
vi: "Tắt nếu bạn đã cài app SmoothScroll",
616-
en: "Turn off if installed SmoothScroll app",
617-
})
618-
);
619-
smoothScrollRow.setAttribute("data-flow", "bottom");
620613
smoothScrollRow.innerHTML = `
621-
<div class="label">${t({
614+
<div class="label"
615+
data-tooltip="${t({
616+
vi: "Tắt nếu bạn đã cài app SmoothScroll",
617+
en: "Turn off if installed SmoothScroll app",
618+
})}"
619+
data-flow="bottom"
620+
>${t({
622621
vi: "Cuôn chuột siêu mượt",
623622
en: "Super smooth scroll",
624623
})}</div>
@@ -715,10 +714,19 @@ async function backup() {
715714
UfsGlobal.Utils.downloadData(JSON.stringify(data), name);
716715
}
717716

718-
function restore() {
717+
async function restore() {
718+
if (
719+
!(await checkPass(
720+
t({
721+
vi: " chức năng Tự động khoá trang web",
722+
en: " feature Auto lock websites",
723+
})
724+
))
725+
)
726+
return;
719727
Swal.fire({
720728
title: t({ en: "Restore data", vi: "Khôi phục dữ liệu" }),
721-
text: t({ en: "Select backup file", vi: "Chọn file đã sao lưu" }),
729+
text: t({ en: "Select file to restore", vi: "Chọn file để khôi phục" }),
722730
input: "file",
723731
inputAttributes: {
724732
accept: ".json",
@@ -747,12 +755,14 @@ function restore() {
747755
const { localStorage: l, chromeStorage } = json;
748756

749757
if (l) {
758+
localStorage.clear();
750759
Object.keys(l).forEach((key) => {
751760
localStorage[key] = l[key];
752761
});
753762
}
754763

755764
if (chromeStorage) {
765+
await chrome.storage.local.clear();
756766
for (let key in chromeStorage) {
757767
await chrome.storage.local.set({ [key]: chromeStorage[key] });
758768
}
@@ -777,7 +787,16 @@ function restore() {
777787
});
778788
}
779789

780-
function reset() {
790+
async function reset() {
791+
if (
792+
!(await checkPass(
793+
t({
794+
vi: " chức năng Tự động khoá trang web",
795+
en: " feature Auto lock websites",
796+
})
797+
))
798+
)
799+
return;
781800
Swal.fire({
782801
icon: "warning",
783802
title: t({ en: "Reset", vi: "Đặt lại" }),

popup/themes/default.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ option {
360360
display: flex;
361361
justify-content: center;
362362
align-items: center;
363-
margin-bottom: 5px;
363+
min-height: 50px;
364364

365365
.label {
366366
flex-grow: 1;

scripts/auto_lockWebsite.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BADGES } from "./helpers/badge.js";
22
import { md5 } from "./libs/crypto/md5.js";
3+
import { Storage } from "./helpers/utils.js";
34

45
const 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-
124109
export 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
};

scripts/content-scripts/ufs_global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function enableDragAndZoom(element, container, onUpdateCallback) {
326326
const targetValue = animTarget[prop];
327327
let del = Math.abs(targetValue - currentValue);
328328

329-
if (del > 0) {
329+
if (del > 0.1) {
330330
const newValue =
331331
del < 1 ? targetValue : lerp(currentValue, targetValue, lerpSpeed);
332332
element.style[prop] = newValue + "px";

scripts/helpers/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const Storage = {
173173
await chrome.storage.local.set({ [key]: value });
174174
return value;
175175
},
176-
get: async (key, defaultValue = "") => {
176+
get: async (key, defaultValue) => {
177177
let result = await chrome.storage.local.get([key]);
178178
return result[key] || defaultValue;
179179
},

scripts/magnify_image.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ function createPreview(
797797
case BgState.none:
798798
break;
799799
case BgState.transparent:
800-
var gradientValue =
800+
const gradientValue =
801801
"linear-gradient(45deg, rgba(255, 255, 255, 0.4) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.4) 75%, rgba(255, 255, 255, 0.4) 100%) 0 0 / 20px 20px, linear-gradient(45deg, rgba(255, 255, 255, 0.4) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.4) 75%, rgba(255, 255, 255, 0.4) 100%) 10px 10px / 20px 20px";
802802
img.style.cssText += "background: " + gradientValue + " !important;";
803803
break;
@@ -867,10 +867,10 @@ function createPreview(
867867
toolbar.onmousemove = (e) => {
868868
if (
869869
e.target != toolbar &&
870-
e.target?.ufs_title &&
871-
e.target?.ufs_title != desc.textContent
870+
e.target.attributes.ufs_title &&
871+
e.target.attributes.ufs_title.textContent != desc.textContent
872872
) {
873-
desc.textContent = e.target.ufs_title;
873+
desc.textContent = e.target.attributes.ufs_title.textContent;
874874
let x =
875875
e.target.offsetLeft + e.target.offsetWidth / 2 - desc.offsetWidth / 2;
876876
desc.style.cssText = `left: ${x}px`;

0 commit comments

Comments
 (0)