Spaces:
Running
Running
Update goo
Browse files
goo
CHANGED
|
@@ -3,22 +3,19 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>HTML Viewer
|
| 7 |
<style>
|
| 8 |
.hidden { display: none; }
|
| 9 |
</style>
|
| 10 |
</head>
|
| 11 |
<body>
|
| 12 |
<h1>HTML Viewer</h1>
|
| 13 |
-
|
| 14 |
<label for="modeSelect">モードを選択:</label>
|
| 15 |
<select id="modeSelect">
|
| 16 |
<option value="html">HTML表示モード</option>
|
| 17 |
<option value="url">URLのiframe表示モード</option>
|
| 18 |
-
<option value="pip">PiPウィンドウ表示モード</option>
|
| 19 |
</select>
|
| 20 |
<br>
|
| 21 |
-
|
| 22 |
<label for="displayTarget">表示先を選択:</label>
|
| 23 |
<select id="displayTarget">
|
| 24 |
<option value="blob">blobURL</option>
|
|
@@ -27,7 +24,7 @@
|
|
| 27 |
</select>
|
| 28 |
|
| 29 |
<div id="htmlMode">
|
| 30 |
-
<textarea id="htmlInput" placeholder="ここにHTMLを入力してください" rows="10" cols="50"><
|
| 31 |
</div>
|
| 32 |
|
| 33 |
<div id="urlMode" class="hidden">
|
|
@@ -54,17 +51,13 @@
|
|
| 54 |
const clearButton = document.getElementById('clearButton');
|
| 55 |
const errorMessage = document.getElementById('errorMessage');
|
| 56 |
|
| 57 |
-
// モード切り替え
|
| 58 |
modeSelect.addEventListener('change', () => {
|
| 59 |
if (modeSelect.value === 'html') {
|
| 60 |
htmlMode.classList.remove('hidden');
|
| 61 |
urlMode.classList.add('hidden');
|
| 62 |
-
} else
|
| 63 |
htmlMode.classList.add('hidden');
|
| 64 |
urlMode.classList.remove('hidden');
|
| 65 |
-
} else {
|
| 66 |
-
htmlMode.classList.remove('hidden');
|
| 67 |
-
urlMode.classList.add('hidden');
|
| 68 |
}
|
| 69 |
});
|
| 70 |
|
|
@@ -72,115 +65,47 @@
|
|
| 72 |
errorMessage.textContent = '';
|
| 73 |
const target = displayTarget.value;
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
if (!
|
| 79 |
errorMessage.textContent = 'HTMLを入力してください。';
|
| 80 |
return;
|
| 81 |
}
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
const video = document.createElement('video');
|
| 86 |
-
video.setAttribute('autoplay', '');
|
| 87 |
-
video.setAttribute('muted', '');
|
| 88 |
-
video.setAttribute('playsinline', '');
|
| 89 |
-
video.style.display = 'none';
|
| 90 |
-
|
| 91 |
-
const canvas = document.createElement('canvas');
|
| 92 |
-
const ctx = canvas.getContext('2d');
|
| 93 |
-
canvas.width = 640;
|
| 94 |
-
canvas.height = 360;
|
| 95 |
-
|
| 96 |
-
const htmlContainer = document.createElement('div');
|
| 97 |
-
htmlContainer.style.width = '640px';
|
| 98 |
-
htmlContainer.style.height = '360px';
|
| 99 |
-
htmlContainer.innerHTML = htmlContent;
|
| 100 |
-
|
| 101 |
-
document.body.appendChild(video); // 必須: 動画がDOMにないとPiPは許可されない
|
| 102 |
-
document.body.appendChild(htmlContainer);
|
| 103 |
-
htmlContainer.style.position = 'absolute';
|
| 104 |
-
htmlContainer.style.left = '-9999px'; // 画面に表示させない
|
| 105 |
-
|
| 106 |
-
const stream = canvas.captureStream();
|
| 107 |
-
video.srcObject = stream;
|
| 108 |
-
|
| 109 |
-
video.play();
|
| 110 |
-
|
| 111 |
-
// 描画ループ
|
| 112 |
-
const draw = () => {
|
| 113 |
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 114 |
-
ctx.drawImage(htmlContainer, 0, 0, canvas.width, canvas.height);
|
| 115 |
-
requestAnimationFrame(draw);
|
| 116 |
-
};
|
| 117 |
-
draw();
|
| 118 |
-
|
| 119 |
-
await video.requestPictureInPicture();
|
| 120 |
-
} catch (e) {
|
| 121 |
-
errorMessage.textContent = 'PiP表示に失敗しました: ' + e.message;
|
| 122 |
-
}
|
| 123 |
-
} else {
|
| 124 |
-
try {
|
| 125 |
-
if (target === 'blob') {
|
| 126 |
-
const blob = new Blob([htmlContent], { type: 'text/html' });
|
| 127 |
-
const url = URL.createObjectURL(blob);
|
| 128 |
-
const newWindow = window.open(url);
|
| 129 |
-
if (!newWindow) {
|
| 130 |
-
errorMessage.textContent = '新しいタブを開けませんでした。ポップアップがブロックされている可能性があります。';
|
| 131 |
-
}
|
| 132 |
-
} else if (target === 'blank') {
|
| 133 |
-
const newWindow = window.open('about:blank');
|
| 134 |
-
if (newWindow) {
|
| 135 |
-
newWindow.document.write(htmlContent);
|
| 136 |
-
newWindow.document.close();
|
| 137 |
-
} else {
|
| 138 |
-
errorMessage.textContent = '新しいタブを開けませんでした。ポップアップがブロックされている可能性があります。';
|
| 139 |
-
}
|
| 140 |
-
}
|
| 141 |
-
} catch (e) {
|
| 142 |
-
errorMessage.textContent = 'エラーが発生しました: ' + e.message;
|
| 143 |
-
}
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
} else if (modeSelect.value === 'url') {
|
| 147 |
-
const url = document.getElementById('urlInput').value;
|
| 148 |
-
|
| 149 |
-
if (!url.trim()) {
|
| 150 |
errorMessage.textContent = 'URLを入力してください。';
|
| 151 |
return;
|
| 152 |
}
|
|
|
|
|
|
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
errorMessage.textContent = '新しいタブを開けませんでした。ポップアップがブロックされている可能性があります。';
|
| 170 |
-
}
|
| 171 |
-
} else if (target === 'pip') {
|
| 172 |
-
errorMessage.textContent = 'URLモードではPiP表示はサポートされていません。';
|
| 173 |
-
}
|
| 174 |
-
} catch (e) {
|
| 175 |
-
errorMessage.textContent = 'エラーが発生しました: ' + e.message;
|
| 176 |
}
|
|
|
|
|
|
|
| 177 |
}
|
| 178 |
});
|
| 179 |
|
| 180 |
clearButton.addEventListener('click', () => {
|
| 181 |
-
if (modeSelect.value === 'html'
|
| 182 |
document.getElementById('htmlInput').value = '';
|
| 183 |
-
} else
|
| 184 |
document.getElementById('urlInput').value = '';
|
| 185 |
}
|
| 186 |
errorMessage.textContent = '';
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>HTML Viewer</title>
|
| 7 |
<style>
|
| 8 |
.hidden { display: none; }
|
| 9 |
</style>
|
| 10 |
</head>
|
| 11 |
<body>
|
| 12 |
<h1>HTML Viewer</h1>
|
|
|
|
| 13 |
<label for="modeSelect">モードを選択:</label>
|
| 14 |
<select id="modeSelect">
|
| 15 |
<option value="html">HTML表示モード</option>
|
| 16 |
<option value="url">URLのiframe表示モード</option>
|
|
|
|
| 17 |
</select>
|
| 18 |
<br>
|
|
|
|
| 19 |
<label for="displayTarget">表示先を選択:</label>
|
| 20 |
<select id="displayTarget">
|
| 21 |
<option value="blob">blobURL</option>
|
|
|
|
| 24 |
</select>
|
| 25 |
|
| 26 |
<div id="htmlMode">
|
| 27 |
+
<textarea id="htmlInput" placeholder="ここにHTMLを入力してください" rows="10" cols="50"><!DOCTYPE html><html lang="ja"><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title> </title><style>html,body{margin:0;padding:0;overflow:hidden;width:100vw;height:100vh}</style><iframe src="https://gooberdash.winterpixel.io/" style="width:100vw;height:100vh;border:none;display:block;margin:0;padding:0"></iframe></textarea><br>
|
| 28 |
</div>
|
| 29 |
|
| 30 |
<div id="urlMode" class="hidden">
|
|
|
|
| 51 |
const clearButton = document.getElementById('clearButton');
|
| 52 |
const errorMessage = document.getElementById('errorMessage');
|
| 53 |
|
|
|
|
| 54 |
modeSelect.addEventListener('change', () => {
|
| 55 |
if (modeSelect.value === 'html') {
|
| 56 |
htmlMode.classList.remove('hidden');
|
| 57 |
urlMode.classList.add('hidden');
|
| 58 |
+
} else {
|
| 59 |
htmlMode.classList.add('hidden');
|
| 60 |
urlMode.classList.remove('hidden');
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
});
|
| 63 |
|
|
|
|
| 65 |
errorMessage.textContent = '';
|
| 66 |
const target = displayTarget.value;
|
| 67 |
|
| 68 |
+
let content = '';
|
| 69 |
+
if (modeSelect.value === 'html') {
|
| 70 |
+
content = document.getElementById('htmlInput').value.trim();
|
| 71 |
+
if (!content) {
|
| 72 |
errorMessage.textContent = 'HTMLを入力してください。';
|
| 73 |
return;
|
| 74 |
}
|
| 75 |
+
} else {
|
| 76 |
+
const url = document.getElementById('urlInput').value.trim();
|
| 77 |
+
if (!url) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
errorMessage.textContent = 'URLを入力してください。';
|
| 79 |
return;
|
| 80 |
}
|
| 81 |
+
content = `<!DOCTYPE html><html lang="ja"><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title> </title><style>html,body{margin:0;padding:0;overflow:hidden;width:100vw;height:100vh}</style><iframe src="${url}" style="width:100vw;height:100vh;border:none;"></iframe></html>`;
|
| 82 |
+
}
|
| 83 |
|
| 84 |
+
try {
|
| 85 |
+
if (target === 'blob') {
|
| 86 |
+
const blob = new Blob([content], { type: 'text/html' });
|
| 87 |
+
const url = URL.createObjectURL(blob);
|
| 88 |
+
const newWindow = window.open(url);
|
| 89 |
+
if (!newWindow) throw new Error('ポップアップがブロックされています。');
|
| 90 |
+
} else if (target === 'blank') {
|
| 91 |
+
const newWindow = window.open('about:blank');
|
| 92 |
+
if (newWindow) {
|
| 93 |
+
newWindow.document.write(content);
|
| 94 |
+
newWindow.document.close();
|
| 95 |
+
} else throw new Error('ポップアップがブロックされています。');
|
| 96 |
+
} else if (target === 'pip') {
|
| 97 |
+
const pipWindow = await documentPictureInPicture.requestWindow();
|
| 98 |
+
pipWindow.document.body.innerHTML = content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
+
} catch (e) {
|
| 101 |
+
errorMessage.textContent = 'エラーが発生しました: ' + e.message;
|
| 102 |
}
|
| 103 |
});
|
| 104 |
|
| 105 |
clearButton.addEventListener('click', () => {
|
| 106 |
+
if (modeSelect.value === 'html') {
|
| 107 |
document.getElementById('htmlInput').value = '';
|
| 108 |
+
} else {
|
| 109 |
document.getElementById('urlInput').value = '';
|
| 110 |
}
|
| 111 |
errorMessage.textContent = '';
|