fix: resolve account country from rendered about page

This commit is contained in:
Darío Sevilla committed 2026-10-15 07:42:06 +00:00
1 parent 3811ae9cfc
commit d6c31bdf95
5 files changed
+102 -17

No files matched your search

+23
View File
@@ -9,6 +9,11 @@ let scanQueued = false;
initialize();
async function initialize() {
const aboutMatch = location.pathname.match(/^\/([A-Za-z0-9_]{1,15})\/about\/?$/);
if (aboutMatch) {
reportRenderedAboutPage(aboutMatch[1]);
return;
}
settings = await extensionApi.storage.sync.get({ enabled: true, showPlaceholder: false });
scan(document);
new MutationObserver((mutations) => {
@@ -16,6 +21,24 @@ async function initialize() {
}).observe(document.documentElement, { childList: true, subtree: true });
}
function reportRenderedAboutPage(username) {
const startedAt = Date.now();
const inspect = () => {
const result = XGeoParser.parseAboutDocument(document, username);
if (result.country) {
extensionApi.runtime.sendMessage({ type: "about-page-result", username, ...result }).catch(() => {});
return true;
}
return Date.now() - startedAt >= 24000;
};
if (inspect()) return;
const observer = new MutationObserver(() => {
if (inspect()) observer.disconnect();
});
observer.observe(document.documentElement, { childList: true, subtree: true, characterData: true });
setTimeout(() => observer.disconnect(), 24500);
}
extensionApi.storage.onChanged.addListener((changes, area) => {
if (area !== "sync") return;
if (changes.enabled) settings.enabled = changes.enabled.newValue;