Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
59 lines (54 loc) · 2.34 KB
/
Copy pathindex.html
File metadata and controls
59 lines (54 loc) · 2.34 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>狗屁不通文章生成器</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="options">
<div>最小字数:<input id="min" type="range" min="500" max="5000" step="100" value="2000"><span>2000</span></div>
<div>最大字数:<input id="max" type="range" min="1000" max="10000" step="100" value="5000"><span>5000</span>
</div>
</div>
<div class="ref"><a href="https://github.com/menzi11/BullshitGenerator">原版</a></div>
<div class="title"><span>标题:</span><input id="title" type="text" value="">
<button id="generate">生成</button>
<button id="anotherTitle">换一个</button>
</div>
</header>
<main>
<article></article>
</main>
<script type="module">
import { generate } from './lib/generator.js';
import { createRandomPicker } from './lib/random.js';
const options = document.querySelector('.options');
const config = { min: 2000, max: 5000 };
options.addEventListener('change', ({ target }) => {
const num = Number(target.value);
config[target.id] = num;
target.parentNode.querySelector('input + span').innerHTML = num;
});
const generateButton = document.getElementById('generate');
const anotherTitleButton = document.getElementById('anotherTitle');
const article = document.querySelector('article');
const titleEl = document.getElementById('title');
(async function () {
const corpus = await (await fetch('./corpus/data.json')).json();
const pickTitle = createRandomPicker(corpus.title);
titleEl.value = pickTitle();
generateButton.addEventListener('click', () => {
const text = generate(titleEl.value, { corpus, ...config });
article.innerHTML = `<section>${text.join('</section><section>')}</section>`;
});
anotherTitleButton.addEventListener('click', () => {
titleEl.value = pickTitle();
if (article.innerHTML) generateButton.click();
});
}());
</script>
</body>
</html>