-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
194 lines (172 loc) · 6.93 KB
/
Copy pathtest.html
File metadata and controls
194 lines (172 loc) · 6.93 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM Elements Test Page</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
.container {
background: #f5f5f5;
padding: 20px;
border-radius: 8px;
margin: 20px 0;
}
.highlight {
background: yellow;
padding: 2px 4px;
}
code {
background: #eee;
padding: 2px 4px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
.console-output {
background: #333;
color: #0f0;
padding: 15px;
border-radius: 5px;
font-family: monospace;
margin: 10px 0;
white-space: pre-wrap;
}
</style>
</head>
<body>
<!-- This script element is OUTSIDE body - original code would incorrectly include it -->
<header>
<h1>DOM Elements Test Page</h1>
<nav>
<ul>
<li><a href="#test1">Basic Test</a></li>
<li><a href="#test2">Advanced Test</a></li>
</ul>
</nav>
</header>
<main>
<section id="test1">
<h2>Basic Test</h2>
<div class="container">
<p>This page contains various HTML elements to test the <code>getUniqueDomElements</code> function.</p>
<article>
<h3>Sample Article</h3>
<p>This paragraph is inside an <span class="highlight">article</span> element.</p>
<blockquote>
"A quote to test blockquote elements."
</blockquote>
</article>
</div>
</section>
<section id="test2">
<h2>Advanced Test</h2>
<div class="container">
<form>
<fieldset>
<legend>Sample Form</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<br><br>
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea>
<br><br>
<button type="submit">Submit</button>
</fieldset>
</form>
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</tbody>
</table>
</div>
</section>
</main>
<footer>
<p>Test page for DOM element analysis</p>
<small>© 2024 DOM Elements Test</small>
</footer>
<!-- Load the improved script -->
<script src="js/scripts.js"></script>
<script>
// Demonstrate the improvements when page loads
document.addEventListener('DOMContentLoaded', function() {
console.log('=== DOM ELEMENTS TEST RESULTS ===\n');
// Show basic functionality
console.log('✅ Basic Implementation:');
console.log('getUniqueDomElements():', getUniqueDomElements());
console.log('');
// Show robust options
console.log('✅ With Options (lowercase, include body):');
console.log('getUniqueDomElementsRobust({ toLowerCase: true, includeContainer: true }):');
console.log(getUniqueDomElementsRobust({ toLowerCase: true, includeContainer: true }));
console.log('');
// Show metadata
console.log('✅ With Metadata (showing first 3 elements):');
const metadata = getUniqueDomElementsWithMetadata(true);
console.log('First 3 elements with metadata:');
metadata.slice(0, 3).forEach(item => {
console.log(`${item.tagName}: ${item.count} instances, classes: [${item.firstInstanceClasses.join(', ')}]`);
});
console.log('');
// Show DOM analysis
console.log('✅ DOM Structure Analysis:');
const analysis = analyzeDomStructure();
console.log(`Total elements in body: ${analysis.totalElements}`);
console.log(`Unique element types: ${analysis.uniqueElements}`);
console.log(`Most common element: ${analysis.mostCommon[0]} (${analysis.mostCommon[1]} instances)`);
console.log(`Maximum nesting depth: ${analysis.deepestNesting}`);
console.log('');
console.log('🎉 All tests completed! Open DevTools Console to see results.');
console.log('💡 Try running runExamples() to see more detailed output.');
// Add visual feedback to page
const resultDiv = document.createElement('div');
resultDiv.innerHTML = `
<div class="console-output">
✅ Tests completed successfully!
Basic elements found: ${getUniqueDomElements().join(', ')}
Total elements in body: ${analysis.totalElements}
Unique element types: ${analysis.uniqueElements}
Most common: ${analysis.mostCommon[0]} (${analysis.mostCommon[1]} instances)
Check the browser console for detailed results.
</div>
`;
document.body.appendChild(resultDiv);
});
// Add some interactive testing
function testInteractively() {
console.log('\n=== INTERACTIVE TEST ===');
// Test with different containers
const main = document.querySelector('main');
console.log('Elements in <main> only:',
getUniqueDomElementsRobust({ container: main }));
const form = document.querySelector('form');
console.log('Elements in <form> only:',
getUniqueDomElementsRobust({ container: form }));
console.log('✅ Interactive test completed');
}
// Expose test function globally
window.testInteractively = testInteractively;
</script>
</body>
</html>
<!-- This comment and any scripts here would be OUTSIDE body -->
<script>
// This script is outside body - the original flawed code might incorrectly include
// elements from here, but our improved version won't because it only searches within body
console.log("This script runs outside body - should not affect results");
</script>