-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet-count.html
92 lines (85 loc) · 3.43 KB
/
tweet-count.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
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>文字数カウント</title>
<style type="text/css">
strong { color: darkgray; font-weight: bold; font-size: 18pt; }
input.tweet { font-size: 14pt; }
textarea#twitter_draft_counter {
font-size: 14pt;
width: 100%;
height: 5em;
overflow: visible;
}
</style>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//var count = 1;
var hash_text = location.hash.substring(1);
if ( hash_text ) {
$("#twitter_draft_counter").val(decodeURIComponent(hash_text));
}
$("#twitter_draft_counter").keyup(function(){
var tweet = this.value;
if($("#tco_shorten")[0].checked) {
// ティコリンクに短縮されたものとして計算する
tweet = tweet.replace(/\bhttp:\/\/[^ ]+/g, "http://t.co/1234567890");
tweet = tweet.replace(/\bhttps:\/\/[^ ]+/g, "https://t.co/1234567890");
}
if($("#twitpic_append")[0].checked) {
//tweet = tweet + " http://twitpic.com/123456";
tweet = tweet + " http://t.co/1234567890"; // やっぱりティコリンク
}
location.hash = "#" + encodeURIComponent(tweet);
document.title =
"ツイート文字数カウント:" + tweet.substring(0, 20).replace(/\n/g, " ") + (
tweet.length > 20 ? "…" : ""
);
let char = tweet.length;
let bytes = encodeURIComponent(tweet).replace(/%\w\w/g,'?').length;
let info_html = '<strong>'+(140-char)+'</strong> (';
info_html += char+'文字、'+bytes+'バイト)<br />';
info_html += 'Twistory的には残り<strong>'+(255-bytes)+'</strong>バイト、UTF-8文字列にして残り<strong>'+(Math.floor((255-bytes)/3))+'</strong>文字は打てるでしょう。';
$("#twitter_draft_info").html(info_html);
});
$("#twitter_draft_counter").keyup(); /* 一度押しておく */
$("#tco_shorten").click(function(){
$("#twitter_draft_counter").keyup();
});
$("#twitpic_append").click(function(){
$("#twitter_draft_counter").keyup();
});
$("#reset_twitter_draft_counter").click(function(){
if(confirm("内容をリセットしますか?")){
$("#twitter_draft_counter").val("");
$("#twitter_draft_counter").keyup();
}
});
$("#open_twitter_client").click(function(){
var screen_name = $("#screen_name").val(); // or .text() ?
if(!screen_name)screen_name="";
if(confirm("Tweetbotを起動します")){
location.href = "tweetbot://"+screen_name+"/post?text="+encodeURIComponent($("#twitter_draft_counter").val());
}
});
});
</script>
</head>
<body>
<h1>文字数カウント</h1>
<div class="word_count">
<textarea id="twitter_draft_counter"></textarea>
<br />
<label><input type="checkbox" id="tco_shorten" checked="checked">t.coリンクで短縮された場合の文字数を計算</label><br />
<label><input type="checkbox" id="twitpic_append">twitpicのアドレスが一つついた場合の文字数を計算</label><br />
<div id="twitter_draft_info"></div>
<button id="open_twitter_client">Tweetbot for iOSでオープン</button><br />
(<label>screen_name: <input type="text" id="screen_name" value="" /></label>)<br />
<input type="button" id="reset_twitter_draft_counter" value="リセット" />
</div>
</body>
</html>