Twitterで背景画像を表示するぐりもん

Twitterで遊んでいると、「背景画像が気になるーーー!!!」っていうページに出会うことがよくあります。そんなとき、ワンタッチで見れたらいいなーっと思って作りました。


↑これが

↑こうなります。

使ってみた様子

残念ながら元には戻すことはできません。F5押してください。

.user.js を上げられるうpろだが見つかりませんでした。残念。下のコードをaaa.user.jsって名前でどこかに保存して、FireFoxにドラッグしてください。欲を言うと誰かコードレビューして下さい。

// Hello World! example user script
// version 0.1 BETA!
// 2005-04-22
// Copyright (c) 2005, Mark Pilgrim
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Hello World", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Twitter背景表示ぐりもん
// @namespace http://d.hatena.ne.jp/drgqst/
// @description Twitterのページで背景を表示する。
// @include http://twitter.com/*
// ==/UserScript==
(function(){
    const ELEMENT_NODE = 1;
    
    // 「body」要素を取得。
    var body = document.body;
    if( body == undefined )
    {
        return;
    }
    
    var nodes = document.body.childNodes;
    var firstElement = null;
    for( var i=0; i<nodes.length; i++ )
    {
        if( nodes[i].nodeType == ELEMENT_NODE )
        {
            firstElement = nodes[i];
            break;
        }
    }
    
    if( firstElement == undefined )
    {
        alert( 'firstElement is undefined' );
        return;
    }
    
    // リンクを作成
    var link = document.createElement( 'a' );
    link.innerHTML = '背景を表示';
    link.href = 'javascript:void(0);';
    link.addEventListener( "click", invisible, false );
    
    // リンクを配置
    var div = document.createElement( 'div' );
    div.style.textAlign = 'right';
    div.appendChild( link );
    body.insertBefore( div, firstElement );
    
    
    function invisible ()
    {
        var nodes = document.body.childNodes;
        for( var i=0; i<nodes.length; i++ )
        {
            if( nodes[i].nodeType == ELEMENT_NODE )
            {
                nodes[i].style.visibility = 'hidden';
            }
        }
    }
})();

気が付いたら4時じゃないか。明日起きられるかな。

追記

よく考えたら、Firefoxには右クリックメニューに「背景画像を表示」ってのがあるなぁー。そっちを使ったほうがいいなぁー。プヒー。