Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6fbfc69

Browse files
andauthored
Refactor json-string-extractor.html to use fragment ID for loading example (#71)
* Initial plan * Refactor loadExampleJSON to use fragment ID link Co-authored-by: simonw <9599+simonw@users.noreply.github.com> * Add hashchange listener to load gist when fragment changes Co-authored-by: simonw <9599+simonw@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: simonw <9599+simonw@users.noreply.github.com>
1 parent 664d8fe commit 6fbfc69

File tree

1 file changed

+6
-27
lines changed
  • json-string-extractor.html

1 file changed

+6
-27
lines changed

json-string-extractor.html

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@

JSON string extractor

160160
<label for="jsonInput" style="font-size: 14px; color: #666;">Paste JSON here:label>
161161
<div style="display: flex; gap: 8px;">
162162
<button id="loadGist" class="load-example-button">Load Gistbutton>
163-
<button id="loadExample" class="load-example-button">Load example JSONbutton>
163+
<a href="#gist=1d1013ba059af76461153722005a039d" class="load-example-button" style="text-decoration: none; display: inline-block; line-height: 1.5;">Load example JSONa>
164164
div>
165165
div>
166166
<textarea id="jsonInput" placeholder="Paste your JSON here...">textarea>
@@ -174,33 +174,8 @@

JSON string extractor

174174
const jsonInput = document.getElementById('jsonInput');
175175
const errorDiv = document.getElementById('error');
176176
const resultsDiv = document.getElementById('results');
177-
const loadExampleButton = document.getElementById('loadExample');
178177
const loadGistButton = document.getElementById('loadGist');
179178

180-
async function loadExampleJSON() {
181-
loadExampleButton.disabled = true;
182-
loadExampleButton.textContent = 'Loading...';
183-
184-
try {
185-
const response = await fetch('https://gist.githubusercontent.com/simonw/1d1013ba059af76461153722005a039d/raw/0835963f6cc3554fe49c50f273660a6d01e4a7e0/response.json');
186-
187-
if (!response.ok) {
188-
throw new Error(`HTTP error! status: ${response.status}`);
189-
}
190-
191-
const text = await response.text();
192-
jsonInput.value = text;
193-
processJSON();
194-
195-
loadExampleButton.textContent = 'Load example JSON';
196-
} catch (e) {
197-
showError(`Failed to load example JSON: ${e.message}`);
198-
loadExampleButton.textContent = 'Load example JSON';
199-
} finally {
200-
loadExampleButton.disabled = false;
201-
}
202-
}
203-
204179
function extractGistId(input) {
205180
// Try to extract Gist ID from URL or use input directly
206181
const urlMatch = input.match(/gist\.github\.com\/[^\/]+\/([a-fA-F0-9]+)/i);
@@ -289,7 +264,6 @@

JSON string extractor

289264
}
290265
}
291266

292-
loadExampleButton.addEventListener('click', loadExampleJSON);
293267
loadGistButton.addEventListener('click', loadGist);
294268

295269
function showError(message) {
@@ -435,6 +409,11 @@

JSON string extractor

435409
loadGistFromHash().then(() => {
436410
processJSON();
437411
});
412+
413+
// Listen for hash changes to load gists dynamically
414+
window.addEventListener('hashchange', () => {
415+
loadGistFromHash();
416+
});
438417
script>
439418
body>
440419
html>

0 commit comments

Comments
(0)