-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
90 lines (79 loc) · 3.19 KB
/
content.js
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
function getDecoSegmentCookie(callback) {
chrome.tabs?.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0) {
const tab = tabs[0];
const url = tab.url;
if (url) {
chrome.cookies.get({ url, name: 'deco_segment' }, (cookie) => {
if (cookie) {
const decodedData = JSON.parse(decodeURIComponent(atob(cookie.value)));
callback(decodedData);
} else {
console.warn("Cookie 'deco_segment' não encontrado.");
callback(null);
}
});
}
}
});
}
getDecoSegmentCookie((data) => {
if (data) {
const segmentsContainer = document.querySelector('.space-y-4');
data.active.forEach(segment => {
const segmentDiv = document.createElement('div');
segmentDiv.className = 'segment';
segmentDiv.innerHTML = `
<span class="segment-text">${segment}</span>
<span class="status-true">True</span>
`;
segmentsContainer.appendChild(segmentDiv);
});
data.inactiveDrawn.forEach(segment => {
const segmentDiv = document.createElement('div');
segmentDiv.className = 'segment';
segmentDiv.innerHTML = `
<span class="segment-text">${segment}</span>
<span class="status-false">False</span>
`;
segmentsContainer.appendChild(segmentDiv);
});
}
});
async function fillSiteInfo(){
chrome.tabs?.query({ active: true, currentWindow: true }, async (tabs) => {
if (tabs.length > 0) {
const tab = tabs[0];
const url = tab.url;
const newUrl = new URL(url)
if (url) {
const siteInfo = await fetch(newUrl.origin + "/live/_meta");
const siteData = await siteInfo.json();
document.querySelector("#infra").innerHTML = siteData.platform;
document.querySelector("#sitename").innerHTML = siteData.site;
document.querySelector("#sitename").href = `https://github.com/deco-sites/${siteData.site}`;
document.querySelector("#deco").innerHTML = siteData.version;
document.querySelector("#apps").innerHTML = "";
Object.entries(siteData.manifest.blocks.apps).forEach(([key, value]) => {
document.querySelector("#apps").innerHTML += `<li>${sanitizeAppName(key)}</li>`;
})
}
}
});
}
sanitizeAppName = (appName) => {
return appName.replace(".ts", "").replace("site/apps/deco/", "").replace("site/apps/", "")
}
fillSiteInfo()
document.getElementById('general')?.addEventListener('click', function(){
document.getElementById('general-content').classList.remove('hide');
document.getElementById('more-info-content').classList.add('hide');
document.getElementById('general').classList.add('selected');
document.getElementById('more-info').classList.remove('selected');
});
document.getElementById('more-info')?.addEventListener('click', function(){
document.getElementById('general-content').classList.add('hide');
document.getElementById('more-info-content').classList.remove('hide');
document.getElementById('general').classList.remove('selected');
document.getElementById('more-info').classList.add('selected');
});