Skip to content

Commit c328a40

Browse files
committed
Twitter 文字数カウント (tweet-count.html) を追加
1 parent dd5c99d commit c328a40

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

tweet-count.html

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="robots" content="noindex,nofollow" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
6+
7+
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
8+
<title>文字数カウント</title>
9+
<style type="text/css">
10+
strong { color: darkgray; font-weight: bold; font-size: 18pt; }
11+
input.tweet { font-size: 14pt; }
12+
textarea#twitter_draft_counter {
13+
font-size: 14pt;
14+
width: 100%;
15+
height: 5em;
16+
overflow: visible;
17+
}
18+
</style>
19+
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
20+
<script type="text/javascript">
21+
$(document).ready(function(){
22+
//var count = 1;
23+
var hash_text = location.hash.substring(1);
24+
if ( hash_text ) {
25+
$("#twitter_draft_counter").val(decodeURIComponent(hash_text));
26+
}
27+
$("#twitter_draft_counter").keyup(function(){
28+
var tweet = this.value;
29+
if($("#tco_shorten")[0].checked) {
30+
// ティコリンクに短縮されたものとして計算する
31+
tweet = tweet.replace(/\bhttp:\/\/[^ ]+/g, "http://t.co/1234567890");
32+
tweet = tweet.replace(/\bhttps:\/\/[^ ]+/g, "https://t.co/1234567890");
33+
}
34+
if($("#twitpic_append")[0].checked) {
35+
//tweet = tweet + " http://twitpic.com/123456";
36+
tweet = tweet + " http://t.co/1234567890"; // やっぱりティコリンク
37+
}
38+
location.hash = "#" + encodeURIComponent(tweet);
39+
document.title =
40+
"ツイート文字数カウント:" + tweet.substring(0, 20).replace(/\n/g, " ") + (
41+
tweet.length > 20 ? "…" : ""
42+
);
43+
let char = tweet.length;
44+
let bytes = encodeURIComponent(tweet).replace(/%\w\w/g,'?').length;
45+
let info_html = '<strong>'+(140-char)+'</strong> (';
46+
info_html += char+'文字、'+bytes+'バイト)<br />';
47+
info_html += 'Twistory的には残り<strong>'+(255-bytes)+'</strong>バイト、UTF-8文字列にして残り<strong>'+(Math.floor((255-bytes)/3))+'</strong>文字は打てるでしょう。';
48+
$("#twitter_draft_info").html(info_html);
49+
});
50+
$("#twitter_draft_counter").keyup(); /* 一度押しておく */
51+
52+
$("#tco_shorten").click(function(){
53+
$("#twitter_draft_counter").keyup();
54+
});
55+
$("#twitpic_append").click(function(){
56+
$("#twitter_draft_counter").keyup();
57+
});
58+
59+
$("#reset_twitter_draft_counter").click(function(){
60+
if(confirm("内容をリセットしますか?")){
61+
$("#twitter_draft_counter").val("");
62+
$("#twitter_draft_counter").keyup();
63+
}
64+
});
65+
$("#open_twitter_client").click(function(){
66+
var screen_name = $("#screen_name").val(); // or .text() ?
67+
if(!screen_name)screen_name="";
68+
if(confirm("Tweetbotを起動します")){
69+
location.href = "tweetbot://"+screen_name+"/post?text="+encodeURIComponent($("#twitter_draft_counter").val());
70+
}
71+
});
72+
});
73+
</script>
74+
75+
</head>
76+
<body>
77+
78+
<h1>文字数カウント</h1>
79+
80+
<div class="word_count">
81+
<textarea id="twitter_draft_counter"></textarea>
82+
<br />
83+
<label><input type="checkbox" id="tco_shorten" checked="checked">t.coリンクで短縮された場合の文字数を計算</label><br />
84+
<label><input type="checkbox" id="twitpic_append">twitpicのアドレスが一つついた場合の文字数を計算</label><br />
85+
<div id="twitter_draft_info"></div>
86+
<button id="open_twitter_client">Tweetbot for iOSでオープン</button><br />
87+
(<label>screen_name: <input type="text" id="screen_name" value="" /></label>)<br />
88+
<input type="button" id="reset_twitter_draft_counter" value="リセット" />
89+
</div>
90+
91+
</body>
92+
</html>

0 commit comments

Comments
 (0)