| 1 | (function () { |
| 2 | var root = document.querySelector("[data-reveal-url]"); |
| 3 | if (!root) { |
| 4 | return; |
| 5 | } |
| 6 | var csrfEl = document.querySelector("[data-secret-csrf]"); |
| 7 | root.querySelectorAll("[data-reveal]").forEach(function (btn) { |
| 8 | btn.addEventListener("click", function () { |
| 9 | var row = btn.closest("tr"); |
| 10 | var out = row && row.querySelector("[data-revealed]"); |
| 11 | if (!out) { |
| 12 | return; |
| 13 | } |
| 14 | var csrf = csrfEl ? csrfEl.value : ""; |
| 15 | var body = "csrf=" + encodeURIComponent(csrf) + "&name=" + encodeURIComponent(btn.getAttribute("data-reveal") || ""); |
| 16 | fetch(root.getAttribute("data-reveal-url"), { |
| 17 | method: "POST", |
| 18 | headers: { "Content-Type": "application/x-www-form-urlencoded" }, |
| 19 | body: body |
| 20 | }).then(function (res) { |
| 21 | return res.text().then(function (text) { |
| 22 | var data = {}; |
| 23 | try { |
| 24 | data = JSON.parse(text); |
| 25 | } catch (e) { |
| 26 | data = { error: text }; |
| 27 | } |
| 28 | return { ok: res.ok, data: data }; |
| 29 | }); |
| 30 | }).then(function (r) { |
| 31 | out.hidden = false; |
| 32 | out.textContent = r.ok ? (r.data.value || "") : (r.data.error || ""); |
| 33 | }); |
| 34 | }); |
| 35 | }); |
| 36 | })(); |