Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
つぶやきの平均文字数を表示するGreasemonkey
// ==UserScript==
// @name twitter-average-length
// @namespace http://www.hatena.ne.jp/hitode909
// @include http://twitter.com/*
// @include https://twitter.com/*
// ==/UserScript==
(function() {
var header = document.querySelector('h2.thumb');
if (!header) return;
// length
var average = 0;
var entries = document.querySelectorAll('.entry-content');
Array.forEach(entries, function(entry) {
average += entry.textContent.length;
});
average /= entries.length;
div = document.createElement('div');
div.textContent = '平均' + Math.floor(average * 100) / 100 + '文字';
header.appendChild(div);
// speed
var timestamps = document.querySelectorAll('.timestamp');
var top = eval("(" + timestamps[0].getAttribute("data") + ")");
var bottom = eval("(" + timestamps[timestamps.length - 1].getAttribute("data") + ")");
var per_tweet = (new Date(top.time).getTime() - new Date(bottom.time).getTime()) / timestamps.length / 1000;
var maps = [ {size: 60 * 60 * 24, name: "日"}, {size: 60 * 60, name: "時間"}, {size:60, name: "分"}, {size:1, name: "秒"}];
var map;
for(var i = 0; i < maps.length; i++) with({m: maps[i]}) {
console.log([m, per_tweet]);
if (m.size < per_tweet) {
map = m;
break;
}
}
if (!map) map = maps[maps.length - 1];
div = document.createElement('div');
div.textContent = Math.floor((per_tweet / map.size) * 100) / 100 + map.name + 'に1回投稿';
header.appendChild(div);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment