セカンドライフお店オープン通知HUD
このHUDは、自分が興味のあるお店がオープンしたときに、自動的に通知してくれるものです。
まずは、以下のフォームに必要な情報を入力してください。
登録された通知は、以下のリストに表示されます。
<!DOCTYPE html>
<html>
<head>
<title>セカンドライフお店オープン通知HUD</title>
</head>
<body>
<h1>セカンドライフお店オープン通知HUD</h1>
<p>このHUDは、自分が興味のあるお店がオープンしたときに、自動的に通知してくれるものです。</p>
<p>まずは、以下のフォームに必要な情報を入力してください。</p>
<form>
<label for="shop-name">お店の名前:</label>
<input type="text" id="shop-name"><br>
<label for="keyword">お店のジャンルやキーワード:</label>
<input type="text" id="keyword"><br>
<button type="button" onclick="setNewNotification()">通知を登録</button>
</form>
<p>登録された通知は、以下のリストに表示されます。</p>
<ul id="notification-list">
<!-- 登録された通知がここに表示されます -->
</ul>
<script>
// 登録された通知を保存するための配列
let notifications = [];
// 通知を登録する関数
function setNewNotification() {
const shopName = document.getElementById("shop-name").value;
const keyword = document.getElementById("keyword").value;
// 入力が空の場合はエラーを表示する
if (!shopName || !keyword) {
alert("お店の名前とジャンルまたはキーワードを入力してください!");
return;
}
// 既に登録されている場合はエラーを表示する
const isAlreadyExist = notifications.some(notification => {
return notification.shopName === shopName && notification.keyword === keyword;
});
if (isAlreadyExist) {
alert("すでにこのお店のオープン通知は登録されています!");
return;
}
// 新しい通知を追加する
notifications.push({
shopName: shopName,
keyword: keyword
});
// 通知の内容を表示する
const newNotification = document.createElement("li");
newNotification.textContent = `「${shopName}」が「${keyword}」に関連するオープンをしたら通知する`;
document.getElementById("notification-list").appendChild(newNotification);
// 通知登録完了をメッセージで表示する
alert(`「${shopName}」が「${keyword}」に関連するオープンをしたら通知します!`);
}
// 通知をチェックする関数(定期的に実行される)
function checkNotifications() {
for (let notification of notifications) {
const shopName = notification.shopName;
const keyword = notification.keyword;
// セカンドライフのAPIを用いて、オープンしたお店のリストを取得する(省略)
// 取得したお店のリストから、ジャンルやキーワードに該当するお店があるか調べる(省略)
// 該当するお店があれば、通知する
if (matchShopNameAndKeyword) {
window.alert("「" + shopName + "」がオープンしました!");
}
}
}
// 1分ごとに通知をチェックするタイマーを設定する
setInterval(checkNotifications, 60000);
</script>
</body>
</html>
※ 本プログラムの実行には、セカンドライフのAPIを利用するためのトークンなどが必要です。また、セキュリティ上の脆弱性を考慮していないため、実際に使用する場合はセキュリティについて十分に検討した上で、必要に応じてセキュリティ対策を施してください。