All checks were successful
Deploy / deploy (push) Successful in 25s
Live testing showed the CDP approach still fails hCaptcha even with a real human clicking through chrome://inspect: the headless Chromium's own fingerprint (HeadlessChrome user-agent, navigator.webdriver=true) is what gets flagged, independent of who's driving it. Trying to disguise that browser to get past bot detection would be captcha evasion, not a session-handling technique, so that path is dropped entirely rather than patched further. New flow: log into MassPrice with an ordinary, non-automated browser (hCaptcha passes normally), export the session's cookies with a extension, and paste them into the Session page. import_cookies() converts the export into Playwright's storage_state shape and verifies it actually authenticates against the live site before saving it, so a bad paste never clobbers a working session. This also removes the now-unnecessary socat proxy / debug port exposure — Chromium's own CDP port was only ever needed for the dropped approach. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H6TgffxTvYhqxykAbVQg2v
136 lines
4.4 KiB
JavaScript
136 lines
4.4 KiB
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
const refreshBtn = document.getElementById("refresh-rules");
|
|
if (refreshBtn) {
|
|
refreshBtn.addEventListener("click", async () => {
|
|
refreshBtn.disabled = true;
|
|
const original = refreshBtn.textContent;
|
|
refreshBtn.textContent = "Refreshing…";
|
|
try {
|
|
const res = await fetch("/api/rules/refresh", { method: "POST" });
|
|
if (!res.ok) {
|
|
const data = await res.json().catch(() => ({}));
|
|
alert("Refresh failed: " + (data.error || res.status));
|
|
return;
|
|
}
|
|
window.location.reload();
|
|
} finally {
|
|
refreshBtn.disabled = false;
|
|
refreshBtn.textContent = original;
|
|
}
|
|
});
|
|
}
|
|
|
|
document.querySelectorAll(".rule-card").forEach(initRuleCard);
|
|
initSessionControls();
|
|
});
|
|
|
|
function initSessionControls() {
|
|
const importBtn = document.getElementById("session-import");
|
|
const textarea = document.getElementById("cookie-paste");
|
|
if (!importBtn) return; // not on the Session page
|
|
|
|
importBtn.addEventListener("click", async () => {
|
|
const original = importBtn.textContent;
|
|
importBtn.disabled = true;
|
|
importBtn.textContent = "Verifying…";
|
|
try {
|
|
const res = await fetch("/api/session/import", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ cookies: textarea.value }),
|
|
});
|
|
const data = await res.json().catch(() => ({}));
|
|
if (!res.ok) {
|
|
alert(data.error || "Import failed");
|
|
return;
|
|
}
|
|
window.location.reload();
|
|
} finally {
|
|
importBtn.disabled = false;
|
|
importBtn.textContent = original;
|
|
}
|
|
});
|
|
}
|
|
|
|
function initRuleCard(card) {
|
|
const ruleId = card.dataset.ruleId;
|
|
|
|
card.querySelector(".rule-enabled").addEventListener("change", (e) => {
|
|
saveSchedule(card, { enabledOverride: e.target.checked });
|
|
});
|
|
|
|
card.querySelectorAll(".day-toggle").forEach((btn) => {
|
|
btn.addEventListener("click", () => btn.classList.toggle("active"));
|
|
});
|
|
|
|
card.querySelector(".add-schedule").addEventListener("click", () => {
|
|
const time = card.querySelector(".new-time").value;
|
|
const days = [...card.querySelectorAll(".day-toggle.active")].map((b) => b.dataset.day);
|
|
if (!time || days.length === 0) {
|
|
alert("Pick a time and at least one day.");
|
|
return;
|
|
}
|
|
addChip(card, time, days);
|
|
card.querySelectorAll(".day-toggle.active").forEach((b) => b.classList.remove("active"));
|
|
saveSchedule(card);
|
|
});
|
|
|
|
card.querySelectorAll(".chip-remove").forEach((btn) => bindRemove(btn));
|
|
|
|
card.querySelector(".run-now").addEventListener("click", async (e) => {
|
|
const btn = e.currentTarget;
|
|
const original = btn.textContent;
|
|
btn.disabled = true;
|
|
btn.textContent = "Queuing…";
|
|
try {
|
|
const res = await fetch(`/api/rules/${ruleId}/run`, { method: "POST" });
|
|
btn.textContent = res.ok ? "Queued" : "Failed";
|
|
} catch (err) {
|
|
btn.textContent = "Failed";
|
|
} finally {
|
|
setTimeout(() => {
|
|
btn.textContent = original;
|
|
btn.disabled = false;
|
|
}, 2000);
|
|
}
|
|
});
|
|
}
|
|
|
|
function bindRemove(btn) {
|
|
btn.addEventListener("click", () => {
|
|
const card = btn.closest(".rule-card");
|
|
btn.closest(".schedule-chip").remove();
|
|
saveSchedule(card);
|
|
});
|
|
}
|
|
|
|
function addChip(card, time, days) {
|
|
const list = card.querySelector(".schedule-list");
|
|
const li = document.createElement("li");
|
|
li.className = "schedule-chip";
|
|
li.innerHTML =
|
|
`<span class="chip-time">${time}</span>` +
|
|
`<span class="chip-days">${days.join(" ")}</span>` +
|
|
`<button type="button" class="chip-remove" title="Remove">×</button>`;
|
|
list.appendChild(li);
|
|
bindRemove(li.querySelector(".chip-remove"));
|
|
}
|
|
|
|
async function saveSchedule(card, opts = {}) {
|
|
const ruleId = card.dataset.ruleId;
|
|
const enabled =
|
|
opts.enabledOverride !== undefined ? opts.enabledOverride : card.querySelector(".rule-enabled").checked;
|
|
const schedules = [...card.querySelectorAll(".schedule-chip")].map((chip) => ({
|
|
time: chip.querySelector(".chip-time").textContent.trim(),
|
|
days: chip
|
|
.querySelector(".chip-days")
|
|
.textContent.trim()
|
|
.split(/\s+/)
|
|
.filter(Boolean),
|
|
}));
|
|
await fetch(`/api/rules/${ruleId}/schedule`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ enabled, schedules }),
|
|
});
|
|
}
|