Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:08:31+00:00 2026-05-23T23:08:31+00:00

I’m trying to convert a pretty simple script that takes search results from Twitter

  • 0

I’m trying to convert a pretty simple script that takes search results from Twitter and outputs it into an unordered list. This is my first time trying to write a plugin and it doesn’t seem to be firing all the code when I call it. Script by iteself works fine, this is the code I’ve written for the plugin:

(function($) {

    $.fn.tweetGet = function(options) {

        var defaults = {

            query: 'from:twitter&rpp=10',
            url: 'http://search.twitter.com/search.json?callback=?&q='
        };

        var options = $.extend(defaults, options);

        return this.each(function() {

            // Get tweets from user query
            $.getJSON(options.url + options.query, function(data) {

                var tweets = [];

                $.each(data.results, function(i, tweet) {

                    tweets.push('<li>' + tweet.text.parseURL().parseUsername().parseHashtag() + '</li>');
                });

                $('#target').append('<ul>' + tweets.join('') + '</ul>');
            });

            // Parse tweets for URLs and convert to links
            String.prototype.parseURL = function() {
                return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
                    return url.link(url);
                });
            };

            // Parse tweets for twitter usernames and convert to links
            String.prototype.parseUsername = function() {
                return this.replace(/(?:^|\s)@[a-zA-Z0-9_.-]+\b/, function(user) {
                    var username = user.replace("@","")
                    return user.link("http://twitter.com/"+username);
                });
            };

            // Parse tweets for hashtags and convert to links
            String.prototype.parseHashtag = function() {
                return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(hash) {
                    var hashtag = hash.replace("#","%23")
                    return hash.link("http://search.twitter.com/search?q="+hashtag);
                });
            };
        });
    };
})(jQuery);

The function is being called with:

$('#target').tweetGet({query: 'from:twitter&rpp:10'});

Everything outside of return this.each(function() {}; is working fine, but nothing placed within is firing or giving me any errors. All the tutorials I’ve read seem to use this same basic format but I can’t seem to figure out what I’m doing wrong…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:08:32+00:00Added an answer on May 23, 2026 at 11:08 pm

    Here is a working version: http://jsfiddle.net/JAAulde/QK35D/3/

    ( function( global )
    {
        var String, $;
    
        if( global.jQuery )
        {
            String = global.String;
            $ = window.jQuery;
    
            String.prototype = $.extend( String.prototype, {
                // Parse tweets for URLs and convert to links
                parseURL: function()
                {
                    return this.replace( /[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function( url )
                    {
                        return url.link( url );
                    } );
                },
                // Parse tweets for twitter usernames and convert to links
                parseUsername: function()
                {
                    return this.replace( /@[a-zA-Z0-9_.-]+\b/g, function( user )
                    {
                        return user.link( 'http://twitter.com/' + user.replace( '@', '' ) );
                    } );
                },
                // Parse tweets for hashtags and convert to links
                parseHashtag: function()
                {
                    return this.replace( /[#]+[A-Za-z0-9-_]+/g, function( hash )
                    {
                        return hash.link( 'http://search.twitter.com/search?q=' + hash.replace( '#', '%23' ) );
                    } );
                }
            } );
    
            $.fn.tweetGet = function( options )
            {
                var defaults = {
                    query: 'from:twitter&rpp=10',
                    url: 'http://search.twitter.com/search.json?callback=?&q='
                };
    
                options = $.extend( defaults, options );
    
                return this.each( function()
                {
                    var target = this;
                    // Get tweets from user query
                    $.getJSON( options.url + options.query, function( data )
                    {
                        var tweets = [];
    
                        $.each( data.results, function( i, tweet )
                        {
                            tweets.push( '<li>' + tweet.text.parseURL().parseUsername().parseHashtag() + '</li>' );
                        } );
    
                        $( target ).append( '<ul>' + tweets.join('') + '</ul>' );
                    } );
                } );
            };
        }
    }( window ) );
    

    Watch this answer for updates as I explain my modifications.

    Edits:

    1. removed all modifications of the string prototype out of the plugin–they should not be there as they are not part of the plugin code, and they would be redefined on every call to the plugin.
    2. removed the #target selector from within the plugin as it specifically targeted an element rather than using the collection against which the plugin had been called (adjusted for scope due to getJSON callback).
    3. removed the var declaration from in front of options = $.extend( defaults, options ); as it was unneeded and there was risk of wiping what had been passed into the plugin on execution.
    4. as an aside, fixed your parseUsername function to stop adding a space in front of usernames in the username URLs
    5. used my preferred syntax for localizing code
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.