Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name count_tweet_words_in_hatena_diary
// @description はてなダイアリーの編集時、twitterへ投稿する欄の文字数を表示
// @namespace http://shiba-yu36.net/
// @include http://d.hatena.ne.jp/*/edit
// ==/UserScript==
(function(){
function xpath(query) {
return document.evaluate(
query,
document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
);
}
function count_words(twitter_notifier) {
twitter_notifier.nextSibling.textContent = twitter_notifier.value.length + '文字';
}
var twitter_notifier = xpath('//*[@id="twitter_notification_prefix"]').snapshotItem(0);
var span = document.createElement('span');
span.style.margin = 5;
span.textContent = '0文字';
twitter_notifier.parentNode.insertBefore(span, twitter_notifier.nextSibling);
twitter_notifier.addEventListener('keyup', function() {
count_words(twitter_notifier);
}, false);
setInterval(function(){
count_words(twitter_notifier);
},3000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.