Flickr No Awards

By Justin Locsei Last update Mar 10, 2009 — Installed 1,039 times. Daily Installs: 4, 0, 3, 1, 1, 0, 3, 0, 1, 0, 2, 0, 1, 4, 1, 3, 2, 0, 3, 0, 2, 0, 2, 0, 1, 1, 2, 0, 0, 3, 0, 2

There are 1 previous version of this script.

// ==UserScript==
// @name           Flickr No Awards
// @description    Removes any award comments from flickr photos
// @include        http://www.flickr.com/photos/*
// @include        http://flickr.com/photos/*
// ==/UserScript==
//
//  Script written by Justin Locsei 
//		   http://www.moremonks.com

//  Begin enclosure
(function() {

//  Toggles the visibility of the modified awards
function toggleAwards() {
	
	//  Cycle through awards and toggle visibility
	for (i=0; i < hiddenAwards.length; i++) {
		hiddenAwards[i].style.display = (hiddenAwards[i].style.display == "none" ? "block" : "none");
	}

	//  Get link object and award text
	var toggleLink = document.getElementById("toggleLink");
	var awardText  = document.getElementById("awardText");

	//  Update text in status area to reflect current state of award display
	if (toggleLink.innerHTML == "show awards") {
		awardText.innerHTML = "( S" + awardText.innerHTML.slice(7);
		awardText.style.color = "#FF0084";
	}
	else {
		awardText.innerHTML = "( Not s" + awardText.innerHTML.slice(3);
		awardText.style.color = "gray";
	}

	//  Show fitting text for link 
	toggleLink.innerHTML = (toggleLink.innerHTML == "show awards" ? "hide awards" : "show awards");
}

//  Array for storing hidden award comments
var hiddenAwards = new Array();

//  Request all photo comments containing a link to a group
var allComments = document.evaluate("//a[contains(@href, '/groups/')]/ancestor::div[contains(@class,'comment-block')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

//  Cycle through the returned award elements
for (var i=0; i < allComments.snapshotLength; i++) {

	//  Get award element
	var awardComment = allComments.snapshotItem(i);

	//  Give comment a light background
	awardComment.style.backgroundColor = "#FFEAF0";

	//  Push div to array for later use
	hiddenAwards[hiddenAwards.length] = awardComment;

	//  Hide award element
	awardComment.style.display = "none";
}

//  If award comments were hidden, display hidden amount and add toggling button
if (allComments.snapshotLength) {

	//  Create status div 
	var statusDiv = document.createElement("div");

	//  Style and fill div with content
	statusDiv.innerHTML           = "( Not showing " + allComments.snapshotLength + " award comments )";
	statusDiv.style.fontStyle     = "italic";
	statusDiv.style.fontSize      = "8pt";
	statusDiv.style.color         = "gray";
	statusDiv.style.paddingTop    = "2px";
	statusDiv.style.paddingBottom = "10px";
	statusDiv.id				  = "awardText";

	//  Create toggle element
	var toggleDiv = document.createElement("span");

	//  Style and fill span with content
	toggleDiv.innerHTML			= "show awards";
	toggleDiv.style.cursor		= "pointer";
	toggleDiv.style.fontSize	= "8pt";
	toggleDiv.style.color		= "#0063DC";
	toggleDiv.style.paddingLeft = "22px";
	toggleDiv.id				= "toggleLink";

	//  Add toggle click event listener 
	toggleDiv.addEventListener("click", toggleAwards, true);

	//  Get the comments header
	var commentHeader = document.evaluate("//h3[starts-with(text(), 'Comments')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

	//  Insert display of number of award comments and link to toggle their visibility
	commentHeader.snapshotItem(0).appendChild(toggleDiv);
	commentHeader.snapshotItem(0).appendChild(statusDiv);
}

//  End enclosure
})();