<?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>zethrae.us/blog &#187; web_dev</title>
	<atom:link href="http://zethrae.us/blog/category/web_dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://zethrae.us/blog</link>
	<description>Miscellaneous Geekery</description>
	<lastBuildDate>Thu, 19 Aug 2010 01:32:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Playing with user scripts</title>
		<link>http://zethrae.us/blog/2010/playing-with-user-scripts/</link>
		<comments>http://zethrae.us/blog/2010/playing-with-user-scripts/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 23:07:09 +0000</pubDate>
		<dc:creator>zethraeus</dc:creator>
				<category><![CDATA[web_dev]]></category>
		<category><![CDATA[4chan]]></category>
		<category><![CDATA[cs016]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[userscript]]></category>

		<guid isPermaLink="false">http://zethrae.us/blog/?p=201</guid>
		<description><![CDATA[I&#8217;m taking a rather fun algorithms course with a website that reddit loves but I do not. I decided to turn this dire, lolcat-overloaded, situation into an opportunity to practice some javascript (without jQuery) and to write my first userscript. User scripts are javascript files with the extension &#8216;.user.js&#8217; that are executed client-side to add [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m taking a rather fun algorithms course with a <a href="http://www.cs.brown.edu/courses/cs016/">website</a> that <a href="http://www.reddit.com/r/funny/comments/azo5c/weve_all_had_that_one_really_eccentric_professor/">reddit loves</a> but I do not. I decided to turn this dire, lolcat-overloaded, situation into an opportunity to practice some javascript (without jQuery) and to write my first userscript.</p>
<p>User scripts are javascript files with the extension &#8216;.user.js&#8217; that are executed client-side to add functionality to a web page. They are natively supported by chrome and opera and are supported via extensions in most other browsers of any note. (Some include Greasemonkey for Firefox, GreaseKit for Safari and Trixie for IE).</p>
<p>I succeeded in reskinning the whole website which was pretty fun. There seems to be a limit to the usefulness of userscripts in that support for the &#8216;@run-at document-start&#8217; flag which I believe should make the script run before any scripts on the page do, is not supported by most browsers. It&#8217;s not all that useful a flag anyway as I imagine you&#8217;d often want the script to run after the DOM has been written so that you can work with the content expected to be on the page. In this case however it would be useful as I attempt to strip out a script on the course page that redirects 1% of all hits to a rickroll (sigh). As such the script still runs before the userscript and so the rickrolling still happens.</p>
<p>I might also put some more time into the replacement style sheet some time soon.</p>
<p style="text-align: center;"><a href="http://zethrae.us/blog/wp-content/uploads/cs16.png"><img class="size-medium wp-image-206 aligncenter" title="cs16" src="http://zethrae.us/blog/wp-content/uploads//cs16-254x300.png" alt="CS16 course site" width="254" height="300" /></a></p>
<p style="text-align: center;">Original<a href="http://zethrae.us/blog/wp-content/uploads//cs16.user_.js.png"><img class="size-medium wp-image-207 aligncenter" title="cs16.user.js" src="http://zethrae.us/blog/wp-content/uploads//cs16.user_.js-300x245.png" alt="CS16 course site with userscript and restyle" width="300" height="245" /></a></p>
<p style="text-align: center;">Reshaped and restyled</p>
<p style="text-align: left;">Code after the break.<span id="more-201"></span></p>
<h3 style="text-align: left;">Final Code:</h3>
<pre>﻿// ==UserScript==
// @name           !cs16chan
// @namespace      http://zethrae.us
// @description    Strips mematic content from the cs16 course website
// @include        http://cs.brown.edu/courses/cs016/*
// @include        http://www.cs.brown.edu/courses/cs016/*
// @run-at document-start
// ==/UserScript==

(function() {
 //the following function is from http://snipplr.com/view/1696/get-elements-by-class-name/
 //the internet claims that document.getElementsByClassName() is supported in firefox 3.
 //this doesn't seem to be the case on the CIT machines, so I guess this will have to do.
 //and yes. if i was writing this again, I'd just include and use jquery.
 function getElementsByClassName(classname, node) {
 if(!node) node = document.getElementsByTagName("body")[0];
 var a = [];
 var re = new RegExp('\\b' + classname + '\\b');
 var els = node.getElementsByTagName("*");
 for(var i=0,j=els.length; i&lt;j; i++)
 if(re.test(els[i].className))a.push(els[i]);
 return a;
 }

function insertAfter(parent, node, referenceNode) {
 parent.insertBefore(node, referenceNode.nextSibling);
}

function strip_css_js(){
 var jsToRemove = document.getElementsByTagName("script");
 for (var i=jsToRemove.length; i&gt;=0; i--){
 if (jsToRemove[i] &amp;&amp; jsToRemove[i].getAttribute("src")!=null){
 jsToRemove[i].parentNode.removeChild(jsToRemove[i]);
 }
 }
 var cssToRemove = document.getElementsByTagName("link")
 for (var i=cssToRemove.length; i&gt;=0; i--){
 if (cssToRemove[i] &amp;&amp; cssToRemove[i].getAttribute("href")!=null){
 cssToRemove[i].parentNode.removeChild(cssToRemove[i]);
 }
 }
 }

function import_css(source) {
 var link = document.createElement("link");
 link.href = source;
 link.rel = "stylesheet";
 link.type = "text/css";
 document.getElementsByTagName("head")[0].appendChild(link);
}

//removes memes that won't be wiped by the fix_markup function
function strip_inline_memes(){
 var tagline = document.getElementById('tagline');
 tagline.parentNode.removeChild(tagline);

 var footer = document.getElementById('footer');
 footer.parentNode.removeChild(footer);

 var images = document.getElementsByTagName("img")
 for (var i=images.length; i&gt;=0; i--){
 if (images[i]){
 images[i].parentNode.removeChild(images[i]);
 }
 }

var memesbyclass = getElementsByClassName('preH1').concat(getElementsByClassName('postH1'))
 for (var i=memesbyclass.length; i&gt;=0; i--){
 if (memesbyclass[i]){
 memesbyclass[i].parentNode.removeChild(memesbyclass[i]);
 }
 }

}
function fix_markup(){
 var header = document.getElementById('header');
 header.parentNode.removeChild(header);

 var head1 = getElementsByClassName('h1')
 for (var i=head1.length; i&gt;=0; i--){
 if (head1[i]){
 var newheader = document.createElement("div");
 newheader.innerHTML = "&lt;h1&gt;CS16 / "+ head1[i].innerHTML +"&lt;/h1&gt;";
 head1[i].parentNode.replaceChild(newheader,head1[i]);
 }
 }

 var nav = document.getElementById('nav');
 var navcontent = nav.innerHTML;
 var newnav = document.createElement("div");
 newnav.id = "navigation";
 newnav.innerHTML = navcontent;
 nav.parentNode.removeChild(nav);

 var content = document.getElementById('content');
 content.insertBefore(newnav, content.firstChild.nextSibling.nextSibling.nextSibling.nextSibling);

}

strip_css_js();
strip_inline_memes();
fix_markup();
import_css("http://zethrae.us/work/bangCS16chan/style.css");
})();
</pre>
<p>This was all intended to be tongue in cheek. But yes, memes from &#8217;06 are rather annoying to see every day. And there wasn&#8217;t even longcat.</p>
]]></content:encoded>
			<wfw:commentRss>http://zethrae.us/blog/2010/playing-with-user-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Newspaper Layout with JQuery</title>
		<link>http://zethrae.us/blog/2010/news-paper-layout-with-jquery/</link>
		<comments>http://zethrae.us/blog/2010/news-paper-layout-with-jquery/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 03:06:48 +0000</pubDate>
		<dc:creator>zethraeus</dc:creator>
				<category><![CDATA[web_dev]]></category>

		<guid isPermaLink="false">http://zethrae.us/blog/?p=169</guid>
		<description><![CDATA[Is it a good idea to use javascript to completely reshape a website&#8217;s design? Columnizer is a JQuery plugin which makes the long wished for and ever intangible vertical wrap CSS feature come to life. The idea of the feature is to allow for dynamic newspaper style columns on a website. Columns have ordinarily been [...]]]></description>
			<content:encoded><![CDATA[<p>Is it a good idea to use javascript to completely reshape a website&#8217;s design? <a href="http://welcome.totheinter.net/columnizer-jquery-plugin/">Columnizer</a> is a JQuery plugin which makes the long wished for and ever intangible vertical wrap CSS feature come to life.</p>
<p>The idea of the feature is to allow for dynamic newspaper style columns on a website. Columns have ordinarily been unachievable though any means but manually separating up content (which would still give unpredictable results).</p>
<p>I&#8217;m in the camp that wants the web to be both usable and pretty even with javascript turned off. I&#8217;ve missed lots of neat aspects of websites as a result of browsing behind NoScript in past. I think it would be very difficult to make a website designed with such drastic styling done with javascript degrade gracefully in a browser with the tool disabled. However, from a designer&#8217;s perspective, this is still one of the most interesting JQuery plugins I&#8217;ve seen yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://zethrae.us/blog/2010/news-paper-layout-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
