// /mods/submit: signs in with GitHub through the registry's service, then sends the page and the file. The service // checks the file and answers with the pull request it opened, or with what to fix. import { API, entryFrom } from "./mods.js"; import { setUpMenu, setUpTheme } from "./chrome.js"; import { escape } from "./markdown.js"; const auth = document.getElementById("submit-auth"); const form = document.getElementById("submit-form"); const result = document.getElementById("submit-result"); let csrf = ""; // The form's own controls by name (form.id and form.name are the form's attributes). const control = (name) => form.elements.namedItem(name); function signedOut(message) { auth.innerHTML = `
`; form.hidden = true; } async function start() { let me; try { const r = await fetch(`${API}/me`, { credentials: "same-origin" }); if (r.status === 401) return signedOut("Sign in to submit: reviewers and updates go through your GitHub account."); if (!r.ok) throw new Error(String(r.status)); me = await r.json(); } catch { auth.innerHTML = ``; return; } csrf = me.csrf; auth.innerHTML = ``; document.getElementById("sign-out").addEventListener("click", async () => { await fetch(`${API}/auth/logout`, { method: "POST", credentials: "same-origin" }); signedOut("Signed out."); }); form.hidden = false; } // A file namedSubmitted. Follow the review in its pull request: the checks' report is there, and reviewers answer there.
`; form.reset(); } else { result.innerHTML = `${escape(json.error || `The service answered ${r.status}.`)}
`; } } catch { result.innerHTML = `The service didn't answer. Try again in a minute.
`; } finally { send.disabled = false; } }); setUpTheme(); setUpMenu(); start();