// huffandpuff.user.js huffingtonpost.com user script.
// version 0.2, 2005-12-20
// Released under the GPL license
// Copyright (c) Doktor Armand Geddyn, the Ministry of Truth
// http://www.gnu.org/copyleft/gpl.html
//
//--------------------------------------------------------------------
//
// ==UserScript==
// @name          HuffandPuff
// @namespace     http://www.minitru.org/gm/
// @description   Does stuff to the Huffington Post to make it less irritating.
// @include       http://*.huffingtonpost.com/*
// ==/UserScript==
//

/* Goals: Remove ads. Done in 0.1!
					Soften press photos. They make my eyes hurt. Done in 0.2!
					I'd rather see the layout of all the blogs up top, then the regular news under that.
							Planned for v 0.3
*/

/* Anonymous function to kill the advertising iframes. */
/* Most iframes are ads. Some aren't. Need to test them all. */
(function() {
	var Iframes;
	Iframes = document.getElementsByTagName('ifRame');
	for (var i = 0; i < Iframes.length; i++) {
		// GM_log('Saw iframe: '+Iframes[i].src);
		/* If the iframe is sourced from somewhere other than huffingtonpost.com, kill it*/
		if (!(/^http:\/\/.*\.huffingtonpost\.com\//.test(Iframes[i].src))) {
			// GM_log('Removing ad: '+Iframes[i].src);
			Iframes[i].parentNode.removeChild(Iframes[i]);
		}
	}
})();
/* * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Anonymous function to kill the newsad DIV. */
/* Note: Sped this up Div check with XPath evaluation:
				 http://diveintogreasemonkey.org/patterns/match-attribute.html
				 This way, I'm only testing DIV elements that have a Class attribute.
*/

(function() {
	var aDivs, thisDiv;
	xpath = "//div[contains(@class,'ad')]";
	aDivs = document.evaluate(
    xpath,
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
  for (var i = 0; i < aDivs.snapshotLength; i++) {
  	thisDiv = aDivs.snapshotItem(i);
  	// GM_log('Saw div: '+thisDiv.className);
  	if ((/^(inlineindex|right|permalink)ad$/.test(thisDiv.className))) {
    	// GM_log('Removing ad: '+thisDiv.className);
			thisDiv.parentNode.removeChild(thisDiv);
		}
	}
})();
/* * * * * * * * * * * * * * * * * * * * * * * * * * */ 

/* Anonymous function to soften Arianna's often harshly lit news photos. */

(function() {

	var opacityValue = '.60';
	var allImgs, thisImg;
	var xpath = "//img[contains(@src,'thenewswire')]";

	allImgs = document.evaluate(
    xpath,
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
  for (var i = 0; i < allImgs.snapshotLength; i++) {
  	thisImg = allImgs.snapshotItem(i);
  	//GM_log('Saw img: '+thisImg.src);
    thisImg.style.opacity = opacityValue;
  }

})();
/* * * * * * * * * * * * * * * * * * * * * * * * * * */ 
