Google Reader All Starred

By Benjamin Beckwith Last update Dec 13, 2005 — Installed 2,792 times.

Archived Comments (locked)

in
Subscribe to Archived Comments 10 posts, 4 voices



Jesse Andrews Admin

The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008)

 
Richard Osba... User

For what it's worth the script has been broken again by changes to Google Reader. I'm stumped this time as Google Reader now seems to be dynamically generating much of the page content which prevents us from tapping into it from GreaseMonkey? at least its effective at barring someone with my level of knowledge (low javascript foo).

 
Abhay Singh User
Here is the completely patched script. // GoogleReaderAllStarred // version 0.5 // 2005-12-13 // Copyright (c) 2005, Ben Beckwith // Released under the GPL license // http://www.gnu.org/copyleft/gpl.html // // -------------------------------------------------------------------- // // This is a Greasemonkey user script. To install it, you need // Greasemonkey 0.3 or later: http://greasemonkey.mozdev.org/ // Then restart Firefox and revisit this script. // Under Tools, there will be a new menu item to "Install User Script". // Accept the default configuration and install. // // -------------------------------------------------------------------- // There are a couple of extra ideas I had for this, but these may need // 1.) Make it easy to post all to del.icio.us // 2.) Automatic/batch unstar of all items // // -------------------------------------------------------------------- // Changes // 0.5 bnb // Updated to work with the latest Reader // 0.1.1 bnb // Updated script to work with the new GR XML file for starred items // 0.1 bnb // Initial Version // // -------------------------------------------------------------------- // // // ==UserScript== // @name Google Reader All Starred // @namespace http://whitebucket.com/greasemonkey // @description Script to extract all links from google reader that have been starred. // @include http://*.google.com/reader/* // @include http://google.com/reader/* // @include http://reader.google.com/* // ==/UserScript== // Be informative for older versions of Greasemonkey if (!GM_xmlhttpRequest) { alert('Please upgrade to the latest version of Greasemonkey.'); return; } // The variable to hold the page output var links = ''; // Get the userid from the script on the page var uid = unsafeWindow["_USER_ID"]; // Page number variable for output var pages; // kick off the collection function getAllStarred() { // Set the text for the message box document.getElementById('GRAS_MSG').innerHTML = 'Getting links.'; // Show the message box document.getElementById('GRAS_DIV').style.display = 'block'; // Initialize the page variable pages = 1; // Begin the new links page links = '<head><title>Google Reader Starred Entries</title></head><html>' + // '<input />' + // '<input />' + '
' + '
    '; // Make the initial request // The 'continuation' string isn't needed for the first request. googleRequest(''); } // Perform the request for the starred item // Param: c // This string is used as an offset if the initial // request didn't get all of starred items // function googleRequest(c){ // Generate a request to get the list (xml) of starred items GM_xmlhttpRequest({ method: 'GET', url: 'http://google.com/reader/atom/user/' + uid + '/state/com.google/starred?n=250'+c, headers: { 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3', 'Accept': 'application/atom+xml,application/xml,text/xml', }, onload: collectAllStarred }); } // This function parses the response object to get the starred items. // If it finds a continuation parameter, it will call googleRequest // again until all of the starred items are collected. function collectAllStarred(responseObj) { document.getElementById('GRAS_MSG').innerHTML = 'Collecting links, Set ' + pages++; // Create a new parser var dp = new XPCNativeWrapper(window, "DOMParser()"); var parser = new dp.DOMParser(); var DOM = parser.parseFromString(responseObj.responseText, "application/xhtml+xml"); // Grab all of the entries var entries = DOM.getElementsByTagName('entry'); // Loop through all of the entries for(var i = 0, len = entries.length; i < len; i++){ // Grab the link URL var link = entries[i].getElementsByTagName('id')[0].getAttribute('gr:original-id'); if (!(/^http/.test(link))) { link = entries[i].getElementsByTagName('link')[0].getAttribute('href'); } // Grab the item Title var title = entries[i].getElementsByTagName('title')[0].childNodes[0].nodeValue; // Grab the feed name var feedtitle = entries[i].getElementsByTagName('source')[0].getElementsByTagName('title')[0].textContent // Add a new link to the page. links += '
  • ' + title + ' from ' + feedtitle +'
  • \n'; // Note that other fields can be displayed here as well. } // Check for continuation if(DOM.getElementsByTagName('gr:continuation')[0]){ googleRequest('&c=' + DOM.getElementsByTagName('gr:continuation')[0].childNodes[0].nodeValue); }else{ // If there is no continuation, then we have finished and it is time to display the page // tidy up the page. links += "
</html>"; // Write a new document (another window) var d = open().document; d.write(links); d.close(); // Hide the message box document.getElementById('GRAS_DIV').style.display = 'none'; } } // function pushToDelicious() // { // } // function showDeliciousForm() // { // alert('Clicked'); // document.getElementById('GRAS_ACTIONFORM').innerHTML = // '<form><label>Your del.icio.us ID:</label>
<input />' + // '
<label>Your del.icio.us Password:</label>
<input />' + // '
<label>Del.icio.us tags to use:</label>
<input />' + // '
<input />'; // } // function unstarLinks() // { // alert("When I wish upon a star...."); // } // Add a small messagebox to indicate that the script is working var msg = document.createElement("div"); msg.innerHTML = '

' + 'YOUR TEXT HERE ' + '

'; // Add it at the end of the page. document.body.appendChild(msg); if(document.getElementById('selectors-container') && document.getElementById('star-selector')) { // Create a list item to add to the regular google links var starlink = document.createElement("li"); starlink.setAttribute("class", "selector"); starlink.setAttribute("id", "all-starred-link"); // Add the text starlink.innerHTML='All Starred'; // Create a listener to handle the click event starlink.addEventListener('click',getAllStarred,false); // Add the link to the Google Reader page. document.getElementById('selectors-container').insertBefore(starlink, document.getElementById('star-selector').nextSibling); } // if(document.getElementById('GRAS_DELICIOUS')){ // document.getElementById('GRAS_DELICIOUS').addEventListener('click',showDeliciousForm,false); // } // if(document.getElementById('GRAS_UNSTAR')){ // document.getElementById('GRAS_UNSTAR').addEventListener('click',unstarLinks,false); // }</form>
 
Abhay Singh User

Thanks Mark.

 
Mark Hutton Scriptwright

Script was only getting the first 250 for me.. it seems the "continuation" element is now called "gr:continuation".. fixing this in the script gets it working again

Now I have extracted all my 7530 starred item links from Google Reader :)

Edit: Some of the extracted links are of the form "tag:" which I understand is something to do with Atom, however I needed real links - adding the following gets the real link in most cases I have seen where "tag:..." is used:

find:

	var link = entries[i].getElementsByTagName('id')[0].getAttribute('gr:original-id');

add the following after the above line:

	if (!(/^http/.test(link))) {
		link = entries[i].getElementsByTagName('link')[0].getAttribute('href');
	} 

 
Abhay Singh User

Well ok, Now I have my 3000+ links, I would like to "unstar" them and make room for new "stars" . Would you know how to this this? I think some tweak in this script should be able to handle this well.

 
Richard Osba... User

Ah, just applied my own patch to the office computer and it wasn't quite right. Forget to escape the angle brackets around the "All Starred" link so the forum removed them. I modified the patch below so you might want to patch again. It's a cosmetic issue that meant "All Starred" wasn't being rendered as a link - but would still work when clicked.

 
Abhay Singh User

Super Richard. I owe you a beer!

 
Richard Osba... User

Noticed it had stopped working recently. Had a crack at patching it myself, edit the script and look for the line that starts if(document.getElementById('broadcast-selector').parentNode) {
(line 176 near the end) and replace that whole if {} block with:


if(document.getElementById('selectors-container') && document.getElementById('star-selector')) {
// Create a list item to add to the regular google links
var starlink = document.createElement("li");
starlink.setAttribute("class", "selector");
starlink.setAttribute("id", "all-starred-link");
// Add the text
starlink.innerHTML='<a href="#">All Starred</a>';
// Create a listener to handle the click event
starlink.addEventListener('click',getAllStarred,false);
// Add the link to the Google Reader page.
document.getElementById('selectors-container').insertBefore(starlink, document.getElementById('star-selector').nextSibling);
}

 
Abhay Singh User

Doesnt seems to work with new reader :(

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel