-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchcount.html
143 lines (136 loc) · 4.42 KB
/
chcount.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1">
<title>文字数カウント・リターンズ</title>
<style>
html {
background-color: #ccc;
}
body {
max-width: 800px;
margin: 0 auto;
padding: 2px 12px;
background-color: #fff;
color: #333;
}
#textarea {
box-sizing: border-box;
width: 100%;
min-height: 12em;
padding: 8px;
font-size: 16px;
line-height: 1.5;
color: #000;
}
#input-actions {
text-align: right;
}
.notice {
font-size: 85%;
color: #999;
}
#result {
margin: 0 auto;
border-collapse: collapse;
}
#result tr {
border-bottom: 1px solid #ccc;
}
#result th {
padding: 2px;
text-align: left;
color: #666;
font-weight: normal;
}
#result td.value {
min-width: 3em;
padding: 2px 8px;
text-align: right;
color: #328d4d;
font-weight: bold;
}
#result td.actions {
padding: 2px 12px;
}
#result td.actions button {
background-color: transparent;
border: none;
cursor: pointer;
outline: none;
padding: 0;
appearance: none;
color: #5793cc;
font-size: 11px;
font-weight: bold;
}
</style>
</head>
<body>
<h1>文字数カウント・リターンズ</h1>
<textarea id="textarea" placeholder="テキストを入力"></textarea>
<div id="input-actions">
<button id="action-paste">貼り付け</button>
<button id="action-clear">クリア</button>
</div>
<table id="result">
<tr id="field1">
<th>■文字数(スペース込み)</th>
<td class="value"><span>0</span></td>
<td class="actions"><button>コピー</button></td>
</tr>
<tr id="field2">
<th>■文字数(スペース無視)</th>
<td class="value"><span>0</span></td>
<td class="actions"><button>コピー</button></td>
</tr>
<tr id="field3">
<th>■行数</th>
<td class="value"><span>0</span></td>
<td class="actions"><button>コピー</button></td>
</tr>
<tr id="field4">
<th>■段落数</th>
<td class="value"><span>0</span></td>
<td class="actions"><button>コピー</button></td>
</tr>
</table>
<p class="notice">※オリジナルの「文字数カウント」(旧URL: http://www1.odn.ne.jp/megukuma/count.htm)サービスとは無関係です。</p>
<script>
(function () {
const textarea = document.querySelector("#textarea");
const output1 = document.querySelector("#field1 span");
const output2 = document.querySelector("#field2 span");
const output3 = document.querySelector("#field3 span");
const output4 = document.querySelector("#field4 span");
document.querySelector("#action-paste").addEventListener("click", async function (event) {
const value = await navigator.clipboard.readText();
textarea.value = value;
update(textarea);
});
document.querySelector("#action-clear").addEventListener("click", async function (event) {
textarea.value = "";
update(textarea);
});
textarea.addEventListener("input", function (event) {
update(this);
});
for (const button of document.querySelectorAll("#result .actions button")) {
button.addEventListener("click", function (event) {
const value = this.closest("tr").querySelector(".value span").innerText;
navigator.clipboard.writeText(value);
});
}
function update(textarea) {
const text = (textarea.value || "").trim();
output1.innerText = "" + +(text.length);
output2.innerText = "" + +(text.replace(/\s/g, "").length);
output3.innerText = "" + +(text == "" ? 0 : text.split("\n").length);
output4.innerText = "" + +(text == "" ? 0 : text.split(/\n{2,}/).length);
}
update(this);
})();
</script>
</body>
</html>