Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created July 4, 2009 13:15
Show Gist options
  • Save hitode909/140576 to your computer and use it in GitHub Desktop.
Save hitode909/140576 to your computer and use it in GitHub Desktop.
Twitterのタイムラインにふぁぼられ具合を表示するGreasemonkey
// ==UserScript==
// @name favlevel
// @namespace http://www.hatena.ne.jp/hitode909/
// @description show favotter level
// @include http://twitter.com/*
// @include https://twitter.com/*
// @require http://code.jquery.com/jquery-1.3.2.min.js
// ==/UserScript==
(function() {
var BEGINNER_MODE = eval(GM_getValue("BEGINNER_MODE"));
if (!BEGINNER_MODE) {
BEGINNER_MODE = false;
}
GM_registerMenuCommand(
'favlevel - toggle beginner mode',
function () {
BEGINNER_MODE = !BEGINNER_MODE;
GM_setValue("BEGINNER_MODE", uneval(BEGINNER_MODE));
alert("Beginner Mode: " + BEGINNER_MODE + " (" + BEGINNER_LEVEL + "favs)");
// 計算しなおし
$("a.favotter_link").remove();
}
);
var BEGINNER_LEVEL = eval(GM_getValue("BEGINNER_LEVEL"));
if (typeof BEGINNER_LEVEL == 'undefined') {
BEGINNER_LEVEL = 1000;
}
GM_registerMenuCommand(
'favlevel - toggle set beginner level',
function () {
var st = prompt("Your favs in begginer mode", BEGINNER_LEVEL);
var level = parseInt(st);
if (!isNaN(level) && level >= 0) {
BEGINNER_LEVEL = level;
GM_setValue("BEGINNER_LEVEL", uneval(BEGINNER_LEVEL));
}
alert("Beginner Mode: " + BEGINNER_MODE + " (" + BEGINNER_LEVEL + "favs)");
if (BEGINNER_MODE) {
$("a.favotter_link").remove();
}
}
);
var getLoginUser = function() {
var url = $("div.user_icon > a.url");
if (url.length > 0) {
url = url[0].href.split('/');
url = url[url.length - 1];
login_user = url;
GM_setValue("login_user", login_user);
} else {
login_user = GM_getValue("login_user");
}
};
var getUsers = function() {
users = eval(GM_getValue("users"));
if (!users) {
users = {};
}
var now = Date.now();
for (var i in users) if (users.hasOwnProperty(i)) {
if (typeof(users[i]) == 'undefined' || users[i].due < now) {
delete(users[i]);
}
}
};
var saveUsers = function() {
GM_setValue("users", uneval(users));
};
var getFav = function(name) {
if (typeof users[name] == 'undefined') {
users[name] = {level: null, try: 0, due: Date.now() + 3600*1000};
GM_xmlhttpRequest({
method: "GET",
url: favotterUrlFor(name),
onload: function(response) {
try {
var title = $('title', $('<root>' + response.responseText + '</root>')).text();
var level = title.match(/\((\d+)\)/)[1];
var user = response.finalUrl.split('/').reverse()[0];
users[user].level = parseInt(level);
saveUsers();
} catch(e) {
console.log(e);
}
}
});
}
users[name].try++;
return users[name];
};
var favotterUrlFor = function(name) {
return 'http://favotter.net/user/' + name;
};
var appendFavLevel = function(target) {
if ($("a.favotter_link", target).length > 0) return;
var target_name;
if (location.href == 'http://twitter.com/') {
target_name = $($('a.screen-name',target)[0]).text();
} else {
target_name = location.href.split('/').reverse()[0];
}
target_name = target_name.replace(/\s/g, '');
var fav = getFav(target_name);
if (fav.level != null) {
fav.try = 0;
var anchor = document.createElement('a');
anchor.className = 'favotter_link';
anchor.setAttribute('href', favotterUrlFor(target_name));
anchor.appendChild(document.createTextNode(fav.level + 'favs'));
$($('span.entry-meta',target)[0]).append(anchor);
// 自分のレベルが分かってるとき関係を出す
if (BEGINNER_MODE || login_user && users[login_user].level) {
var login_user_level = BEGINNER_MODE ? BEGINNER_LEVEL : users[login_user].level;
var param = {"line-height": 1};
size = Math.sqrt(fav.level / login_user_level);
if (size > 4) {
param.color = "#FF0000";
} else if (size > 3) {
param.color = "#660099";
} else if (size > 2) {
param.color = "#009900";
} else if (size < 0.5) {
param.color = "#999999";
} else if (size < 0.7) {
param.color = "#4C4C4C";
}
if (size > 7) {
size = 7;
}
if (size < 0.7) {
size = 0.7;
}
param["font-size"] = size+"em";
$("span.entry-content, a.screen-name", target).css(param);
}
} else if (fav.try > 10) {
users[target_name].level = 0;
saveUsers();
appendFavLevel(target);
}
};
getUsers();
getLoginUser();
if (login_user) {
getFav(login_user);
}
var append = function() {
$('li.status').each(
function(){
var that=this;
setTimeout(function(){appendFavLevel(that);}, 0);
}
);
};
append(document);
setInterval(append, 1000);
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment