twitter_followers_checkerというgreasemonkeyをつくった。

なにこれ?


followされていない相手につぶやいている様子。

これを未然に防ぎたい。


このようにユーザーアイコンにアウトラインを付けることによってフォロアーかどうか一目で確認ができる。

同じ機能のグリモンに『相手に Follow されてるかどうかを表示するグリモン』(今は動かない)がある。これと違うのはAPIを使ってないところ。使用制限の付いたAPIなんてごめんだ。

id:Kiri_Featherさんがつくった Tween には備わっている機能だし、多くのひとは適当なtwitterクライアントを使ってるみたいだけど、自分の為にと深く考えずつくった。

使い方

firefox限定。アドオンのgreasemonkeyをインストールした後、以下のtwitter_followers_checker.user.jsをクリックしてインストールする。

ソースコード

// ==UserScript==
// @name           twitter_followers_checker
// @namespace      http://d.hatena.ne.jp/Cherenkov/
// @include        http*://twitter.com/home*
// @include        http*://twitter.com/friends*
// @include        http*://twitter.com/followers*
// ==/UserScript==

Array.prototype.contains = function(value){
    for(var i in this){
        if( this.hasOwnProperty(i) && this[i].toString() === value.toString()){ //
        return true;
        }
    }
    return false;
}

var myURL = 'http://twitter.com/'+document.getElementById('me_name').textContent;
var thumbURL = document.evaluate("//td[contains(@class,'thumb')]/a", document, null, 7, null);

var URLs = [];
for(var i=0;i<thumbURL.snapshotLength;i++){
    if(!URLs.contains(thumbURL.snapshotItem(i)) && thumbURL.snapshotItem(i).href!=myURL){
        URLs.push(thumbURL.snapshotItem(i));
        }
}

for(var i=0;i<URLs.length;i++){
    (function(i){
        GM_xmlhttpRequest({
            method: 'GET',
            url: URLs[i].href,
            onload: function(res){
                var id = URLs[i].href.replace(/https*\:\/\/twitter\.com\//,'');
                if(/<a href\="\/direct_messages\/create/.test(res.responseText) === false){
                    for(var j=0;j<thumbURL.snapshotLength;j++){
                        if(thumbURL.snapshotItem(j).href===URLs[i].href){
                            thumbURL.snapshotItem(j).firstChild.style.MozOutline = '4px double pink';
                        }
                    }
                    unsafeWindow.console.log('not follower. > '+id);
                }else{
                    unsafeWindow.console.log('follower! > '+id);
                }
            }
        });
    })(i);
}

更新履歴

http://gist.github.com/29842
20081204:twitterの仕様変更(ユーザ名のclassName廃止)があったので書き換えた。
20081205:同じひとの発言が複数あったときに、ひとつだけしかstyle処理してなかったのを直した。for文増えた。とりあえず。

感想

Tweenはどうやって片思い判定をしているんだろう。APIを使ってなくてかっこいい。