if (document.URL.match(/new/) || document.URL.match(/edit/)) {
document.addEventListener('DOMContentLoaded', function () {
const ImageList = document.getElementById("image-list")
document.getElementById('message_image').addEventListener('change', function (e) {
// 投稿した時、既に画像が表示されている場合は、その画像を削除する
const imageContent = document.querySelector('img');
if (imageContent) {
imageContent.remove();
}
//console.log(e); 画像のパスを調べる e.target.files[0]
const file = e.target.files[0]; //一番最新の画像
const blob = window.URL.createObjectURL(file); //最新の画像のURLを作成
const imageElement = document.createElement('div'); // 画像を表示するためのdiv要素を生成
const blobImage = document.createElement('img'); // 表示する画像要素を生成
blobImage.setAttribute('src', blob); //最新の画像のURLを指定
// 生成したHTMLの要素をブラウザに表示させる
imageElement.appendChild(blobImage); //最新の画像をdivに
ImageList.appendChild(imageElement); //divをWindows画面に
});
});
}