Merge pull request #124 from linkwarden/dev

Dev
This commit is contained in:
Daniel
2025-05-03 13:50:55 +03:30
committed by GitHub
5 changed files with 71 additions and 12 deletions
+2 -2
View File
@@ -13,8 +13,8 @@ if [ "$1" = "--firefox" ]; then
cp firefox/manifest.json dist/manifest.json
else
# Copy to dist/manifest.json
echo "Built for Chrome(ium)..."
cp src/manifest.json dist/manifest.json
echo "Built for Chromium..."
cp chromium/manifest.json dist/manifest.json
fi
# Done (for now...)
+9 -9
View File
@@ -3,14 +3,14 @@
"name": "Linkwarden",
"description": "The browser extension for Linkwarden.",
"homepage_url": "https://linkwarden.app/",
"version": "1.3.2",
"version": "1.3.3",
"action": {
"default_popup": "./index.html",
"default_icon": {
"16": "./16.png",
"32": "./32.png",
"48": "./48.png",
"128": "./128.png"
"16": "16.png",
"32": "32.png",
"48": "48.png",
"128": "128.png"
},
"default_title": "Linkwarden"
},
@@ -19,10 +19,10 @@
"browser_style": false
},
"icons": {
"16": "./16.png",
"32": "./32.png",
"48": "./48.png",
"128": "./128.png"
"16": "16.png",
"32": "32.png",
"48": "48.png",
"128": "128.png"
},
"permissions": [
"storage",
+1 -1
View File
@@ -3,7 +3,7 @@
"name": "Linkwarden",
"description": "The browser extension for Linkwarden.",
"homepage_url": "https://linkwarden.app/",
"version": "1.3.2",
"version": "1.3.3",
"browser_action": {
"default_popup": "./index.html",
"default_icon": {
+32
View File
@@ -2,6 +2,7 @@ import captureScreenshot from '../screenshot.ts';
import { bookmarkFormValues } from '../validators/bookmarkForm.ts';
import axios from 'axios';
import { bookmarkMetadata } from '../cache.ts';
import { getCurrentTabInfo } from '../utils.ts';
export async function postLink(
baseUrl: string,
@@ -111,3 +112,34 @@ export async function getLinksFetch(
});
return await response.json();
}
export async function checkLinkExists(
baseUrl: string,
apiKey: string
): Promise<boolean> {
const tabInfo = await getCurrentTabInfo();
if (!tabInfo.url) {
console.error('No URL found for current tab');
return false;
}
const url =
`${baseUrl}/api/v1/links?cursor=0&sort=0&searchQueryString=` +
encodeURIComponent(`${tabInfo.url}`);
console.log('Checking if link exists at:', url);
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
const data = await response.json();
console.log('Link exists response:', data);
const exists = data.response.length > 0;
return exists;
}
+27
View File
@@ -2,6 +2,7 @@ import { getBrowser, getCurrentTabInfo } from '../../@/lib/utils.ts';
// import BookmarkTreeNode = chrome.bookmarks.BookmarkTreeNode;
import { getConfig, isConfigured } from '../../@/lib/config.ts';
import {
checkLinkExists,
// deleteLinkFetch,
// updateLinkFetch,
postLinkFetch,
@@ -297,6 +298,32 @@ browser.runtime.onInstalled.addListener(function () {
});
});
browser.tabs.onActivated.addListener(async ({ tabId }) => {
const cachedConfig = await getConfig();
const linkExists = await checkLinkExists(
cachedConfig.baseUrl,
cachedConfig.apiKey
);
if (linkExists) {
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 {
if (browser.action) {
browser.action.setBadgeText({ tabId, text: '' });
} else {
browser.browserAction.setBadgeText({ tabId, text: '' });
}
}
});
// Omnibox implementation
browser.omnibox.onInputStarted.addListener(async () => {