Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions hn-comments-for-user.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
</head>
<body>
<h1>Hacker News comments for a user</h1>
<div class="controls">
<form id="user-form" class="controls">
<label for="hn-user">Hacker News handle:</label>
<input id="hn-user" type="text" placeholder="e.g., pg" />
<button id="fetchBtn">Fetch comments</button>
<button id="copyBtn" disabled>Copy Output</button>
</div>
<button id="fetchBtn" type="submit">Fetch comments</button>
<button id="copyBtn" type="button" disabled>Copy Output</button>
</form>
<p>Fetches up to 1,000 recent comments.</p>
<textarea id="output" placeholder="Comments will appear here..."></textarea>
<div id="note"></div>

<script>
const form = document.getElementById('user-form');
const username = document.getElementById('hn-user');
const fetchBtn = document.getElementById('fetchBtn');
const copyBtn = document.getElementById('copyBtn');
Expand Down Expand Up @@ -83,7 +84,11 @@ <h1>Hacker News comments for a user</h1>
note.textContent = `Fetched ${all.length} comment(s).`;
}

fetchBtn.addEventListener('click', () => fetchComments(username.value.trim()));
const submitUsername = () => fetchComments(username.value.trim());
form.addEventListener('submit', (event) => {
event.preventDefault();
submitUsername();
});
copyBtn.addEventListener('click', async () => {
await navigator.clipboard.writeText(output.value);
const originalText = copyBtn.textContent;
Expand Down
Loading