-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathhide-all
More file actions
98 lines (77 loc) · 2.73 KB
/
Copy pathhide-all
File metadata and controls
98 lines (77 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<script>
(function () {
const MODULE_KEY = "StackLab_OcultarAbaTodos_permissions_v1";
if (window[MODULE_KEY]) return;
window[MODULE_KEY] = true;
console.log("[StackLab:OcultarAba] iniciado...");
async function fetchUserProfile() {
try {
const resp = await axios.get("/api/v1/profile");
console.log("[StackLab:OcultarAba] RAW PROFILE:", resp);
return resp?.data || null;
} catch (e) {
console.error("[StackLab:OcultarAba] erro ao buscar /profile", e);
return null;
}
}
function isAdminByPermissions(profile) {
if (!profile) {
console.log("[StackLab:OcultarAba] profile NULL → ocultar");
return false;
}
const currentAccountId = profile.account_id;
console.log("[StackLab:OcultarAba] Conta ativa:", currentAccountId);
const accounts = profile.accounts || [];
console.log("[StackLab:OcultarAba] Accounts:", accounts);
const currentAcc = accounts.find(acc => acc.id === currentAccountId);
if (!currentAcc) {
console.warn("[StackLab:OcultarAba] Conta ativa não encontrada no array accounts → fallback ocultar");
return false;
}
console.log("[StackLab:OcultarAba] Conta atual encontrada:", currentAcc);
const perms = currentAcc.permissions || [];
console.log("[StackLab:OcultarAba] Permissions da conta atual:", perms);
const isAdmin = perms.includes("administrator");
console.log("[StackLab:OcultarAba] isAdmin =", isAdmin);
return isAdmin;
}
function ocultarAbaTodos() {
const labels = ["Todos", "Todos os Contatos", "All Contacts"];
const uls = document.querySelectorAll("ul");
uls.forEach(ul => {
ul.querySelectorAll("a").forEach(a => {
const t = (a.innerText || "").trim();
labels.forEach(lbl => {
if (t.startsWith(lbl)) {
const li = a.closest("li");
if (li) {
li.style.display = "none";
console.log("[StackLab:OcultarAba] ocultado:", t);
}
}
});
});
});
}
function startObserver(shouldHide) {
const root = document.body;
const obs = new MutationObserver(() => {
if (shouldHide) ocultarAbaTodos();
});
obs.observe(root, { childList: true, subtree: true });
}
document.addEventListener("DOMContentLoaded", async () => {
console.log("[StackLab:OcultarAba] DOM Loaded");
const profile = await fetchUserProfile();
const isAdmin = isAdminByPermissions(profile);
if (!isAdmin) {
console.log("[StackLab:OcultarAba] Não é admin → ocultando aba");
ocultarAbaTodos();
startObserver(true);
} else {
console.log("[StackLab:OcultarAba] É admin → NÃO ocultar aba");
startObserver(false);
}
});
})();
</script>