用于主持实时推文的Twitter小部件

时间:2012-05-13 09:33:29

标签: javascript jquery twitter

我正在寻找一个小部件/ jquery插件/托管服务或类似的,你可以放到一个html页面,它将显示和更新包含特定主题标签的推文,但只来自一个或多个可配置的帐户+审核以相同的标签批准其他人的推文。

想想要发布活动的报纸,但要控制其他人在页面上显示的内容。

我已经搜索过,但找不到合适的东西 - 我相信它一定存在。

1 个答案:

答案 0 :(得分:1)

Hiya 演示 http://jsfiddle.net/RGrgM/ http://jsfiddle.net/RGrgM/show/

我已将某人(我的)推文与此演示相关联但你可以链接你的:)我在Twitter上懒得anyhooo:P这会对你有帮助。它适用于实时Feed。

休息一切都在那里,您可以右键单击并查看源代码以及下面的代码。乙 - )

这[链接]可能会派上用场:http://boxmodeljunkie.com/create-a-simple-twitter-widget-with-yui-3-and-yql/

:)

D'uh不要忘记接受并投票自己!

它使用:

  <title>Twitter Feed Widget with YUI 3 &amp; YQL - jsFiddle demo</title>

  <script type='text/javascript' src='/js/lib/yui-min-3.2.0.js'></script>

Jquery代码

// top-level global namespace
YUI.namespace('CIF');

// accepts a tweet timestamp and produces relational time text
YUI.CIF.relativeTime = function ( c ) {

    var origStamp = Date.parse( c ),

        curDate = new Date(),

        currentStamp = curDate.getTime(),

        difference = parseInt( ( currentStamp - origStamp ) / 1000, 10 ),

        dateArr = c.toString().split(' ');

    // if no difference, do nothing
    if ( difference < 0 ) {
        return false;
    }

    if ( difference <= 5 ) {
        return "Just now";
    }

    if ( difference <= 20 ) {
        return "Seconds ago";
    }

    if ( difference <= 60 ) {
        return "A minute ago";
    }

    if ( difference < 3600 ) {
        return parseInt( difference / 60, 10 ) + ' minutes ago';
    }

    if (difference <= 1.5 * 3600) {
        return "One hour ago";
    }

    if ( difference < 23.5 * 3600 ) {
        return Math.round( difference / 3600 ) + ' hours ago';
    }

    if (difference < 1.5*24*3600) {
        return "One day ago";
    }

    // produce date stamp for tweets older than a day
    return dateArr[3].replace( /\:\d+$/,'' ) + ' ' + dateArr[2] + ' ' + dateArr[1] + dateArr[5] !== curDate.getFullYear().toString() ? ' ' + dateArr[5] : '';

};

// load required modules and set up YUI instance
YUI().use( 'node', 'substitute', 'yql', function ( Y ) {

    var n = Y.one( '#twitterFeed' ),

        // accepts a YQL JSON result object and produces a list of 
        // tweets using Y.substitute for templating
        formatTwitterFeed = function ( r ) {

            if (r) {

                var s = r.query.results.statuses.status,

                    // HTML markup template
                    t = '<li><span class="status-text">{sText}</span> <span ' + 
                        'class="quiet status-time">{sTime}</span></li>',

                    l = s.length,

                    f = '<ul>',

                    i;

                for ( i = 0; i < l; i++ ) {

                    // Y.substitute method to merge HTML markup and result object
                    f += Y.substitute( t, {

                        // convert usernames, hash tags and URLs to links
                        sText : s[i].text
                            .replace(/(http\S+)/i,'<a href="$1" target="_blank">$1</a>')
                            .replace(/(@)([a-z0-9_\-]+)/i,
                                '<a href="http://twitter.com/$2" target="_blank">$1$2</a>')
                            .replace(/(#)(\S+)/ig, 
                                '<a href="http://search.twitter.com/search' + 
                                '?q=%23$2" target="_blank">$1$2</a>'),

                        sTime : YUI.CIF.relativeTime( s[i].created_at )

                    } );

                }

                f += '</ul>';

                f += '<a class="button" href="http://twitter.com/tats_innit" title="Follow @Tats_innit on Twitter" target="_blank">Follow on Twitter&nbsp;&raquo;</a>';

                // append output to target parent node
                n.append( f );

            }

        };

    // YQL Twitter query limited to five results for a specified username
    Y.YQL( 'select * from twitter.user.timeline( 5 ) ' + 
            'where screen_name="@tats_innit"', formatTwitterFeed );

});
​