-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfollow_cost.user.js
76 lines (69 loc) · 2.08 KB
/
follow_cost.user.js
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
// ==UserScript==
// @name Follow Cost for Twitter profiles
// @author Barry Hess
// @namespace http://followcost.com
// @description Display a user's Follow Cost right in his/her Twitter profile
// @include http://twitter.com/*
// ==/UserScript==
function noFollowCostDefinedBeneath(element) {
return 0 == element.find('.follow-cost').length
}
function findUsername(profileElement) {
username = false;
if(0 == profileElement.find('.screen-name strong').length) {
// Grab from the URL
var m=/^http[s]{0,1}:\/\/twitter.com\/(\w+)|(\#!\/(\w+))\/?/.exec(window.location.href);
if(m) {
username = (undefined == m[1] ? m[3] : m[1]);
}
} else {
username = profileElement.find('.screen-name strong').html().replace(/^@/, '');
}
return username;
}
function updateFollowCost() {
$('.profile-basics, .profile-dashboard').each(function() {
if(noFollowCostDefinedBeneath($(this))) {
var username = findUsername($(this));
if(username) {
var ul = $(this).find('.user-stats');
$.getJSON("http://followcost.com/" + username + ".json?callback=?", function(json) {
var markup = '<li><a class="user-stats-count follow-cost" href="http://followcost.com/' + username + '">' + Math.round(parseFloat(json.average_tweets_per_day)*100)/100 + '<span class="user-stats-stat">Follow Cost</span></a></li>';
if(noFollowCostDefinedBeneath(ul)) {
ul.html(ul.html() + markup);
}
});
}
}
});
}
function updateFollowCostAfterInterval() {
var executions = 0;
intervalId = window.setInterval(function() {
updateFollowCost();
if(executions >= 300) {
window.clearInterval(intervalId);
}
executions++;
}, 2000);
}
function GM_wait()
{
if(typeof unsafeWindow.jQuery == 'undefined')
{
window.setTimeout(GM_wait,251);
}
else
{
$ = unsafeWindow.jQuery; letsJQuery();
}
}
function letsJQuery()
{
updateFollowCostAfterInterval();
}
if(navigator.appVersion.match('AppleWebKit')) {
updateFollowCostAfterInterval();
} else {
GM_wait();
}