evesquare
ドラマも含むかも。
感想を書いてみたりみなかったり。
評価をつけてみたりつけてみなかったり。
2025ベスト
twitter: @evesquaretti
code:script.js
// Scrapbox.io 年間映画視聴数表示カスタマイズ
// この関数は指定された年の映画視聴記録の数を取得します
async function countMovieInYear(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 displayMovieCountInHeader() {
const year = new Date().getFullYear();
const count = await countMovieInYear(year);
// すでに表示要素がある場合は削除(再表示防止)
const existingElement = document.querySelector('.movie-count-display');
if (existingElement) {
existingElement.remove();
}
// 映画カウント表示用の要素を作成
const movieCountElement = document.createElement('li');
movieCountElement.className = 'movie-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タグを追加
movieCountElement.appendChild(linkElement);
// .navbar-menuを取得して、その最初の子要素の前に挿入
const navbarMenu = document.querySelector('.navbar-menu');
if (navbarMenu) {
// 既存のメニュー項目の前に挿入
if (navbarMenu.firstChild) {
navbarMenu.insertBefore(movieCountElement, navbarMenu.firstChild);
} else {
navbarMenu.appendChild(movieCountElement);
}
console.log('映画カウントを.navbar-menuに表示しました✨');
} else {
console.error('navbar-menu要素が見つかりませんでした💦');
}
}
function initMovieCounter() {
setTimeout(async () => {
await displayMovieCountInHeader();
}, 500);
}
(async () => await initMovieCounter())();