-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
31 lines (25 loc) · 793 Bytes
/
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
function generatedByAstro() {
const generator = document.querySelector('meta[name="generator"][content^="Astro v"]');
return generator !== null;
}
function hasAstroIsland() {
const astroIslandElement = document.querySelector('astro-island');
return astroIslandElement !== null;
}
function hasAstroClass() {
const astroClassRegex = /astro-[A-Z0-9]{8}/;
const allElements = document.querySelectorAll('*');
for (const element of allElements) {
const classes = element.classList;
for (const className of classes) {
if (astroClassRegex.test(className)) {
return true;
}
}
}
return false;
}
function detectAstro() {
return generatedByAstro() || hasAstroClass() || hasAstroIsland();
}
chrome.runtime.sendMessage({ detected: detectAstro() });