{"id":2233,"date":"2011-08-02T20:47:19","date_gmt":"2011-08-03T00:47:19","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=2233"},"modified":"2011-08-02T20:47:19","modified_gmt":"2011-08-03T00:47:19","slug":"twitterautolinks-jquery-extension-to-replace-twitter-names-for-links-to-their-respective-pages","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/twitterautolinks-jquery-extension-to-replace-twitter-names-for-links-to-their-respective-pages\/","title":{"rendered":"twitterAutoLinks: jQuery extension to replace twitter @names for links to their respective pages."},"content":{"rendered":"<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/farm7.static.flickr.com\/6022\/5896418528_f8183111dd.jpg?w=640\" \/><\/p>\n<p>Save the following on a .js file, preferably named <strong>jquery.twitterAutoLinks.js<\/strong><br \/>\n[javascript]<br \/>\n\/** Auto replace all Twitter nicknames for links *\/<br \/>\n$.fn.twitterAutoLinks = function() {<br \/>\n  return this.each(function() {<br \/>\n    var html = $(this).html();<br \/>\n    $(this).html(html.replace(\/B@([w-]+)\/gm, &#8216;&lt;a href=&quot;http:\/\/twitter.com\/$1&quot; target=&quot;_blank&quot;&gt;@$1&lt;\/a&gt;&#8217;));<br \/>\n  });<br \/>\n};<br \/>\n[\/javascript]<\/p>\n<p><strong>Usage<\/strong><\/p>\n<p>After importing the jquery.twitterAutoLinks.js file (make sure it&#8217;s after you&#8217;ve imported jquery itself), you&#8217;ll use the extension as follows.<\/p>\n<p>[html]<br \/>\n&lt;script type=&quot;text\/javascript&quot; language=&quot;Javascript&quot;&gt;<\/p>\n<p>    $(document).ready(function() {<br \/>\n      \/\/say you&#8217;re running a wordpress blog and you want to do this for your posts<br \/>\n      $(&quot;div.entry&quot;).twitterAutoLinks();<br \/>\n    });<\/p>\n<p>&lt;\/script&gt;<br \/>\n[\/html] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Save the following on a .js file, preferably named jquery.twitterAutoLinks.js [javascript] \/** Auto replace all Twitter nicknames for links *\/ $.fn.twitterAutoLinks = function() { return this.each(function() { var html = $(this).html(); $(this).html(html.replace(\/B@([w-]+)\/gm, &#8216;&lt;a href=&quot;http:\/\/twitter.com\/$1&quot; target=&quot;_blank&quot;&gt;@$1&lt;\/a&gt;&#8217;)); }); }; [\/javascript] Usage After importing the jquery.twitterAutoLinks.js file (make sure it&#8217;s after you&#8217;ve imported jquery itself), you&#8217;ll use the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4,15],"tags":[],"class_list":["post-2233","post","type-post","status-publish","format-standard","hentry","category-ajax","category-code"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-A1","jetpack-related-posts":[{"id":1051,"url":"https:\/\/www.gubatron.com\/blog\/jquery-tag-wrapping\/","url_meta":{"origin":2233,"position":0},"title":"jQuery tag wrapping","author":"gubatron","date":"December 19, 2008","format":false,"excerpt":"Many times you'll be working on something in HTML that could be long and repetitive, and then for some reason you need to edit the entire thing to wrap each of the tags on some other tags, a common example would be to link many elements. Take this example, there's\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2634,"url":"https:\/\/www.gubatron.com\/blog\/javascript-format-a-number-to-display-thousands-us-style\/","url_meta":{"origin":2233,"position":1},"title":"javascript: Format a number to display thousands US style (#,###,###,###)","author":"gubatron","date":"January 5, 2012","format":false,"excerpt":"[javascript] \/** * Format a number to display thousands like in the US -> 1000000 => 1,000,000 * @param number * @returns *\/ function formatThousands(number) { return Math.max(0, number).toFixed(0).replace(\/(?=(?:d{3})+$)(?!^)\/g, ','); } [\/javascript]","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":308,"url":"https:\/\/www.gubatron.com\/blog\/useful-firefox-extensions\/","url_meta":{"origin":2233,"position":2},"title":"Useful Firefox extensions","author":"gubatron","date":"May 2, 2006","format":false,"excerpt":"Here's a page I've been meaning to do a long time ago, if you're a web developer you might want to bookmark it so that next time you set up Firefox +1.5 you'll have direct links to all the web developer tools you'll ever need. Web Developer Extension (Best extension\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2637,"url":"https:\/\/www.gubatron.com\/blog\/javascript-capitalize-text-like-in-this-title\/","url_meta":{"origin":2233,"position":3},"title":"Javascript: Capitalize Text Like In This Title","author":"gubatron","date":"January 5, 2012","format":false,"excerpt":"On this one, we'll show of the dynamic nature of javascript and we're going to make all strings have a new method called \"capitalize()\". So you can do stuff like this: [javascript] console.log(\"this text should look nicer now\".capitalize()); >> This Text Should Look Nicer Now [\/javascript] Here's the magic code\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1535,"url":"https:\/\/www.gubatron.com\/blog\/javascript-get-how-many-digits-are-there-in-a-decimal-number\/","url_meta":{"origin":2233,"position":4},"title":"JavaScript: Get how many digits are there in a decimal number","author":"gubatron","date":"January 16, 2010","format":false,"excerpt":"\/** * 1 + Floor(LogBase10(number)) * *\/ function digits(n) { return 1+Math.floor(Math.log(n)\/Math.log(10)); } Yes, javascript doesn't have a Math.log10() function. I tried doing it by dividing by Math.ln10 constant but the function won't return the correct number of digits when you pass numbers like 100,1000,10000,etc. So I just divided by\u2026","rel":"","context":"In &quot;Geeklife&quot;","block_context":{"text":"Geeklife","link":"https:\/\/www.gubatron.com\/blog\/category\/geeklife\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3386,"url":"https:\/\/www.gubatron.com\/blog\/how-to-make-a-foreach-function-in-javascript\/","url_meta":{"origin":2233,"position":5},"title":"How to make a &#8220;foreach&#8221; function in JavaScript","author":"gubatron","date":"April 4, 2015","format":false,"excerpt":"I thought this would be a simple exercise in case of having to interview someone for a JavaScript position. \"How would you make your own 'foreach' in JavaScript\" I came up with the following solution: \/\/ \/\/ collection: A list of objects. \/\/ onElementIterationCallback: The function to be called on\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/2233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=2233"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/2233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=2233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=2233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=2233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}