Spaces:
Running
Running
updateHistoryList(); | |
loadFromUserStorage(); | |
setInterval(() => { | |
saveToUserStorage(); | |
}, 60000); | |
// 入力フォームの内容を保存する | |
document.querySelectorAll('input, textarea').forEach(input => { | |
input.addEventListener('input', saveToUserStorage); | |
}); | |
// Ctrl+Enterでプロンプト生成を実行する | |
document.addEventListener('keydown', function (event) { | |
if (event.ctrlKey && event.key === 'Enter') { | |
event.preventDefault(); // デフォルトの動作を防ぐ | |
generatePrompt(); // プロンプト生成関数を呼び出す | |
} | |
}); | |
// サイドバーの切り替え機能を修正 | |
document.getElementById('sidebarToggle').addEventListener('click', function () { | |
const sidebarContainer = document.getElementById('sidebar-container'); | |
const content = document.getElementById('content'); | |
const isActive = sidebarContainer.classList.toggle('active'); | |
if (isActive) { | |
// サイドバーを開く | |
sidebarContainer.style.width = '250px'; | |
content.style.marginLeft = '250px'; | |
} else { | |
// サイドバーを閉じる | |
sidebarContainer.style.width = '0'; | |
content.style.marginLeft = '0'; | |
} | |
}); | |
function resizeQueryTextarea() { | |
const queryTextarea = document.getElementById('query'); | |
const cardBody = queryTextarea.closest('.card-body'); | |
queryTextarea.style.minHeight = cardBody.offsetHeight + 'px'; | |
} | |
document.addEventListener('DOMContentLoaded', function () { | |
resizeQueryTextarea(); | |
initSidebarResize(); // 新しい関数を呼び出し | |
}); | |
window.addEventListener('resize', resizeQueryTextarea); | |
// サイドバーのリサイズ機能を修正 | |
function initSidebarResize() { | |
const sidebarContainer = document.getElementById('sidebar-container'); | |
const content = document.getElementById('content'); | |
const resizer = document.getElementById('sidebar-resizer'); | |
let isResizing = false; | |
resizer.addEventListener('mousedown', (e) => { | |
isResizing = true; | |
document.addEventListener('mousemove', resize); | |
document.addEventListener('mouseup', stopResize); | |
}); | |
function resize(e) { | |
if (!isResizing) return; | |
const newWidth = e.clientX; | |
const minWidth = 250; | |
const maxWidth = 500; | |
const sidebarWidth = Math.min(Math.max(minWidth, newWidth), maxWidth); | |
sidebarContainer.style.width = `${sidebarWidth}px`; | |
content.style.marginLeft = `${sidebarWidth}px`; | |
sidebarContainer.classList.add('active'); // サイドバーを開いた状態にする | |
} | |
function stopResize() { | |
isResizing = false; | |
document.removeEventListener('mousemove', resize); | |
document.removeEventListener('mouseup', stopResize); | |
} | |
} | |
// localStorageをクリアする機能を追加 | |
function initClearStorageButton() { | |
const clearStorageButton = document.getElementById('clearStorageButton'); | |
clearStorageButton.addEventListener('click', () => { | |
const userInput = prompt('全てのデータを削除します。よろしければ「YES」と入力してください。'); | |
if (userInput === 'YES') { | |
localStorage.clear(); | |
alert('全てのデータが削除されました。ページを再読み込みします。'); | |
location.reload(); | |
} else { | |
alert('削除がキャンセルされました。'); | |
} | |
}); | |
} | |
// DOMContentLoadedイベントリスナーを更新 | |
document.addEventListener('DOMContentLoaded', function () { | |
resizeQueryTextarea(); | |
initSidebarResize(); | |
initClearStorageButton(); | |
// addDynamicStyles(); // この行を削除 | |
// 初期状態でサイドバーを非表示にする処理も不要になるため、削除 | |
// const sidebarContainer = document.getElementById('sidebar-container'); | |
// const content = document.getElementById('content'); | |
// sidebarContainer.classList.remove('active'); | |
// content.classList.remove('sidebar-active'); | |
}); | |
window.addEventListener('resize', resizeQueryTextarea); | |