Skip to content

Commit

Permalink
refactor: Update Hacker News widget title link to use a div instead o…
Browse files Browse the repository at this point in the history
…f an anchor tag
  • Loading branch information
sametcn99 committed May 14, 2024
1 parent 5fb4865 commit c1a9a36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 2 additions & 8 deletions public/widgets/hacker news/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>

<html lang="en">
<head>
Expand Down Expand Up @@ -26,13 +26,7 @@ <h1 id="widget-title">
<p>Hacker News</p>
</h1>
<div id="story">
<a
id="title"
href="http://www.getdropbox.com/u/2/screencast.html"
target="_blank"
rel="noopener noreferrer"
>My YC app: Dropbox - Throw away your USB drive</a
>
<div id="title">My YC app: Dropbox - Throw away your USB drive</div>
<div id="footer">
<p id="time">1175714200</p>
<div id="byContainer">
Expand Down
9 changes: 6 additions & 3 deletions public/widgets/hacker news/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ document.getElementById("time").innerText = renderTime(1175714200);

async function fetchData() {
const response = await fetch(
"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty",
);
const data = await response.json();
console.log(data);
for (const id of data) {
const storyResponse = await fetch(
`https://hacker-news.firebaseio.com/v0/item/${id}.json?print=pretty`
`https://hacker-news.firebaseio.com/v0/item/${id}.json?print=pretty`,
);
const story = await storyResponse.json();
const storyContainer = document.getElementById("story").cloneNode(true);
storyContainer.id = "story";
storyContainer.style.display = "flex";
const time = storyContainer.querySelector("#time");
const title = storyContainer.querySelector("#title");
title.addEventListener("click", () => {
window.electronAPI.openExternal(story.url);
});
const score = storyContainer.querySelector("#score");
const by = storyContainer.querySelector("#by");
time.innerText = renderTime(story.time);
Expand All @@ -44,7 +47,7 @@ fetchData();

setInterval(
() => window.electronAPI.reloadWidget("hacker news"),
1000 * 60 * 60 // reload every hour
1000 * 60 * 60, // reload every hour
);

window.onscroll = function () {
Expand Down
1 change: 1 addition & 0 deletions public/widgets/hacker news/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ body {

#title:hover {
text-decoration: underline;
cursor: pointer;
}

h1 {
Expand Down

0 comments on commit c1a9a36

Please sign in to comment.