Skip to content

Commit

Permalink
* fix error on getting item from GoogleReader (GoogleReader + Tombloo)
Browse files Browse the repository at this point in the history
Fix get_current_item function not to raise error.
  • Loading branch information
Constellation committed Jan 19, 2009
1 parent 6cdce25 commit c352b28
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions greasemonkey/googlereadertombloo.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ window.addEventListener('load', function(e){
}, false);

function share(){
var item = new get_current_item();
var item = get_current_item();
if(!item) return;
// for Tombloo
var ctx = update({
document : doc,
Expand Down Expand Up @@ -84,13 +85,28 @@ function addClass(e, cl){
: (e.className = cl);
}
function get_current_item(){
var item = {
parent: null,
body: null,
target: null,
feed: {
channel: {
link: null
}
}
}, link;
try {
this.parent = $x('id("current-entry")/descendant::div[contains(concat(" ", normalize-space(@class), " "), " entry-container ")]');
this.body = $x('id("current-entry")/descendant::div[contains(concat(" ", normalize-space(@class), " "), " item-body ")]');
this.target = $x('id("current-entry")/descendant::a[contains(concat(" ", normalize-space(@class), " "), " entry-title-link ")]');
this.feed = { channel:{ } };
this.feed.channel.link = decodeURIComponent($x('id("current-entry")/descendant::a[contains(concat(" ", normalize-space(@class), " "), " entry-source-title ")]').href.replace(/^.*\/(?=http)/, ''));
item.parent = $x('id("current-entry")/descendant::div[contains(concat(" ", normalize-space(@class), " "), " entry-container ")]') || null;
item.body = $x('id("current-entry")/descendant::div[contains(concat(" ", normalize-space(@class), " "), " item-body ")]') || null;
item.target = $x('id("current-entry")/descendant::a[contains(concat(" ", normalize-space(@class), " "), " entry-title-link ")]') || null;
link = $x('id("current-entry")/descendant::a[contains(concat(" ", normalize-space(@class), " "), " entry-source-title ")]') || null;
if(link && link.href) item.feed.channel.link = decodeURIComponent(link.href.replace(/^.*\/(?=http)/, ''));
if(!item.parent || !item.body || !item.target || !item.feed.channel.link){
throw 'get_current_item error';
} else {
return item;
}
} catch (e) {
alert(e);
return null;
}
}

0 comments on commit c352b28

Please sign in to comment.