-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
114 lines (101 loc) · 3.64 KB
/
app.js
File metadata and controls
114 lines (101 loc) · 3.64 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
109
110
111
112
113
114
// Toggle between sections
document.addEventListener('DOMContentLoaded', () => {
const sections = Array.from(document.querySelectorAll('[data-section]'));
const buttons = Array.from(document.querySelectorAll('nav [data-target]'));
function show(id) {
sections.forEach(sec => {
const on = (sec.id === id);
sec.hidden = !on; // native hidden attr
sec.classList.toggle('hidden', !on); // class fallback
});
buttons.forEach(btn => {
btn.classList.toggle('active', btn.dataset.target === id);
});
}
buttons.forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
const id = btn.dataset.target;
show(id);
// optional: reflect in URL
history.replaceState(null, '', `#${id}`);
});
});
// Initial state: hash (#madlibs) or default to sliders
const initial = (location.hash || '#sliders').slice(1);
show(initial);
});
// Sliders config update
["rigor", "human", "scale",
"rigor-left", "rigor-right",
"human-left", "human-right",
"scale-left", "scale-right"].forEach(id => {
document.getElementById(id).addEventListener("input", updateSlidersJSON);
});
function updateSlidersJSON() {
const json = {
axes: {
rigor: {
left: document.getElementById("rigor-left").value,
right: document.getElementById("rigor-right").value,
value: document.getElementById("rigor").value / 100
},
human: {
left: document.getElementById("human-left").value,
right: document.getElementById("human-right").value,
value: document.getElementById("human").value / 100
},
scale: {
left: document.getElementById("scale-left").value,
right: document.getElementById("scale-right").value,
value: document.getElementById("scale").value / 100
}
}
};
document.getElementById("sliders-output").textContent = JSON.stringify(json, null, 2);
}
updateSlidersJSON();
// Attach event listeners for Mad Libs fields
["genre", "character", "action", "setting",
"axis1", "axis1-left", "axis1-right",
"axis2", "axis2-left", "axis2-right"].forEach(id => {
document.getElementById(id).addEventListener("input", updateMadlibsJSON);
});
function updateMadlibsJSON() {
const json = {
prompt: "You are a creative writing assistant. Take the provided template, filled values, and axes, and generate a story that balances the axes accordingly.",
template: "Write a {genre} story about {character} who {action} in a {setting}.",
filled: {
genre: document.getElementById("genre").value,
character: document.getElementById("character").value,
action: document.getElementById("action").value,
setting: document.getElementById("setting").value
},
axes: {
tone: {
left: document.getElementById("axis1-left").value,
right: document.getElementById("axis1-right").value,
value: document.getElementById("axis1").value / 100
},
style: {
left: document.getElementById("axis2-left").value,
right: document.getElementById("axis2-right").value,
value: document.getElementById("axis2").value / 100
}
}
};
document.getElementById("madlibs-output").textContent =
JSON.stringify(json, null, 2);
}
// Run once on load
updateMadlibsJSON();
// Handle all copy buttons
document.querySelectorAll(".copy-btn").forEach(button => {
button.addEventListener("click", () => {
const targetId = button.getAttribute("data-target");
const text = document.getElementById(targetId).textContent;
navigator.clipboard.writeText(text).then(() => {
alert("JSON copied to clipboard!");
});
});
});