Tuesday, July 1, 2008

Updated Script!

I know something you guys wanted was an OmniMents count in Google Reader. Sorry kiddos... No cross domain ajax. It took me forever to figure that out. I have found a workaround by using an iframe... but I think that might cause some strange side effects. Play with it and see. I haven't gotten the formatting right and it doesn't autoupdate yet, just when the page reloads. But here is the new script. Just open the current script in grease monkey and copy this new one in and save it. This one also opens the OmniMents page in a new tab, per Rogers request. And the login is fixed... mostly.

// ==UserScript==
// @name Google Reader OmniMents Link
// @description Adds a OmniMent to the end of the action row
// @namespace http://omniments.appspot.com
// @include http://www.google.tld/reader/*
// @include https://www.google.tld/reader/*
// ==/UserScript==


var entries=document.getElementById("entries");
if(entries)
entries.addEventListener('DOMNodeInserted', function(event){nodeInserted(event);},true);


function nodeInserted(event){
if (event.target.tagName=="DIV"){
if (event.target.className === "entry-actions"){
// List mode
var linkbar=event.target;
} else if (event.target.firstChild && event.target.firstChild.className=="card"){
// Expanded mode
var linkbar=event.target.firstChild.firstChild.childNodes[2].childNodes[1].firstChild;
} else
return;

var parent= linkbar;
while (parent.tagName != "TBODY") {
parent= parent.parentNode;
}

var link = parent.getElementsByClassName("entry-title-link")[0].getAttribute('href');
var site = parent.getElementsByClassName("entry-source-title-parent")[0].getElementsByTagName("A")[0].firstChild.nodeValue;
var title = parent.getElementsByClassName("entry-title-link")[0].firstChild.nodeValue;
var OMLink ="http://omniments.appspot.com/display.html?article=" + link;
var span = document.createElement("span");
span.className = "OmniMents";
var a_link = document.createElement("a");
a_link.href = OMLink;
a_link.title = "OmniMents For: " + title;
a_link.setAttribute('style','text-decoration:none;padding-right:10px;margin-right:10px; background: center right no-repeat;');
a_link.setAttribute('target', '_blank');
a_link.appendChild(document.createTextNode("OmniMents"));
span.appendChild(a_link);
var iframe = document.createElement("iframe");
iframe.setAttribute('src', 'http://omniments.appspot.com/count.html?article=' + link);
iframe.setAttribute('frameborder','0');
iframe.setAttribute('width','20');
iframe.setAttribute('height','20');
iframe.setAttribute('vspace','0');
iframe.setAttribute('hspace','0');
iframe.setAttribute('marginwidth','0');
iframe.setAttribute('scrolling','no');
linkbar.appendChild(span);
linkbar.appendChild(iframe);
}
}
Feel free to play around with the script if you think you can make it look better.

My current list of features to be added (in no particular order):
  • OmniMents popup in a bubble in Google Reader(I think I can do this with an iframe too)
  • Build a firefox extension for OmniMents so you guys don't have to update your scripts everytime I make a change
  • OmniMents favicon and logo. (If anyone has artistic ability and wants to take a shot at this, go for it.)
  • Style the OmniMents page
  • Add threading and ratings to the OmniMents
  • Ajax and web 2.0 -ify anything I can
  • Home page for OmniMents that shows hot and recent threads, and the ones you commented on recently
  • Any other ideas guys? Let me know
I know there is a lot of work ahead and I appreciate you guys using the app and letting me know how to improve it.

Thanks!

No comments: