-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (57 loc) · 2.47 KB
/
script.js
File metadata and controls
76 lines (57 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import init,{is_png} from "./WebBinaryViewer_bg.js";
init()
const dropArea = document.getElementById('dropArea');
// ドラッグイベントのデフォルト動作を抑制する
dropArea.addEventListener('dragover', (e) => {
e.preventDefault();
});
// ファイルをドラッグエリアに入れたときの処理
dropArea.addEventListener('dragenter', (e) => {
e.preventDefault();
dropArea.style.backgroundColor = 'rgba(255, 165, 0, 0.5)'; // オレンジ色に変更(アルファ値を指定してほんのりとした透明度にする)
});
// ファイルをドラッグエリアから出したときの処理
dropArea.addEventListener('dragleave', (e) => {
e.preventDefault();
dropArea.style.backgroundColor = 'lightgray'; // 元の色に戻す
});
// ファイルをドロップしたときの処理
dropArea.addEventListener('drop', (e) => {
e.preventDefault();
dropArea.style.backgroundColor = 'lightgray'; // 元の色に戻す
const files = e.dataTransfer.files;
if (files.length > 0) {
// ドロップされたファイルを処理する関数を呼び出す
handleFile(files[0]);
}
});
function handleFile(selectedFile) {
// ファイルの内容を取得したり、ファイルをアップロードしたりする処理をここに記述する
// 例:ファイルの内容をコンソールに出力する
const reader = new FileReader();
reader.onload = onload;
reader.readAsArrayBuffer(selectedFile);
}
const Fileopendialog = document.getElementById("Fileopendialog");
Fileopendialog.addEventListener("click",()=>{
const fileInput = document.createElement('input');
fileInput.type = 'file';
// 選択されたファイルが変更されたときのイベントリスナーを設定
fileInput.addEventListener('change', (e) => {
const selectedFile = e.target.files[0];
// FileReaderオブジェクトを使用してファイルのバイナリデータを読み込む
const reader = new FileReader();
reader.onload=onload;
// ファイルをバイナリデータとして読み込む
reader.readAsArrayBuffer(selectedFile);
});
// ファイル選択ダイアログを開く
fileInput.click();
})
function onload(e) {
let arrayBuffer = e.target.result;
console.log(arrayBuffer.slice(0, 10)) //先頭10のみ表示
let Array_u8 = new Uint8Array(arrayBuffer);
console.log(is_png(Array_u8));
create_table(Array_u8);
}