evesquare
https://scrapbox.io/files/67ef3bcb13f9c760ecc20389.jpeghttps://scrapbox.io/files/645ce9704f2bce001c574f84.jpg
Web Engineer
2001年生まれ
上の画像は筆記体など知らないがそれっぽくホワイトボードに書いたやつ。
X(Twitter): @evesquare_dev(あまりつぶやかない)
他のScrapBox:
table:好きなもの
1位なんて決められない。
code:script.js
// Scrapbox.io 年間アニメ視聴数表示カスタマイズ
// この関数は現在の年を取得します
function getCurrentYear() {
return new Date().getFullYear();
}
// この関数は指定された年のアニメ視聴記録の数を取得します
async function countAnimeInYear(year) {
try {
// Scrapbox APIからアニメデータを取得
const response = await fetch(url);
// レスポンスエラーをチェック
if (!response.ok) {
console.error(データ取得エラー: ${response.status});
return 0;
}
const data = await response.json();
// updatedが今年のものだけカウント
return data.filter(item => {
const updatedDate = new Date(item.updated * 1000);
return updatedDate.getFullYear() === year;
}).length;
} catch (error) {
console.error('アニメデータの取得中にエラーが発生しました💦:', error);
return 0; // エラー時は0を返す
}
}
// ヘッダーの.navbar-menuに年間アニメ視聴数を表示する関数
async function displayAnimeCountInHeader() {
const year = new Date().getFullYear();
const count = await countAnimeInYear(year);
// すでに表示要素がある場合は削除(再表示防止)
const existingElement = document.querySelector('.anime-count-display');
if (existingElement) {
existingElement.remove();
}
// アニメカウント表示用の要素を作成
const animeCountElement = document.createElement('li');
animeCountElement.className = 'anime-count-display';
// liの中に表示用のaタグを作成(Scrapboxのヘッダーのスタイルに合わせる)
const linkElement = document.createElement('a');
linkElement.href = "#"; // リンクは機能しないけどスタイルのため
linkElement.innerHTML = 🎬 ${year}年: ${count}本;
linkElement.style.fontSize = '14px';
linkElement.style.fontWeight = 'bold';
linkElement.style.color = 'white';
// liにaタグを追加
animeCountElement.appendChild(linkElement);
// .navbar-menuを取得して、その最初の子要素の前に挿入
const navbarMenu = document.querySelector('.navbar-menu');
if (navbarMenu) {
// 既存のメニュー項目の前に挿入
if (navbarMenu.firstChild) {
navbarMenu.insertBefore(animeCountElement, navbarMenu.firstChild);
} else {
navbarMenu.appendChild(animeCountElement);
}
console.log('アニメカウントを.navbar-menuに表示しました✨');
} else {
console.error('navbar-menu要素が見つかりませんでした💦');
}
}
function initAnimeCounter() {
setTimeout(async () => {
await displayAnimeCountInHeader();
}, 500);
}
(async () => await initAnimeCounter())();
evesquare.icon