<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Troll-Range &#187; Javascript</title>
	<atom:link href="http://blog.trollgod.org.uk/category/development/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trollgod.org.uk</link>
	<description>Ghworg&#039;s wibblings and geek projects.</description>
	<lastBuildDate>Mon, 26 Apr 2010 19:31:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>OAuthcalypse</title>
		<link>http://blog.trollgod.org.uk/2010/04/oauthcalypse/</link>
		<comments>http://blog.trollgod.org.uk/2010/04/oauthcalypse/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 19:31:11 +0000</pubDate>
		<dc:creator>Ghworg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://blog.trollgod.org.uk/?p=396</guid>
		<description><![CDATA[<p>So, I have a twitter/status.net app that I use to consolidate all the micro-blogs I&#8217;m on and produce a single timeline in a sidebar of my news page. It was originally written as a python plugin for pyblosxom, which runs the rest of the site. It turns out that this causes huge delays in <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.trollgod.org.uk/2010/04/oauthcalypse/">OAuthcalypse</a></span>]]></description>
			<content:encoded><![CDATA[<p>So, I have a twitter/status.net <a href="http://blog.trollgod.org.uk/projects/twixm/">app</a> that I use to consolidate all the micro-blogs I&#8217;m on and produce a single timeline in a sidebar of my news page.  It was originally written as a python plugin for <a href="http://pyblosxom.bluesock.org/">pyblosxom</a>, which runs the rest of the site.  It turns out that this causes huge delays in producing the page though and I eventually rewrote it in javascript.</p>
<p>This is really nice because it all runs client-side and can take its sweet time to pull in the feeds without affecting the rendering of the bulk of the page.  It grabs the friend feeds so it needs to login to the various sites, and it uses http basic auth for this.  Nice and simple.</p>
<p>I&#8217;ve just learned of the coming <a href="http://countdowntooauth.com/">OAuthcalypse</a> though, where the basic auth method is going to be disabled, and this presents me with a quandary.  I need to update my app to use OAuth, there are three ways I could do this:</p>
<p><strong>1) Implement OAuth in javascript.</strong>  This is a really bad idea.  OAuth uses a secret key, and as javascript has to be sent to the browser in plain text it wouldn&#8217;t remain secret for long.</p>
<p><strong>2) Move the app back server side and implement OAuth in python.</strong>  Again this is a bad idea, I moved it client side for a <em>reason</em>, and putting it back server side would give me unacceptable performance.</p>
<p><strong>3) A hybrid approach where the OAuth is done server side, and the requests themselves remain javascript on the client.</strong>  Having had a brief look at how OAuth works I <em>think</em> this might be possible.  It will still slow things down, but it might be good enough.  It&#8217;s going to be a pain in the arse to implement though.</p>
<p>Well, at least I know what I&#8217;m doing with my Bank Holiday.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trollgod.org.uk/2010/04/oauthcalypse/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multiconica update</title>
		<link>http://blog.trollgod.org.uk/2009/03/multiconica-update/</link>
		<comments>http://blog.trollgod.org.uk/2009/03/multiconica-update/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 05:14:16 +0000</pubDate>
		<dc:creator>Ghworg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[laconica]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.trollgod.org.uk/?p=96</guid>
		<description><![CDATA[<p>I&#8217;ve fixed a small bug in my twitter/laconica combining script. HTML tags in tweets were being interpreted by the browser because I wasn&#8217;t escaping the &#60; and &#62; characters. That should be fixed now.</p> <p>In addition I&#8217;ve decided to give the script a better name, from now on it will be Multiconica.</p> <p>Download <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.trollgod.org.uk/2009/03/multiconica-update/">Multiconica update</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve fixed a small bug in my twitter/laconica combining script.  HTML tags in tweets were being interpreted by the browser because I wasn&#8217;t escaping the &lt; and &gt; characters.  That should be fixed now.</p>
<p>In addition I&#8217;ve decided to give the script a better name, from now on it will be Multiconica.</p>
<p><a href='http://blog.trollgod.org.uk/wp-content/uploads/2009/03/multiconica.js'>Download Multiconica</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trollgod.org.uk/2009/03/multiconica-update/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Twitter and Laconica combined</title>
		<link>http://blog.trollgod.org.uk/2009/02/twitter-and-laconica-combined/</link>
		<comments>http://blog.trollgod.org.uk/2009/02/twitter-and-laconica-combined/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 20:34:41 +0000</pubDate>
		<dc:creator>Ghworg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[laconica]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.trollgod.org.uk/?p=83</guid>
		<description><![CDATA[<p>I&#8217;ve written my first bit of javascript code. It&#8217;s designed to combine multiple twitter and laconica feeds into a single stream.</p> <p>It uses jquery, so you&#8217;ll need to include that as well as this code. Then add a div with an id of &#8220;microblog&#8221;, which will get filled up with the tweets. The tweets <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.trollgod.org.uk/2009/02/twitter-and-laconica-combined/">Twitter and Laconica combined</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written my first bit of javascript code.  It&#8217;s designed to combine multiple <a href="http://www.twitter.com/">twitter</a> and <a href="http://laconi.ca/">laconica</a> feeds into a single stream.</p>
<p>It uses <a href="http://jquery.com/">jquery</a>, so you&#8217;ll need to include that as well as this code.  Then add a div with an id of &#8220;microblog&#8221;, which will get filled up with the tweets.  The tweets are set to use the css class &#8220;tweet&#8221; so you can style them as you wish very easily.</p>
<p>It is currently set to read from <a href="http://www.twitter.com/">twitter</a> and <a href="http://identi.ca/">identica</a>, but any number of sites can be used.  Just replace the urls near the bottom of the file with the ones you want to use.</p>
<p>Please do note this is the first javascript I&#8217;ve written so it is very likely to have stupid errors and really bad style in it.  I welcome <strong>constructive</strong> criticism.</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="coMULTI">/*<br />
&nbsp;* twitter_identica &#8211; A program to combine twitter and laconica feeds<br />
&nbsp;* <br />
&nbsp;* @fileOverview A script to combine multiple twitter and laconica feeds.<br />
&nbsp;* @author Ghworg<br />
&nbsp;* @version 1.1<br />
&nbsp;* <br />
&nbsp;* Copyright (c) 2009 Ghworg<br />
&nbsp;* <br />
&nbsp;* This program is free software; you can redistribute it and/or modify it<br />
&nbsp;* under the terms of the GNU General Public License as published by the<br />
&nbsp;* Free Software Foundation; either version 2 of the License, or (at your<br />
&nbsp;* option) any later version.<br />
&nbsp;* <br />
&nbsp;* This program is distributed in the hope that it will be useful, but<br />
&nbsp;* WITHOUT ANY WARRANTY; without even the implied warranty of<br />
&nbsp;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General<br />
&nbsp;* Public License for more details.<br />
&nbsp;* <br />
&nbsp;* You should have received a copy of the GNU General Public License along<br />
&nbsp;* with this program; if not, write to the Free Software Foundation, Inc.,<br />
&nbsp;* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA<br />
&nbsp;* <br />
&nbsp;*/</span></p>
<p><span class="co1">/// @description Array to store the tweets in</span><br />
<span class="kw2">var</span> tweets = <span class="kw2">new</span> Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">/// @description Track which feed to pull from</span><br />
<span class="kw2">var</span> callCount = <span class="nu0">0</span>;</p>
<p><span class="coMULTI">/**<br />
&nbsp;* @description Convert a time string to the age of the tweet<br />
&nbsp;* @param time The time string<br />
&nbsp;* @returns The age<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> dateToAge<span class="br0">&#40;</span>time<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> month = <span class="nu0">1000</span> * <span class="nu0">60</span> * <span class="nu0">60</span> * <span class="nu0">24</span> * <span class="nu0">30</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> week = <span class="nu0">1000</span> * <span class="nu0">60</span> * <span class="nu0">60</span> * <span class="nu0">24</span> * <span class="nu0">7</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> day = <span class="nu0">1000</span> * <span class="nu0">60</span> * <span class="nu0">60</span> * <span class="nu0">24</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> hour = <span class="nu0">1000</span> * <span class="nu0">60</span> * <span class="nu0">60</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> minute = <span class="nu0">1000</span> * <span class="nu0">60</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> second = <span class="nu0">1000</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw2">var</span> now = <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> then = <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;then.<span class="me1">setTime</span><span class="br0">&#40;</span>Date.<span class="me1">parse</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp;<span class="kw2">var</span> diff = now &#8211; then;<br />
&nbsp; &nbsp;<span class="kw2">var</span> text = <span class="st0">&#8221;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>diff &gt; month<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; text = Math.<span class="me1">floor</span><span class="br0">&#40;</span>diff / month<span class="br0">&#41;</span> + <span class="st0">&#8216; months&#8217;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>diff &gt; week<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; text = Math.<span class="me1">floor</span><span class="br0">&#40;</span>diff / week<span class="br0">&#41;</span> + <span class="st0">&#8216; weeks&#8217;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>diff &gt; day<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; text = Math.<span class="me1">floor</span><span class="br0">&#40;</span>diff / day<span class="br0">&#41;</span> + <span class="st0">&#8216; days&#8217;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>diff &gt; hour<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; text = Math.<span class="me1">floor</span><span class="br0">&#40;</span>diff / hour<span class="br0">&#41;</span> + <span class="st0">&#8216; hours&#8217;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>diff &gt; minute<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; text = Math.<span class="me1">floor</span><span class="br0">&#40;</span>diff / minute<span class="br0">&#41;</span> + <span class="st0">&#8216; minutes&#8217;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; text = Math.<span class="me1">floor</span><span class="br0">&#40;</span>diff / second<span class="br0">&#41;</span> + <span class="st0">&#8216; seconds&#8217;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;text += <span class="st0">&#8216; ago&#8217;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw1">return</span> text;<br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description Make a JSON call<br />
&nbsp;* @param Url of handler to call<br />
&nbsp;* @param Event to call when complete<br />
&nbsp;* @param Event to call when an error is encountered<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> reqJSON<span class="br0">&#40;</span>url, success, error<span class="br0">&#41;</span> <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> CallParams = <span class="br0">&#123;</span> <span class="br0">&#125;</span>;<br />
&nbsp; &nbsp;CallParams.<span class="me1">type</span> = <span class="st0">&quot;GET&quot;</span>;<br />
&nbsp; &nbsp;CallParams.<span class="me1">url</span> = url;<br />
&nbsp; &nbsp;<span class="co1">//CallParams.username = username;</span><br />
&nbsp; &nbsp;<span class="co1">//CallParams.password = password;</span><br />
&nbsp; &nbsp;CallParams.<span class="me1">processData</span> = <span class="kw2">true</span>;<br />
&nbsp; &nbsp;<span class="co1">//CallParams.cache = false;</span><br />
&nbsp; &nbsp;CallParams.<span class="me1">dataType</span> = <span class="st0">&quot;json&quot;</span>;<br />
&nbsp; &nbsp;CallParams.<span class="me1">success</span> = success;<br />
&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>error<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; CallParams.<span class="me1">error</span> = error;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;$.<span class="me1">ajax</span><span class="br0">&#40;</span>CallParams<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description Compare two tweets based on their timestamps<br />
&nbsp;* @param a First tweet<br />
&nbsp;* @param b Second tweet<br />
&nbsp;* @returns -1 if a is newer than b else 1<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> sortTweets<span class="br0">&#40;</span>a, b<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> timea = <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> timeb = <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;timea.<span class="me1">setTime</span><span class="br0">&#40;</span>Date.<span class="me1">parse</span><span class="br0">&#40;</span>a.<span class="me1">created_at</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;timeb.<span class="me1">setTime</span><span class="br0">&#40;</span>Date.<span class="me1">parse</span><span class="br0">&#40;</span>b.<span class="me1">created_at</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>timea &gt; timeb<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="nu0">-1</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="nu0">1</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description Strip off the end of a URL to get the site address<br />
&nbsp;* @param fullurl The URL http://www.example.com/some/other/text<br />
&nbsp;* @returns http://www.example.com/<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> getBaseUrl<span class="br0">&#40;</span>fullurl<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> stripped = <span class="st0">&#8221;</span>;<br />
&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>fullurl.<span class="me1">substr</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">8</span><span class="br0">&#41;</span> == <span class="st0">&#8216;https://&#8217;</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; stripped = fullurl.<span class="me1">substring</span><span class="br0">&#40;</span><span class="nu0">8</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; stripped = fullurl.<span class="me1">substring</span><span class="br0">&#40;</span><span class="nu0">7</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> endIndex = stripped.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">&#8216;/&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;stripped = stripped.<span class="me1">substr</span><span class="br0">&#40;</span><span class="nu0">0</span>, endIndex<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw1">return</span> stripped;<br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description Go through all the existing tweets and check if the new one <br />
&nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is there already<br />
&nbsp;* @param oldTweets An array of all the existing tweets<br />
&nbsp;* @param newTweet The new tweet<br />
&nbsp;* @returns true or false<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> checkForDups<span class="br0">&#40;</span>oldTweets, newTweet<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> dupe = <span class="kw2">false</span>;<br />
&nbsp; &nbsp;$.<span class="me1">each</span><span class="br0">&#40;</span>oldTweets, <span class="kw2">function</span><span class="br0">&#40;</span>i, tweet<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>tweet.<span class="me1">text</span> == newTweet.<span class="me1">text</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dupe = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="kw1">return</span> dupe;<br />
<span class="br0">&#125;</span><br />
&nbsp; &nbsp;</p>
<p><span class="coMULTI">/**<br />
&nbsp;* @description Search the text for links and make them clickable<br />
&nbsp;* @param startMarker Text to look for that indicates a link<br />
&nbsp;* @param text The original text<br />
&nbsp;* @param prefix Text to put in front of the URL<br />
&nbsp;* @returns Text with links<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> addLink<span class="br0">&#40;</span>startMarker, text, prefix<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> endindex = <span class="nu0">0</span>;<br />
&nbsp; &nbsp;<span class="kw1">while</span> <span class="br0">&#40;</span>endindex &lt; text.<span class="me1">length</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; startindex = text.<span class="me1">indexOf</span><span class="br0">&#40;</span>startMarker, endindex<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>startindex &gt;= <span class="nu0">0</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;endindex = text.<span class="me1">indexOf</span><span class="br0">&#40;</span><span class="st0">&#8216; &#8216;</span>, startindex<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>endindex &lt; <span class="nu0">0</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endindex = text.<span class="me1">length</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;before = text.<span class="me1">substring</span><span class="br0">&#40;</span><span class="nu0">0</span>, startindex<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url = text.<span class="me1">substring</span><span class="br0">&#40;</span>startindex, endindex<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;after = text.<span class="me1">substring</span><span class="br0">&#40;</span>endindex<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;href = url.<span class="me1">link</span><span class="br0">&#40;</span>prefix + url.<span class="me1">replace</span><span class="br0">&#40;</span><span class="st0">&#8216;@&#8217;</span>, <span class="st0">&#8221;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;text = before + href + after;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;endindex = before.<span class="me1">length</span> + href.<span class="me1">length</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">else</span> &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">break</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">return</span> text;<br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description Convert http https and @ replies to links<br />
&nbsp;* @param text The original text<br />
&nbsp;* @param baseUrl Site the tweet came from (to use for @s)<br />
&nbsp;* @returns Text with links<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> addLinks<span class="br0">&#40;</span>text, baseUrl<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;text = addLink<span class="br0">&#40;</span><span class="st0">&#8216;https://&#8217;</span>, text, <span class="st0">&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;text = addLink<span class="br0">&#40;</span><span class="st0">&#8216;http://&#8217;</span>, text, <span class="st0">&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;text = addLink<span class="br0">&#40;</span><span class="st0">&#8216;@&#8217;</span>, text, baseUrl<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="kw1">return</span> text<br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description JSON request succeeded, <br />
&nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;process the data and insert it into the web page<br />
&nbsp;* @param json The json data received<br />
&nbsp;* @param textStatus Result code<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> readJson<span class="br0">&#40;</span>json, textStatus<span class="br0">&#41;</span> <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="co1">//Successful call</span><br />
&nbsp; &nbsp;<span class="co1">//Do stuff with the JSON</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw2">var</span> requestUrl = <span class="kw1">this</span>.<span class="me1">url</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> baseUrl = getBaseUrl<span class="br0">&#40;</span>requestUrl<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="co1">// Clear out any old tweets from the html</span><br />
&nbsp; &nbsp;$<span class="br0">&#40;</span><span class="st0">&quot;p.tweet&quot;</span><span class="br0">&#41;</span>.<span class="me1">remove</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="co1">// Delete old tweets from this url from the list</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> oldtweets = tweets;<br />
&nbsp; &nbsp;tweets = <span class="kw2">new</span> Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;$.<span class="me1">each</span><span class="br0">&#40;</span>oldtweets, <span class="kw2">function</span><span class="br0">&#40;</span>i, <span class="kw1">item</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">item</span>.<span class="me1">baseUrl</span> != baseUrl<span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tweets<span class="br0">&#91;</span>tweets.<span class="me1">length</span><span class="br0">&#93;</span> = <span class="kw1">item</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="co1">// Add newly retrieved tweets to the list</span><br />
&nbsp; &nbsp;$.<span class="me1">each</span><span class="br0">&#40;</span>json, <span class="kw2">function</span><span class="br0">&#40;</span>i, <span class="kw1">item</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">item</span>.<span class="me1">baseUrl</span> = baseUrl;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>checkForDups<span class="br0">&#40;</span>tweets, <span class="kw1">item</span><span class="br0">&#41;</span> == <span class="kw2">false</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tweets<span class="br0">&#91;</span>tweets.<span class="me1">length</span><span class="br0">&#93;</span> = <span class="kw1">item</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="co1">// Sort the tweet list by age</span><br />
&nbsp; &nbsp;tweets.<span class="me1">sort</span><span class="br0">&#40;</span>sortTweets<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="co1">// Print the tweets to the html</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> pretext = <span class="st0">&#8216;&lt;p class=&quot;tweet&quot;&gt;&#8217;</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> postext = <span class="st0">&#8216;&lt;/p&gt;&#8217;</span>;<br />
&nbsp; &nbsp;$.<span class="me1">each</span><span class="br0">&#40;</span>tweets, <span class="kw2">function</span><span class="br0">&#40;</span>i, <span class="kw1">item</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">//pretext = &#8216;&lt;p class=&quot;tweet &#8216;;</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">//pretext = pretext + item.baseUrl.replace(&#8216;.&#8217;, &#8221;) + &#8216;&quot;&gt;&#8217;;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">var</span> ago = dateToAge<span class="br0">&#40;</span><span class="kw1">item</span>.<span class="me1">created_at</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw2">var</span> base = <span class="st0">&#8216;http://&#8217;</span> + <span class="kw1">item</span>.<span class="me1">baseUrl</span> + <span class="st0">&#8216;/&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw2">var</span> text = addLinks<span class="br0">&#40;</span><span class="kw1">item</span>.<span class="me1">text</span>, base<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw2">var</span> userlink = <span class="kw1">item</span>.<span class="me1">user</span>.<span class="me1">screen_name</span>.<span class="me1">link</span><span class="br0">&#40;</span>base + <span class="kw1">item</span>.<span class="me1">user</span>.<span class="me1">screen_name</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; mb.<span class="me1">append</span><span class="br0">&#40;</span>pretext + ago + <span class="st0">&#8216;: &#8216;</span> + userlink + <span class="st0">&#8216;: &#8216;</span> + text + postext<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description Called if JSON request failed<br />
&nbsp;* @param XMLHttpRequest<br />
&nbsp;* @param textStatus<br />
&nbsp;* @param errorThrown<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> failJson<span class="br0">&#40;</span>XMLHttpRequest, textStatus, errorThrown<span class="br0">&#41;</span> <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="co1">// typically only one of textStatus or errorThrown </span><br />
&nbsp; &nbsp;<span class="co1">// will have info</span><br />
&nbsp; &nbsp;<span class="co1">// </span><br />
&nbsp; &nbsp;mb.<span class="me1">append</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting json data<br />
&quot;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>
<span class="coMULTI">/**<br />
&nbsp;* @description Main function<br />
&nbsp;*/</span><br />
<span class="kw2">function</span> display<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp;mb = $<span class="br0">&#40;</span><span class="st0">&quot;#microblog&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;<span class="kw2">var</span> urls = <span class="br0">&#91;</span> <span class="st0">&quot;https://identi.ca/api/statuses/friends_timeline.json?callback=?&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;https://twitter.com/statuses/friends_timeline.json?callback=?&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="co1">//if ( 0 == $(&quot;p.tweet&quot;).length ) &nbsp;{</span><br />
&nbsp; &nbsp;<span class="co1">// &nbsp; $.each(urls, function(i, url) &nbsp;{</span><br />
&nbsp; &nbsp;<span class="co1">// &nbsp; &nbsp; &nbsp;reqJSON(url, readJson, failJson);</span><br />
&nbsp; &nbsp;<span class="co1">// &nbsp; });</span><br />
&nbsp; &nbsp;<span class="co1">//}</span><br />
&nbsp; &nbsp;<span class="co1">//else &nbsp;{</span><br />
&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>callCount &lt; urls.<span class="me1">length</span><span class="br0">&#41;</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; reqJSON<span class="br0">&#40;</span>urls<span class="br0">&#91;</span>callCount<span class="br0">&#93;</span>, readJson, failJson<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; callCount = callCount + <span class="nu0">1</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span> &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; callCount = <span class="nu0">0</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="co1">//}</span><br />
<span class="br0">&#125;</span></p>
<p>&nbsp;</p></div>
<p>Update (2009-02-22):  I forgot to mention, you need t call the display function to get it to actually do something.  It is currently set to read one feed every time display is called as it is designed to be called on a timer and I didn&#8217;t want two password requests to appear at once.  If you want to read all feeds simultaneously then uncomment the commented code in the display function.</p>
<p>Update (2009-02-28):  Fixed a small bug where html tags in tweets were interpreted, they are now escaped.  New version is available <a href='http://blog.trollgod.org.uk/wp-content/uploads/2009/02/twitter_identica.js'>twitter_identica</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trollgod.org.uk/2009/02/twitter-and-laconica-combined/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
