mirror of
https://github.com/andwati/kget-capture.git
synced 2026-12-06 10:58:47 +00:00
Add a curl/wget one-line installer and popup setup detection
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.
This commit is contained in:
+36
-1
@@ -1,5 +1,5 @@
|
||||
body {
|
||||
width: 240px;
|
||||
width: 320px;
|
||||
padding: 12px;
|
||||
font-family: system-ui, sans-serif;
|
||||
font-size: 13px;
|
||||
@@ -36,3 +36,38 @@ h1 {
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cmd-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.cmd-row code {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
white-space: nowrap;
|
||||
background: #f0f0f0;
|
||||
padding: 4px 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.cmd-row button {
|
||||
flex: none;
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#recheck-setup {
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
+26
-11
@@ -6,17 +6,32 @@
|
||||
</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>
|
||||
<p class="hint">Downloads still prompting for a location? Chrome shows that
|
||||
dialog itself, before this extension can intercept anything.
|
||||
<button id="open-download-settings" type="button">Turn off Chrome's download prompt</button>
|
||||
</p>
|
||||
|
||||
<div id="setup-needed" hidden>
|
||||
<p class="hint">One-time setup needed: KGet Capture needs a small local
|
||||
helper installed before it can talk to KGet. Run this in a terminal:</p>
|
||||
<div class="cmd-row">
|
||||
<code id="setup-command"></code>
|
||||
<button id="copy-command" type="button">Copy</button>
|
||||
</div>
|
||||
<p class="status" id="copy-feedback"></p>
|
||||
<button id="recheck-setup" type="button">I ran it, check again</button>
|
||||
</div>
|
||||
|
||||
<div id="ready" hidden>
|
||||
<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>
|
||||
<p class="hint">Downloads still prompting for a location? Chrome shows that
|
||||
dialog itself, before this extension can intercept anything.
|
||||
<button id="open-download-settings" type="button">Turn off Chrome's download prompt</button>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+50
-3
@@ -1,13 +1,60 @@
|
||||
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"}`;
|
||||
}
|
||||
|
||||
chrome.storage.local.get({ autoCaptureEnabled: true }).then(({ autoCaptureEnabled }) => {
|
||||
checkbox.checked = autoCaptureEnabled;
|
||||
renderStatus(autoCaptureEnabled);
|
||||
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", () => {
|
||||
|
||||
Reference in New Issue
Block a user