MyMixi Them All

    @@ -20,10 +20,12 @@ console.log('Open URL: ' + url); var d = new Deferred(); iframeEl.onload = function() { - var win = iframeEl.contentWindow; - console.log('Loaded: ' + url); - setTimeout(function() { d.call(win); }, 1); - iframeEl.onload = null; + if (win.location.toString() !== 'about:blank') { + var win = iframeEl.contentWindow; + console.log('Loaded: ' + url); + setTimeout(function() { d.call(win); }, 1); + iframeEl.onload = null; + } }; iframeEl.src = url; @@ -52,10 +54,12 @@ console.log('Fire click: ' + el.tagName); var d = new Deferred(); iframeEl.onload = function() { - var win = iframeEl.contentWindow; - console.log('Loaded: ' + win.location); - setTimeout(function() { d.call(win); }, 1); - iframeEl.onload = null; + if (win.location.toString() !== 'about:blank') { + var win = iframeEl.contentWindow; + console.log('Loaded: ' + win.location); + setTimeout(function() { d.call(win); }, 1); + iframeEl.onload = null; + } }; jQuery(el).simulate('click'); return d; @@ -74,11 +78,11 @@ return clickAndWait(btnEls[0]). next(function(win) { jQuery(win.document.getElementsByClassName('formBt01')[0]).simulate('click'); - return wait(20); + return wait(100); }); } else { - return wait(20); + return wait(100); } }); });
  • /*
     * @title MyMixi Them All
     * @description まだ作ってる中
     * @include http://mixi.jp/
     * @license MIT License
     * @require JSDeferred
     * @require jquery
     * @require http://jquery-ui.googlecode.com/svn/trunk/tests/jquery.simulate.js
     */
    
    Deferred = D();
    
    Deferred.iframeId_ = 0;
    
    Deferred.iframe = function iframe(url) {
        var iframeName = 'name-' + Deferred.iframeId_++;
        var iframeEl = document.createElement('iframe');
        iframeEl.name = iframeName;
        document.body.insertBefore(iframeEl, document.body.firstChild);
        console.log('Open URL: ' + url);
        var d = new Deferred();
        iframeEl.onload = function() {
            if (win.location.toString() !== 'about:blank') {
                var win = iframeEl.contentWindow;
                console.log('Loaded: ' + url);
                setTimeout(function() { d.call(win); }, 1);
                iframeEl.onload = null;
            }
        };
        iframeEl.src = url;
    
        return d;
    };
    
    Deferred.xpath = function xpath(expr, ctx, callback) {
        var doc = ctx.nodeType === 9 ? ctx : ctx.ownerDocument;
        var r = doc.evaluate(expr, ctx, null, 7, null);
        return Deferred.loop(r.snapshotLength, function (i) {
    	return callback(r.snapshotItem(i), r, i, expr);
        });
    };
    
    Deferred.clickAndWait = function clickAndWait(el) {
        var iframeName = 'name-' + Deferred.iframeId_++;
        var iframeEl = document.createElement('iframe');
        iframeEl.name = iframeName;
        document.body.insertBefore(iframeEl, document.body.firstChild);
        if (el.tagName === 'A') {
            el.target = iframeName;
        }
        else if (el.form) {
            el.form.target = iframeName;
        }
        console.log('Fire click: ' + el.tagName);
        var d = new Deferred();
        iframeEl.onload = function() {
            if (win.location.toString() !== 'about:blank') {
                var win = iframeEl.contentWindow;
                console.log('Loaded: ' + win.location);
                setTimeout(function() { d.call(win); }, 1);
                iframeEl.onload = null;
            }
        };
        jQuery(el).simulate('click');
        return d;
    };
    
    with(Deferred) {
        xpath('//a[contains(@href, "show_friend.pl")]', document, function(el) {
            return iframe(el.href).
            next(function(win) {
                return xpath('//a[contains(@href, "add_friend.pl")]', win.document, function(el) {
                    return clickAndWait(el).
                    next(function(win) {
                        win.document.getElementById('message').value = 'よろしくおねがいします!';
                        var btnEls = win.document.getElementsByClassName('formBt01');
                        if (btnEls.length) {
                            return clickAndWait(btnEls[0]).
                            next(function(win) {
                                jQuery(win.document.getElementsByClassName('formBt01')[0]).simulate('click');
                                return wait(100);
                            });
                        }
                        else {
                            return wait(100);
                        }
                    });
                });
            });
        }).
        next(function() {
            alert('finish!');
        }).
        error(function(e) {
            alert('Error: ' + e.message + '\nStack: ' + e.stack)
            console.log(e.message, e.stack)
        });
    }
    void(0);
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2010/05/18 00:29:06 - 2010-05-18
  2. 2010/05/18 00:27:59 - 2010-05-18
  3. 2010/05/18 00:26:41 - 2010-05-18
  4. 2010/05/18 00:24:47 - 2010-05-18
  5. 2010/05/18 00:18:25 - 2010-05-18
  6. 2010/05/18 00:15:30 - 2010-05-18
  7. 2010/05/18 00:11:02 - 2010-05-18
  8. 2010/05/18 00:09:22 - 2010-05-18
  9. 2010/05/18 00:08:46 - 2010-05-18
  10. 2010/05/18 00:01:42 - 2010-05-18
  11. 2010/05/18 00:01:01 - 2010-05-18
  12. 2010/05/17 23:58:49 - 2010-05-17
  13. 2010/05/17 23:58:04 - 2010-05-17
  14. 2010/05/17 23:54:14 - 2010-05-17
  15. 2010/05/17 23:53:48 - 2010-05-17
  16. 2010/05/17 23:53:11 - 2010-05-17
  17. 2010/05/17 23:52:17 - 2010-05-17
  18. 2010/05/17 23:44:50 - 2010-05-17
  19. 2010/05/17 23:40:05 - 2010-05-17
  20. 2010/05/17 23:34:22 - 2010-05-17
  21. 2010/05/17 23:31:56 - 2010-05-17
  22. 2010/05/17 23:28:54 - 2010-05-17
  23. 2010/05/17 23:26:27 - 2010-05-17
  24. 2010/05/17 23:22:41 - 2010-05-17
  25. 2010/05/17 23:19:04 - 2010-05-17
  26. 2010/05/17 23:18:00 - 2010-05-17
  27. 2010/05/17 23:17:01 - 2010-05-17
  28. 2010/05/17 23:15:44 - 2010-05-17
  29. 2010/05/17 23:15:04 - 2010-05-17
  30. 2010/05/17 23:12:51 - 2010-05-17
  31. 2010/05/17 23:08:43 - 2010-05-17
  32. 2010/05/17 22:19:34 - 2010-05-17
  33. 2010/05/17 22:18:20 - 2010-05-17
  34. 2010/05/17 22:17:21 - 2010-05-17
  35. 2010/05/17 22:16:26 - 2010-05-17
  36. 2010/05/17 22:13:29 - 2010-05-17