<?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>chromakode &#187; javascript</title>
	<atom:link href="http://www.chromakode.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chromakode.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 30 Apr 2010 17:50:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>saidit, a Greasemonkey script for reddit</title>
		<link>http://www.chromakode.com/2009/01/saidit-a-greasemonkey-script-for-reddit/</link>
		<comments>http://www.chromakode.com/2009/01/saidit-a-greasemonkey-script-for-reddit/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 08:06:13 +0000</pubDate>
		<dc:creator>chromakode</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[DOM storage]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[reddit]]></category>
		<category><![CDATA[saidit]]></category>
		<category><![CDATA[userscript]]></category>

		<guid isPermaLink="false">http://www.chromakode.com/?p=641</guid>
		<description><![CDATA[View and install the saidit Greasemonkey script on userscripts.org. Click here »
The saidit script enhances reddit comment pages by highlighting unread comments. It works by keeping track of the comments you&#8217;ve already viewed. Here&#8217;s what it looks like:

Features

Highlights unread reddit comments
Read comments are stored locally
Automatic removal of old data
Efficient implementation

Installation
If you&#8217;d like to give it [...]]]></description>
			<content:encoded><![CDATA[<div class="noticebox info">View and install the <a href="http://userscripts.org/scripts/show/40860">saidit</a> Greasemonkey script on userscripts.org. <a href="http://userscripts.org/scripts/show/40860">Click here »</a></div>
<p>The <a href="http://userscripts.org/scripts/show/40860">saidit</a> script enhances <a href="http://www.reddit.com">reddit</a> comment pages by highlighting unread comments. It works by keeping track of the comments you&#8217;ve already viewed. Here&#8217;s what it looks like:</p>
<p style="text-align: center;"><a href="http://www.reddit.com/r/funny/comments/7emij/original_drawing_of_a_7legged_spider_sells_for/c06gdav"><img class="aligncenter size-full wp-image-645 frame" title="Learning Gaucho theory with saidit" src="http://www.chromakode.com/wordpress/wp-content/uploads/2009/01/saidit.png" alt="saidit" width="500" height="210" /></a></p>
<h3>Features</h3>
<ul>
<li>Highlights unread reddit comments</li>
<li>Read comments are stored locally</li>
<li>Automatic removal of old data</li>
<li>Efficient implementation</li>
</ul>
<h3>Installation</h3>
<p>If you&#8217;d like to give it a spin, make sure you have <a href="https://addons.mozilla.org/en-US/firefox/addon/748">Greasemonkey</a> installed. Then, just install <a href="http://userscripts.org/scripts/show/40860">saidit</a> from userscripts.org. Have fun!</p>
<p class="note">
<p style="text-align: center;"><span id="more-641"></span></p>
<h3>How it works</h3>
<p>For every comment viewed on reddit, saidit records the comment id in a &#8220;seen comments list&#8221; using <a href="https://developer.mozilla.org/En/DOM/Storage">DOM Storage</a>. When a reddit comments page is loaded, saidit scans through each comment and checks if the id is in the list. If the id is not found, the class &#8220;unread&#8221;, is added to the comment div (this class can then be styled to emphasize unread comments). The seen comments list is then updated to include the new comments.</p>
<p>Since the script scans through hundreds of comments during the time-sensitive page loading process, I needed to make checking comment ids as fast as possible. Experimentation showed that if the seen comment ids were loaded into the fields of an <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a>, looking up ids was much faster than using an <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>. Currently, saidit takes up to 2.5 seconds on the largest comment pages (200+) on my machine. I&#8217;m continuing to look into ways of making it faster.</p>
<h3>Interoperability</h3>
<p>An interesting side-effect of using DOM Storage is that read comment data is accessible to JavaScript on reddit and any other user scripts. If you can think of any clever ways to use this data, feel free to load it using the loading code below, or simply fork saidit to create a new script. Please use your new powers for good, not evil!</p>
<p>Here&#8217;s what the data loading code looks like, using Mozilla&#8217;s non-standard implementation of <a href="https://developer.mozilla.org/En/DOM/Storage">DOM Storage</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> redditStorage <span class="sy0">=</span> globalStorage.<span class="me1">namedItem</span><span class="br0">&#40;</span><span class="st0">&quot;www.reddit.com&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw2">var</span> pageThingID <span class="sy0">=</span> getThingID<span class="br0">&#40;</span>getPageThing<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw2">var</span> seenArray <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="kw2">var</span> seenObject <span class="sy0">=</span> <span class="br0">&#123;</span><span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">var</span> seenData <span class="sy0">=</span> redditStorage.<span class="me1">getItem</span><span class="br0">&#40;</span><span class="st0">&quot;seen-&quot;</span><span class="sy0">+</span>pageThingID<span class="br0">&#41;</span><span class="sy0">;</span>
seenArray <span class="sy0">=</span> seenData.<span class="me1">value</span>.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&quot;,&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// Build an object for faster access</span>
seenArray.<span class="me1">forEach</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>element<span class="br0">&#41;</span> <span class="br0">&#123;</span>
  seenObject<span class="br0">&#91;</span>element<span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>The &#8220;unread&#8221; class can be styled in subreddit CSS to achieve different effects. Just use a CSS rule similar to the default (perhaps with !important added):</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span class="re1">.comment</span><span class="re1">.unread</span> <span class="re1">.tagline</span> <span class="br0">&#123;</span>
  <span class="kw1">font-weight</span><span class="sy0">:</span> <span class="kw2">bold</span><span class="sy0">;</span>
  <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#fea</span><span class="sy0">;</span>
  <span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">inline</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>If you discover any interesting ways to use these, please <a href="#respond">leave a comment</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chromakode.com/2009/01/saidit-a-greasemonkey-script-for-reddit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Letting IE6 down easy</title>
		<link>http://www.chromakode.com/2008/12/letting-ie6-down-easy/</link>
		<comments>http://www.chromakode.com/2008/12/letting-ie6-down-easy/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 10:50:50 +0000</pubDate>
		<dc:creator>chromakode</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.chromakode.com/?p=375</guid>
		<description><![CDATA[If you were browsing using Internet Explorer 6 right now, here&#8217;s what you&#8217;d see:

Note: Internet Explorer version 6 or lower has been detected.
Your browser cannot display this page properly. For compatibility, this page has been reduced to a low-graphics mode. To view this site the way it was intended, please upgrade Internet Explorer or switch [...]]]></description>
			<content:encoded><![CDATA[<p>If you were browsing using <a href="http://en.wikipedia.org/wiki/IE6">Internet Explorer 6</a> right now, here&#8217;s what you&#8217;d see:</p>
<div class="ie6alert">
<h1>Note: Internet Explorer version 6 or lower has been detected.</h1>
<p>Your browser cannot display this page properly. For compatibility, this page has been reduced to a low-graphics mode. To view this site the way it was intended, please upgrade Internet Explorer or <a href="http://browsehappy.com/browsers/">switch to another browser</a>.</div>
<p>This morning, I bit the bullet and finally took a look at my site in IE6. A few minutes later, after fruitlessly experimenting with compatibility scripts, I decided to formally drop IE6 support for this site. I&#8217;ve long felt that it&#8217;s a waste of effort to cater to browsers that don&#8217;t meet developers halfway, so I&#8217;ve typically put minimal effort into designing my pages around them. I&#8217;ve also felt that the best way to finally stab the stake into IE6&#8217;s heart is to simply let pages look bad and out of date in it. I&#8217;m pleased to see that this practice is finally gaining <a href="http://idroppedie6.com/">critical mass</a>.</p>
<p>Thus, I set out to find some JavaScript glue to formally explain my intentions to visitors. After surveying the options, some of which were a bit too <a href="http://www.stopie6.org/">preachy</a>, and others a bit too <a href="http://www.stopie6.com/">mild</a>, I decided to write my own little IE6 handler script.</p>
<p>My script, IE6unstyled.js, adds the header seen at the top of this post. The page is then displayed <strong>unstyled</strong> (based on <a href="http://dorward.me.uk/">David Dorward<a/>&#8217;s <a href="http://dorward.me.uk/software/disablecss/">bookmarklet</a>), which works well if your page degrades gracefully. Rather than allow IE6 to mangle the page layout, I choose to simply give it the raw content. This frees me from worrying about the presentation in IE6 and restores the layout to a basic, usable state. I feel that this projects the right message: to experience the current web to its fullest, you&#8217;d best switch from using IE6.</p>
<p><span id="more-375"></span><br />
Here&#8217;s the script.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span class="kw3">onload</span> <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="kw1">for</span><span class="br0">&#40;</span>i<span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span>i<span class="sy0">&lt;</span>document .<span class="me1">styleSheets</span>.<span class="me1">length</span><span class="sy0">;</span>i<span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		document.<span class="me1">styleSheets</span>.<span class="kw1">item</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">disabled</span><span class="sy0">=</span><span class="kw2">true</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	el <span class="sy0">=</span> document.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">'*'</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">for</span> <span class="br0">&#40;</span> i<span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">&lt;</span>el.<span class="me1">length</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		el<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">style</span>.<span class="me1">cssText</span> <span class="sy0">=</span> <span class="st0">''</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
	div <span class="sy0">=</span> document.<span class="me1">createElement</span><span class="br0">&#40;</span><span class="st0">'div'</span><span class="br0">&#41;</span><span class="sy0">;</span>
	div.<span class="me1">innerHTML</span> <span class="sy0">=</span> <span class="st0">'&lt;h1 style=&quot;font-size:18pt;&quot;&gt;Note: a version of Internet Explorer of 6 or lower has been detected.&lt;p&gt;Your browser cannot display this page properly. For compatibility, this page has been reduced to a low-graphics mode. To view this site the way it was intended, please upgrade Internet Explorer or &lt;a href=&quot;http://browsehappy.com/browsers/&quot;&gt;switch to another browser&lt;/a&gt;.&lt;/p&gt;'</span><span class="sy0">;</span>
	div.<span class="me1">style</span>.<span class="me1">cssText</span> <span class="sy0">=</span> <span class="st0">'color:black; background-color:yellow; border:5px solid black; padding:15px;'</span><span class="sy0">;</span>
	document.<span class="me1">body</span>.<span class="me1">insertBefore</span><span class="br0">&#40;</span>div<span class="sy0">,</span> document.<span class="me1">body</span>.<span class="me1">firstChild</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span></pre></div></div>

<p>To use it, stash the file somewhere on your server. Then, add the following HTML to your header (edited to reflect the file location).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span class="sc-1">&lt;!--[if lte IE 6]&gt;</span>
<span class="sc-1">	&lt;script src=&quot;path/to/IE6unstyled.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</span>
<span class="sc-1">&lt;![endif]--&gt;</span></pre></div></div>

<p>Please feel free use this and make any modifications as you see fit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chromakode.com/2008/12/letting-ie6-down-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
