Thanks Driven Life

日々是感謝

github に登録した&TinyURLしてくれるプラグイン

昨日のやつを github に載せました。

http://github.com/gongo/keysnail_plugin

まあほかにいろいろあるんですが、
しょぼいものばっかなので気にしないでください。


そのままの流れで、「現在開いているページのタイトルと、短縮URLを表示する」プラグインを書いた。

/**
* @fileOverview
* @name make_tinyurl.js
* @description TinyURL (http://tinyurl.com/) client
* @author gongo <gonngo@gmail.com>
* @license The MIT License
*/
 
/**
* Usage
*
* Paste this code to your keysnail.js file.
*
* Press 'C-2' key (or your defined one) to start this client.
*
* When the key is pushed on the site to be shortened,
* the title of the page and shortened URL are displayed with popup.
*/
 
key.setGlobalKey('C-2', function (ev, arg) {
    var title = window.content.document.title;
    var target = encodeURIComponent(window.content.location.href);
    var uri = "http://tinyurl.com/api-create.php?url=";
 
    function createHttpRequest() {
        if (window.ActiveXObject) {
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch(e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e2) {
                    return null;
                }
            }
        } else if (window.XMLHttpRequest) {
            return new XMLHttpRequest;
        } else {
            return null;
        }
    }
 
    var xhr = createHttpRequest();
 
    xhr.onreadystatechange = function (aEvent) {
        if (xhr.readyState == 4) {
            if (xhr.status != 200) {
                alert("I'm sorry, can't make tiny url");
                return;
            }
            var text = xhr.responseText;
            alert(title + " " + text);
        }
    };
 
    xhr.open("GET", uri + target, true);
    xhr.send("");
}, 'MakeTinyURL');

特に目新しいところはねーっす。
難しかったところといえば、英語ですね。おそらくUsageとか意味わからんかも。
いろいろ小物を作って練習していけたらいいと思います。
最終的になにかでっかいのほしいですが、思い浮かぶほど触ってないでこれからね。


alert() でやるのは非常にダサいので、翻訳のやつは
id:mooz さんに教えてもらった display.prettyPrint() や display.notify() をやってみようかと。
今回のやつは、クリップボードに張るぐらいでいいかなー。