入力ワードをランダムチョイスで適当な文章みたいなものを生成するプログラムです.
だいぶ以前に自力かChatGPTに訊いてpythonで作ったプログラムがあるんですが、
exeファイルしかなくて、
動作がやや重いので、
GPTsのGrimoire(https://chat.openai.com/g/g-n7Rs0IK86-grimoire) に作ってもらった.
Grimoireさん、前はいきなりhtmlファイルで返してくれる仕様じゃなかったと思うんですが...どうだったでしょうか?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cute Word List Application</title>
<style>
body {
font-family: 'Comic Sans MS', cursive, sans-serif;
background-color: #f0e6f6;
color: #333;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
input, button {
border: none;
padding: 10px 15px;
margin: 5px;
border-radius: 15px;
font-size: 16px;
outline: none;
}
button {
background-color: #f9d5e5;
color: #333;
cursor: pointer;
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.2);
transition: background-color 0.3s;
}
button:hover {
background-color: #f4aacb;
}
border: 2px solid #f4aacb;
}
border: 1px solid #f4aacb;
border-radius: 10px;
padding: 10px;
margin-top: 10px;
width: 300px;
text-align: center;
}
</style>
</head>
<body>
<input type="text" id="wordInput" placeholder="Enter a word" />
<div>
<button onclick="addWord()">Add</button>
<input type="file" id="fileInput" accept=".txt" onchange="loadFile(event)" style="display: none;" />
<button onclick="fileInput.click()">Upload File</button>
<button onclick="downloadAsText()">Download as Text</button>
<button onclick="outputWords()">Output</button>
</div>
<div id="wordList"></div>
<div id="outputArea"></div>
<script>
let words = [];
function addWord() {
const input = document.getElementById('wordInput');
if (input.value) {
words.push(input.value);
input.value = '';
displayWords();
}
}
function displayWords() {
const listElement = document.getElementById('wordList');
listElement.innerHTML = words.join(', ');
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function outputWords() {
shuffleArray(words);
const output = words.slice(0, 10).join(' ');
document.getElementById('outputArea').textContent = output;
}
function downloadAsText() {
const textToWrite = words.join('\n');
const textBlob = new Blob([textToWrite], { type: 'text/plain' });
const downloadLink = document.createElement('a');
downloadLink.download = 'WordList.txt';
downloadLink.href = window.URL.createObjectURL(textBlob);
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
document.body.removeChild(downloadLink);
}
function loadFile(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const fileContents = e.target.result;
const fileWords = fileContents.split(/\r\n|\n|\r/);
words.push(...fileWords);
displayWords();
};
reader.readAsText(file);
}
}
</script>
</body>
</html>
Comments