/*** BEGIN LICENSE BLOCK {{{ Copyright (c) 2008 suVene distributable under the terms of an MIT-style license. http://www.opensource.jp/licenses/mit-license.html }}} END LICENSE BLOCK ***/ // PLUGIN_INFO//{{{ var PLUGIN_INFO = {NAME} Wassr change notice. Wassr変更通知。 suVene 0.1.1 MIT 2.0pre 2.0pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/notifier/subject_wassr.js ; //}}} (function() { var notifier = liberator.plugins.notifier; if (!notifier) return; var libly = notifier.libly; var $U = libly.$U; var logger = $U.getLogger('subject_wassr'); var URL = 'http://api.wassr.jp/statuses/friends_timeline.json?id='; notifier.subject.register(notifier.SubjectHttp, { interval: 60, options: { url: '', headers: null, extra: {} }, preInitialize: function() { var [username, password] = $U.getUserAndPassword('http://wassr.jp', 'http://wassr.jp'); this.options.url = URL + username; this.options.extra.username = username; this.options.extra.password = password; return (username && password) ? true : false; }, parse: function(res) { // if (this.count == 0) return []; // for debug return $U.evalJson(res.responseText) || []; }, diff: function(cache, parsed) parsed.filter(function(item) !cache.some(function(c) c.html == item.html)), buildMessages: function(diff) diff.map($U.bind(this, function(d) new notifier.Message('Wassr',
{d.reply_status_url ?

{'> ' + d.reply_message + ' by ' + d.reply_user_nick}

: ''}

{d.user_login_id} {d.photo_thumbnail_url ? : ''} {d.html || ''}

.toString(), d.link))) }); })(); // vim: set fdm=marker sw=4 ts=4 sts=0 et: /diff/twitterView.js?h=stella/nico-fullscreen&id=aea3eada705da3995d1ba05b473c8b73b4c15e93'>diffstats
path: root/twitterView.js
blob: d532d75a0784ce7db790bebbfeb89355e17be168 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Vimperator plugin: 'Statusbar Twitter'
// Last Change: 02-Dec-2008
// License: Creative Commons
// Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid
//
// show Twitter on statusesbar script for Vimperator 2.0pre

(function(){
    const checkTime = 90 * 1000;
    const updateTime = 10 * 1000;

    var lastestStatus;

    var statuses = [];
    liberator.plugins.statuses = statuses;

    var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
    var password; var username;
    try{
        var logins = passwordManager.findLogins({},'http://twitter.com','https://twitter.com',null);
        if(logins.length)
            [username,password] = [logins[0].username,logins[0].password];
        else
            liberator.echoerr("Twitter: account not found");
    }
    catch(ex){
    }

    var hbox = document.createElement('hbox');
    var iconPanel = document.createElement('image');
    var statusPanel = document.createElement('label');

    var commandline = document.getElementById('liberator-commandline');

    iconPanel.setAttribute('id','statusbar-twitter-timeline-icon');
    iconPanel.style.width = "16px";
    iconPanel.style.height = "16px";

    statusPanel.setAttribute('id','statusbar-twitter-timeline-status');
    statusPanel.setAttribute('class','plain');

    hbox.appendChild(iconPanel);
    hbox.appendChild(statusPanel);

    hbox.setAttribute('id','statusbar-twitter-timeline');

    commandline.style.overflow = "hidden";
    commandline.insertBefore(hbox,document.getElementById('liberator-commandline-command'));

    document.getElementById('liberator-commandline-command').style.textAlign = "right";
    document.getElementById('liberator-commandline-command').addEventListener("focus",function(e){
        hbox.hidden = true;
        document.getElementById('liberator-commandline-command').style.textAlign = "left";
    },true);
    document.getElementById('liberator-commandline-command').addEventListener("blur",function(e){
        hbox.hidden = false;
        document.getElementById('liberator-commandline-command').style.textAlign = "right";
    },true);

    checkTimeline();
    updateTimeline();
    setInterval(function() checkTimeline(Date.now() - checkTime - 3),checkTime);
    setInterval(updateTimeline,updateTime);

    function favoriteStatus(id){
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status != 200)
                liberator.echoerr("Twitter Viewer: faild to favorite");
        };
        xhr.open("GET","http://twitter.com/favourings/create/" + id,true,username,password);
        xhr.send(null);
    }
    function checkTimeline(since){
        var req = "http://twitter.com/statuses/friends_timeline.json";
        if(typeof since == "number") since = new Date(since);
        if(since){
          req += "?since=" + encodeURIComponent(since.toUTCString());
        }
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function(){
            if(xhr.readyState != 4) return;
            if(xhr.status != 200){
                liberator.echoerr("Twitter Viewer: failed");
            }
            var response = window.eval(xhr.responseText);
            liberator.plugins.statuses = statuses =
                statuses.concat(response.filter(function(r)
                    !statuses.some(function(status)
                        status.id == r.id)));
        };
        //xhr.setRequestHeader("X-Twitter-Client","Vimperator");
        //xhr.setRequestHeader("X-Twitter-Client-Version","");
        //xhr.setRequestHeader("X-Twitter-Client-URL","");
        //xhr.setRequestHeader("If-Modified-Since","");
        xhr.open("GET",req,true,username,password);
        xhr.send(null);
    }
    function updateTimeline(){
        if(statuses.length > 0 && !hbox.hidden){
            lastestStatus = statuses.shift();
            statusPanel.value = lastestStatus.user.screen_name + " : " + lastestStatus.text;
            statusPanel.setAttribute('tooltiptext',lastestStatus.user.screen_name + " : " + lastestStatus.text);
            iconPanel.setAttribute('src',lastestStatus.user.profile_image_url);
            iconPanel.setAttribute('tooltiptext',lastestStatus.user.screen_name);
        }
    }

    liberator.modules.mappings.add([liberator.modules.modes.NORMAL],[",r"],
        "Reply to current user",
        function (){ liberator.modules.commandline.open(":","twitter @" + lastestStatus.user.screen_name + " ",liberator.modules.modes.EX); });
    liberator.modules.mappings.add([liberator.modules.modes.NORMAL],[",f"],
        "Favorite to current user",
        function (){ favoriteStatus(lastestStatus.id); });
})();
// vim: fdm=marker sw=4 ts=4 et: