mirror of
https://github.com/linkwarden/browser-extension.git
synced 2026-06-23 04:10:26 +00:00
big fix
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: '' });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user