Google Reader Make Stars

By Michael Devore Last update Jun 12, 2011 — Installed 198 times.
// grmakestars.user.js
//
// ==UserScript==
// @name          Google Reader Make Stars
// @namespace     http://www.devoresoftware.com/gm/grms
// @description	  Star all visible Google Reader items for particular tags
// @include       http://www.google.com/reader/*
// @include       https://www.google.com/reader/*
// ==/UserScript==
//

// list of text strings to match tag and star the item
// each quoted entry should end the line with a comma, except the final line
var starThisTag = [
	"horse",
	"cow"
];

function main()
{
//	var xpath = "//DIV[@id='entries']//DIV[@class='entry-icons']/DIV[@class='item-star-active']";
	var xpath = "//DIV[@id='entries']//DIV[@class='entry-icons']/DIV[(not(contains(@class,'item-star-active'))) and (contains(@class,'item-star'))]";
	var starDivs = document.evaluate(
		xpath,
		document,
		null,
		XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
		null
	);

	var xpath2 = ".//UL[contains(@class,'user-tags-list')]/LI/A/text()";
	for (var i = 0; i < starDivs.snapshotLength; i++)
	{
 		var candidate = starDivs.snapshotItem(i);
		ancestorNode = candidate.parentNode.parentNode.parentNode.parentNode;
		var tagDivs = document.evaluate(
			xpath2,
			ancestorNode,
			null,
			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
			null
		);
		var bStarred = false;
		for (var j = 0; !bStarred && (j < tagDivs.snapshotLength); j++)
		{
			var tNode = tagDivs.snapshotItem(j);
			for (var k = 0; !bStarred && (k < starThisTag.length); k++)
			{
		 		if (tNode.nodeValue == starThisTag[k])
		 		{
					var oEvent = document.createEvent("MouseEvents");
					oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, null);
					candidate.dispatchEvent(oEvent);
					bStarred = true;
				}
			}
		}
	}
}

GM_registerMenuCommand("Make stars in Google Reader", main, "", "", "R");