forked from wjh18/hugo-liftoff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
functions: hatena: show hatena stars
Signed-off-by: smallkirby <ssmallkirby@gmail.com>
- Loading branch information
1 parent
7a234c7
commit 4b45d67
Showing
9 changed files
with
141 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
const fetchHatenaStars = (uri) => { | ||
const colors = { | ||
normal: '#ffb000', | ||
green: '#00d300', | ||
red: '#ff003e', | ||
blue: '#00a1de', | ||
purple: '#b400c0', | ||
}; | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
const setStars = (stars) => { | ||
const container = document.getElementById('hatena-stars'); | ||
if (!container) { | ||
return; | ||
} | ||
|
||
for (const star of stars) { | ||
const starSpan = document.createElement('span'); | ||
starSpan.classList.add('hatena-star'); | ||
starSpan.classList.add(`hatena-star-${star.color}`); | ||
starSpan.innerHTML = '★'; | ||
const color = colors[star.color] || colors['normal']; | ||
starSpan.style.color = color; | ||
container.appendChild(starSpan); | ||
} | ||
}; | ||
|
||
fetch(`/funcs/hatenastar?uri=${encodeURIComponent(uri)}`).then( | ||
async (res) => { | ||
if (res.status !== 200) { | ||
console.error('Failed to fetch stars'); | ||
return; | ||
} | ||
const data = await res.json(); | ||
if (data.msg !== 'ok') { | ||
console.error('Failed to fetch stars: ' + data.msg); | ||
return; | ||
} | ||
|
||
const stars = data.stars; | ||
setStars(stars); | ||
} | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.hatena { | ||
display: flex; | ||
width: 100%; | ||
|
||
.hatena-bookmark { | ||
margin-right: 1rem; | ||
} | ||
|
||
.hatena-star-area { | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
|
||
img { | ||
cursor: pointer; | ||
display: block; | ||
margin-right: 0.5rem; | ||
} | ||
|
||
.hatena-star { | ||
font-size: 1.1rem; | ||
cursor: pointer; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters