initial commit

This commit is contained in:
2026-08-12 09:02:09 +03:00
commit ef70a20093
20 changed files with 495 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
const NATIVE_HOST = "com.kget_capture.host";
const MENU_ID = "kget-capture-download";
function updateBadge(enabled) {
chrome.action.setBadgeText({ text: enabled ? "ON" : "OFF" });
chrome.action.setBadgeBackgroundColor({ color: enabled ? "#2e7d32" : "#9e9e9e" });
}
async function refreshBadge() {
const { autoCaptureEnabled } = await chrome.storage.local.get({ autoCaptureEnabled: true });
updateBadge(autoCaptureEnabled);
}
function sendToKGet(url) {
chrome.runtime.sendNativeMessage(NATIVE_HOST, { action: "addTransfer", url }, (response) => {
if (chrome.runtime.lastError) {
console.error("[kget-capture] native host error:", chrome.runtime.lastError.message);
return;
}
if (!response || !response.ok) {
console.error("[kget-capture] KGet reported failure:", response && response.error);
}
});
}
chrome.runtime.onInstalled.addListener(async (details) => {
chrome.contextMenus.create({
id: MENU_ID,
title: "Download with KGet",
contexts: ["link", "image", "video", "audio"],
});
if (details.reason === "install") {
await chrome.storage.local.set({ autoCaptureEnabled: true });
}
refreshBadge();
});
chrome.contextMenus.onClicked.addListener((info) => {
if (info.menuItemId !== MENU_ID) return;
const url = info.linkUrl || info.srcUrl;
if (!url) return;
sendToKGet(url);
});
chrome.downloads.onCreated.addListener(async (item) => {
const { autoCaptureEnabled } = await chrome.storage.local.get({ autoCaptureEnabled: true });
if (!autoCaptureEnabled) return;
const url = item.finalUrl || item.url;
if (url.startsWith("blob:") || url.startsWith("data:")) {
console.warn("[kget-capture] cannot redirect blob:/data: URL, letting Chrome handle it:", url);
return;
}
try {
await chrome.downloads.cancel(item.id);
// erase() only clears the history entry -- it does NOT delete the
// partial file Chrome already wrote to disk. removeFile() does that.
await chrome.downloads.removeFile(item.id);
} catch (e) {
// Expected if Chrome finished the download before cancel() landed, or
// hadn't written any bytes yet -- not worth surfacing to the user.
}
try {
await chrome.downloads.erase({ id: item.id });
} catch (e) {
console.error("[kget-capture] failed to erase Chrome download entry:", e);
}
sendToKGet(url);
});
chrome.storage.onChanged.addListener((changes, area) => {
if (area === "local" && "autoCaptureEnabled" in changes) {
updateBadge(changes.autoCaptureEnabled.newValue);
}
});
refreshBadge();
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1018 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

+25
View File
@@ -0,0 +1,25 @@
{
"manifest_version": 3,
"name": "KGet Capture",
"version": "1.0.0",
"description": "Send browser downloads to KGet (KDE Download Manager) on Linux.",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtM1nFg5pPd3UBzynUJHj6aUy7bjudZaX9AQTWGMqAX3fXylw1lubSzP1/BaS9ivvgOJg/loyEgzEZlcNPzblFVlg8BqEJ3tntdk2OzYvUs0pUdcPzzyjso9TykCkUUTI7ev8JkreW/FYlinfvNwSYN4/c1s3h8/I6XHtxOdmO1G3bS98+BQaXPldbDmxoKwyWR8u1f8gTO2Mg3GY4BHau3RWf1kgtNzh20p9wE3sEFdWkFu7ArgRCIrWLh6m3O6lolnHQSCWPwtOTx893Qkp9Eu6FwUnoWc8rsYx8sqa0eNCTCS6Kjr1Iu3yEJ5y9390jUiDZTQ/c62ueCTQaYv2bwIDAQAB",
"permissions": ["downloads", "contextMenus", "storage", "nativeMessaging"],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
},
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
}
+29
View File
@@ -0,0 +1,29 @@
body {
width: 240px;
padding: 12px;
font-family: system-ui, sans-serif;
font-size: 13px;
}
h1 {
font-size: 14px;
margin: 0 0 10px;
}
.toggle-row {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.status {
margin: 8px 0 0;
color: #555;
}
.hint {
margin: 10px 0 0;
color: #777;
line-height: 1.4;
}
+18
View File
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="popup.css">
</head>
<body>
<h1>KGet Capture</h1>
<label class="toggle-row">
<input type="checkbox" id="auto-capture-toggle">
<span>Auto-capture all downloads</span>
</label>
<p class="status" id="status-line"></p>
<p class="hint">Right-click any link, image, video, or audio and choose
"Download with KGet" to send it to KGet on demand.</p>
<script src="popup.js"></script>
</body>
</html>
+16
View File
@@ -0,0 +1,16 @@
const checkbox = document.getElementById("auto-capture-toggle");
const statusLine = document.getElementById("status-line");
function renderStatus(enabled) {
statusLine.textContent = `Auto-capture: ${enabled ? "ON" : "OFF"}`;
}
chrome.storage.local.get({ autoCaptureEnabled: true }).then(({ autoCaptureEnabled }) => {
checkbox.checked = autoCaptureEnabled;
renderStatus(autoCaptureEnabled);
});
checkbox.addEventListener("change", () => {
chrome.storage.local.set({ autoCaptureEnabled: checkbox.checked });
renderStatus(checkbox.checked);
});