This commit is contained in:
daniel31x13
2025-05-03 05:57:48 -04:00
parent 9d6f85d0e5
commit 8b5aeb895a
2 changed files with 26 additions and 8 deletions
+10 -4
View File
@@ -122,14 +122,20 @@ export async function checkLinkExists(
console.error('No URL found for current tab');
return false;
}
const safeUrl = encodeURIComponent(tabInfo.url);
const url = `${baseUrl}/api/v1/links?searchQueryString=${safeUrl}&searchByUrl=true`;
const url =
`${baseUrl}/api/v1/search?cursor=0&sort=0&searchQueryString=` +
encodeURIComponent(`url:${tabInfo.url}`);
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
const data = await response.json();
const exists = data.response.length > 0;
const exists = data.data.links.length > 0;
return exists;
}
}
+16 -4
View File
@@ -298,17 +298,29 @@ browser.runtime.onInstalled.addListener(function () {
});
});
browser.tabs.onActivated.addListener(async (_tabInfo) => {
browser.tabs.onActivated.addListener(async ({ tabId }) => {
const cachedConfig = await getConfig();
const linkExists = await checkLinkExists(
cachedConfig.baseUrl,
cachedConfig.apiKey
);
if (linkExists) {
browser.browserAction.setBadgeText({ text: '✓' });
browser.browserAction.setBadgeBackgroundColor({ color: '#4688F1' });
if (browser.action) {
browser.action.setBadgeText({ tabId, text: '✓' });
browser.action.setBadgeBackgroundColor({ tabId, color: '#4688F1' });
} else {
browser.browserAction.setBadgeText({ tabId, text: '✓' });
browser.browserAction.setBadgeBackgroundColor({
tabId,
color: '#4688F1',
});
}
} else {
browser.browserAction.setBadgeText({ text: '' });
if (browser.action) {
browser.action.setBadgeText({ tabId, text: '' });
} else {
browser.browserAction.setBadgeText({ tabId, text: '' });
}
}
});