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

Function renderSites

scripts/auto_lockWebsite_main.js:4–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { checkPass, initPassword, locker } from "./auto_lockWebsite.js";
3
4async function renderSites() {
5 let sites = await locker.sites.get();
6
7 const containerClass = "sites-container";
8 const exist = document.querySelector("." + containerClass);
9 if (exist) exist.remove();
10
11 let container = document.createElement("div");
12 container.classList.add(containerClass);
13
14 if (!sites.length) {
15 container.innerHTML = t({
16 vi: "Không có trang web nào bị khoá",
17 en: "No website is locked",
18 });
19 }
20
21 sites.forEach((site) => {
22 let div = document.createElement("div");
23 div.classList.add("site");
24 div.innerHTML += `
25 <p>${site}</p>
26 <button class="button">${t({
27 vi: "Mở khoá",
28 en: "Unlock",
29 })}</button>
30 `;
31 let removeBtn = div.querySelector(".button");
32 removeBtn.addEventListener("click", () => {
33 Swal.fire({
34 title: t({
35 vi: "Mở khoá trang web " + site + "?",
36 en: "Unlock " + site + "?",
37 }),
38 showCancelButton: true,
39 confirmButtonText: t({ vi: "Mở khoá", en: "Unlock" }),
40 cancelButtonText: t({ vi: "Huỷ", en: "Cancel" }),
41 }).then(({ isConfirmed }) => {
42 if (isConfirmed) {
43 locker.sites.remove(site);
44
45 // listener will trigger and re-draw all
46 // div.remove();
47 }
48 });
49 });
50 container.appendChild(div);
51 });
52
53 document.body.appendChild(container);
54}
55
56function initAddSite() {
57 let addSiteBtn = document.querySelector("#add-site");

Callers 1

Calls 4

tFunction · 0.90
getMethod · 0.80
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected