-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_character.js
65 lines (55 loc) · 2.73 KB
/
new_character.js
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
// Function to retrieve form data and append to new_characters array
$(document).ready(function() {
var new_characters = JSON.parse(localStorage.getItem('new_characters')) || [];
function saveCharacterInfo() {
// Get the form data // Define the new_characters array
var name = $('#char_form input[name="name"]').val();
var gender = $('#char_form input[name="gender"]:checked').val();
var relationship = $('#char_form input[name="relationship"]:checked').val();
var talkingContext = $('#char_form input[name="context"]:checked').val();
var interests = [];
$('#char_form input[name="interest"]:checked').each(function() {
interests.push($(this).val());
});
var hates = $('#char_form input[name="hates"]').val();
var otherInfo = $('#char_form input[name="other_info"]').val();
// Create a new character object
var character = {
name: name,
gender: gender,
relationship: relationship,
talking_context: talkingContext,
interests: interests,
hates: hates,
other_info: otherInfo
};
// Append the character object to the new_characters array
new_characters.push(character);
// Log the new_characters array for testing
console.log(new_characters);
localStorage.setItem('new_characters', JSON.stringify(new_characters));
}
// Event handler for save_info button click
$('#save_info').on('click', function(event) {
event.preventDefault(); // Prevent form submission
saveCharacterInfo();
$('#char_form input[type="checkbox"]:checked, #char_form input[type="text"], #char_form textarea').val('')
$('#char_form input[type="checkbox"]:checked').prop('checked', false);
$('#char_form input[type="radio"]:checked').prop('checked', false);
window.close();
// Refresh home.html page
// window.opener.location.reload();
});
});
//Dark mode
const darkModeButton = document.getElementById('mymode');
const htmlRoot = document.querySelector('html');
darkModeButton.addEventListener('click', () => {
if (htmlRoot.getAttribute('data-bs-theme') === 'dark') {
htmlRoot.removeAttribute('data-bs-theme');
darkModeButton.textContent = 'Dark mode'
} else {
htmlRoot.setAttribute('data-bs-theme', 'dark');
darkModeButton.textContent = 'Light mode'
}
});