-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurvey.js
More file actions
108 lines (99 loc) · 4.41 KB
/
Copy pathsurvey.js
File metadata and controls
108 lines (99 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(function () {
const roots = Array.from(document.querySelectorAll("[data-fit-survey]"));
if (!roots.length) return;
const reviewEmail = ["parker2017", "gmail.com"].join("@");
function fieldLabel(input) {
const label = input.closest("label");
if (!label) return input.name || "Field";
const span = label.querySelector("span");
return (span ? span.textContent : label.textContent).replace(/\s+/g, " ").trim();
}
function valuesFor(form) {
const grouped = new Map();
const controls = Array.from(form.querySelectorAll("input, textarea"));
controls.forEach((control) => {
const name = control.name || fieldLabel(control);
if (!name) return;
if ((control.type === "checkbox" || control.type === "radio") && !control.checked) return;
const value = control.type === "checkbox" || control.type === "radio" ? control.value : control.value.trim();
if (!value) return;
if (!grouped.has(name)) grouped.set(name, []);
grouped.get(name).push(value);
});
return grouped;
}
function scoreFor(form) {
return Array.from(form.querySelectorAll("input:checked"))
.reduce((total, input) => total + Number(input.dataset.score || 0), 0);
}
function textBonus(grouped) {
let bonus = 0;
["Problem", "User", "Help needed", "Profile", "Intro rule"].forEach((name) => {
const text = (grouped.get(name) || []).join(" ");
if (text.length >= 80) bonus += 4;
else if (text.length >= 35) bonus += 2;
});
if ((grouped.get("Evidence link") || [""])[0].startsWith("http")) bonus += 4;
return Math.min(bonus, 16);
}
function verdict(score) {
if (score >= 78) return "High routing readiness. Verify claims and consent next.";
if (score >= 56) return "Useful submission. Add evidence, risk, or next action.";
if (score >= 34) return "Early idea. Clarify user, Kaspa reason, and proof path.";
return "Needs sharper user, job, evidence, and status labels.";
}
function buildSummary(root, grouped, score, maxScore) {
const type = root.dataset.surveyType === "supporter" ? "Kaspa supporter survey" : "Kaspa builder fit survey";
const lines = [
type,
`Score: ${Math.min(score, maxScore)}/${maxScore}`,
`Verdict: ${verdict(Math.min(score, maxScore))}`,
"",
"Fields:"
];
grouped.forEach((values, name) => {
lines.push(`- ${name}: ${values.join(", ")}`);
});
lines.push("", "Review route: send by email for private approval before any public card or intro.");
lines.push("Consent check before sharing: confirm public-card permission and contact rule.");
lines.push("Status check before posting: use https://kaspaexplained.com/status and https://kaspaexplained.com/toccata-status.");
return lines.join("\n");
}
roots.forEach((root) => {
const form = root.querySelector("form");
const scoreEl = root.querySelector("[data-survey-score]");
const verdictEl = root.querySelector("[data-survey-verdict]");
const summaryEl = root.querySelector("[data-survey-summary]");
const copyButton = root.querySelector("[data-survey-copy]");
const mailLink = root.querySelector("[data-survey-mail]");
const statusEl = root.querySelector("[data-survey-status]");
const maxScore = Number(root.dataset.scoreMax || 100);
function render() {
const grouped = valuesFor(form);
const score = Math.min(scoreFor(form) + textBonus(grouped), maxScore);
const summary = buildSummary(root, grouped, score, maxScore);
scoreEl.textContent = `${score}/${maxScore}`;
verdictEl.textContent = verdict(score);
summaryEl.value = summary;
if (mailLink) {
const subject = root.dataset.surveyType === "supporter" ? "Kaspa supporter survey" : "Kaspa builder fit submission";
mailLink.href = `mailto:${reviewEmail}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(summary)}`;
mailLink.textContent = "Open email draft";
}
}
form.addEventListener("input", render);
form.addEventListener("change", render);
copyButton?.addEventListener("click", async () => {
render();
try {
await navigator.clipboard.writeText(summaryEl.value);
statusEl.textContent = "Survey summary copied.";
} catch (error) {
summaryEl.focus();
summaryEl.select();
statusEl.textContent = "Summary selected. Copy it if clipboard access is blocked.";
}
});
render();
});
})();