jacobinathanialpeterson commited on
Commit
a898227
1 Parent(s): ad43143

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +19 -36
static/script.js CHANGED
@@ -54,43 +54,26 @@ function getMessages(roomId=myRoomId, url="https://jacobinathanialpeterson-chatb
54
  })
55
  .then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
56
  .then(data => {
57
- if (data.message) {
58
- // Get the button element you want to preserve
59
- const preserveButton1 = document.getElementById('createRoom');
60
- const preserveButton2 = document.getElementById('joinRoom');
61
-
62
- // Get the parent element containing all the elements you want to remove
63
- const parentElement = document.body; // Change this selector according to your DOM structure
64
-
65
- // Get all children of the parent element
66
- const children = parentElement.children;
67
-
68
- // Loop through the children and remove elements that are not the preserveButton
69
- for (let i = 0; i < children.length; i++) {
70
- const element = children[i];
71
- if (element !== preserveButton1 || element !== preserveButton2) {
72
- element.remove(); // Remove the element from the DOM
73
- }
74
- }
 
75
  }
76
- // Get the keys of the object
77
- const keys = Object.keys(data);
78
-
79
- // Sort the keys based on their natural order
80
- keys.sort((a, b) => {
81
- // Extract numeric part of keys
82
- const numA = parseInt(a.match(/\d+/)[0]);
83
- const numB = parseInt(b.match(/\d+/)[0]);
84
- return numA - numB;
85
- });
86
-
87
- // Create a new object with sorted keys
88
- DATA = {};
89
- keys.forEach(key => {
90
- DATA[key] = data[key];
91
- });
92
-
93
- controller.abort();
94
  })
95
  .catch(error => { if (error.name === 'AbortError') { console.log('Fetch aborted:', error.message) } else { console.error('Error fetching data:', error.message) }});
96
  }
 
54
  })
55
  .then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
56
  .then(data => {
57
+ if (!data.message) {
58
+ // Get the keys of the object
59
+ const keys = Object.keys(data);
60
+
61
+ // Sort the keys based on their natural order
62
+ keys.sort((a, b) => {
63
+ // Extract numeric part of keys
64
+ const numA = parseInt(a.match(/\d+/)[0]);
65
+ const numB = parseInt(b.match(/\d+/)[0]);
66
+ return numA - numB;
67
+ });
68
+
69
+ // Create a new object with sorted keys
70
+ DATA = {};
71
+ keys.forEach(key => {
72
+ DATA[key] = data[key];
73
+ });
74
+
75
+ controller.abort();
76
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  })
78
  .catch(error => { if (error.name === 'AbortError') { console.log('Fetch aborted:', error.message) } else { console.error('Error fetching data:', error.message) }});
79
  }