mirror of
https://github.com/andwati/kget-capture.git
synced 2026-10-18 03:02:56 +00:00
Add install-remote.sh, which fetches the latest release and runs its install.sh so setup no longer needs a git clone. The popup now probes the native host with a "ping" action on open and, if it's not registered yet, shows the one-liner (with copy-to-clipboard) instead of the auto-capture toggle -- so a Web Store install can be completed end-to-end by clicking the extension icon and pasting one command.
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
const NATIVE_HOST = "com.kget_capture.host";
|
|
const INSTALL_COMMAND =
|
|
"curl -fsSL https://raw.githubusercontent.com/andwati/kget-capture/main/install-remote.sh | bash";
|
|
|
|
const setupPanel = document.getElementById("setup-needed");
|
|
const readyPanel = document.getElementById("ready");
|
|
const checkbox = document.getElementById("auto-capture-toggle");
|
|
const statusLine = document.getElementById("status-line");
|
|
const copyFeedback = document.getElementById("copy-feedback");
|
|
|
|
function renderStatus(enabled) {
|
|
statusLine.textContent = `Auto-capture: ${enabled ? "ON" : "OFF"}`;
|
|
}
|
|
|
|
function showReady() {
|
|
setupPanel.hidden = true;
|
|
readyPanel.hidden = false;
|
|
chrome.storage.local.get({ autoCaptureEnabled: true }).then(({ autoCaptureEnabled }) => {
|
|
checkbox.checked = autoCaptureEnabled;
|
|
renderStatus(autoCaptureEnabled);
|
|
});
|
|
}
|
|
|
|
function showSetupNeeded() {
|
|
document.getElementById("setup-command").textContent = INSTALL_COMMAND;
|
|
readyPanel.hidden = true;
|
|
setupPanel.hidden = false;
|
|
}
|
|
|
|
// The native host is only reachable once install.sh (or install-remote.sh)
|
|
// has registered it -- sendNativeMessage fails with a lastError like
|
|
// "Specified native messaging host not found" until then, which is exactly
|
|
// the signal we want to gate the rest of the popup on.
|
|
function checkNativeHost() {
|
|
chrome.runtime.sendNativeMessage(NATIVE_HOST, { action: "ping" }, () => {
|
|
if (chrome.runtime.lastError) {
|
|
showSetupNeeded();
|
|
} else {
|
|
showReady();
|
|
}
|
|
});
|
|
}
|
|
|
|
checkNativeHost();
|
|
|
|
document.getElementById("recheck-setup").addEventListener("click", checkNativeHost);
|
|
|
|
document.getElementById("copy-command").addEventListener("click", async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(INSTALL_COMMAND);
|
|
copyFeedback.textContent = "Copied to clipboard.";
|
|
} catch (e) {
|
|
copyFeedback.textContent = "Couldn't copy -- select and copy the command manually.";
|
|
}
|
|
setTimeout(() => {
|
|
copyFeedback.textContent = "";
|
|
}, 2000);
|
|
});
|
|
|
|
checkbox.addEventListener("change", () => {
|
|
chrome.storage.local.set({ autoCaptureEnabled: checkbox.checked });
|
|
renderStatus(checkbox.checked);
|
|
});
|
|
|
|
document.getElementById("open-download-settings").addEventListener("click", () => {
|
|
chrome.tabs.create({ url: "chrome://settings/downloads" });
|
|
});
|