MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / restore

Function restore

popup/index.js:954–1047  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

952}
953
954async function restore() {
955 const { checkPass } = await import("../scripts/auto_lockWebsite.js");
956
957 if (
958 !(await checkPass(
959 t({
960 vi: " chức năng Tự động khoá trang web",
961 en: " feature Auto lock websites",
962 })
963 ))
964 )
965 return;
966 const result = await Swal.fire({
967 title: t({ en: "Restore data", vi: "Khôi phục dữ liệu" }),
968 text: t({ en: "Select file to restore", vi: "Chọn file để khôi phục" }),
969 input: "file",
970 inputAttributes: {
971 accept: ".json",
972 },
973 showCancelButton: true,
974 confirmButtonText: t({ en: "Restore", vi: "Khôi phục" }),
975 showLoaderOnConfirm: true,
976 inputValidator: (value) => {
977 if (!value)
978 return t({ en: "Please select a file", vi: "Vui lòng chọn file" });
979 },
980 preConfirm: (file) => {
981 return new Promise((resolve) => {
982 const reader = new FileReader();
983 reader.onload = () => {
984 resolve(reader.result);
985 };
986 reader.readAsText(file);
987 });
988 },
989 allowOutsideClick: () => !Swal.isLoading(),
990 });
991
992 if (!result.isConfirmed) return;
993 try {
994 trackEvent("RESTORE");
995 const json = JSON.parse(result.value);
996 const { localStorage: l, chromeStorage } = json;
997
998 // override localStorage
999 if (l) {
1000 localStorage.clear();
1001 Object.keys(l).forEach((key) => {
1002 localStorage[key] = l[key];
1003 });
1004 }
1005
1006 if (chromeStorage) {
1007 // trigger onDisable current active scripts
1008 const oldActiveScriptIds = await getAllActiveScriptIds();
1009 for (let id of oldActiveScriptIds) {
1010 // ⚡ LAZY LOAD: Load full script for onDisable
1011 const s = await loadFullScript(id);

Callers

nothing calls this directly

Calls 6

tFunction · 0.90
trackEventFunction · 0.90
getAllActiveScriptIdsFunction · 0.90
checkPassFunction · 0.85
loadFullScriptFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected