mirror of
https://github.com/Dasemu/X-GeoBlock.git
synced 2026-11-26 15:26:09 +00:00
fix: resolve account country from rendered about page
This commit is contained in:
1 parent
3811ae9cfc
commit
d6c31bdf95
5 files changed
+102
-17
No files matched your search
+23
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user