Hey there,
I'm writing a script in Greasemonkey that uses jQuery + Livequery +
Lowpro. The script is an audioscrobbler script for muxtape.com, and
provides a link to allow a user to scrobble a song.
So far I've managed to get it as far as creating the link on the page,
and passing another attach to the link once created. It seems to
work, as the initialize function for it does the CSS change, but the
onclick seems to be ignored.
Here is what I have cut down (as there is a lot of included library
code):
ScrobbleClick = jQuery.klass({
initialize : function(options) {
this.element.css({'padding-left':'10px;'});
},
onclick: function(){
console.log('moo');
GM_xmlhttpRequest({
method: 'POST',
url: this.element.attr('href'),
headers: {
'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
'Accept': 'application/atom+xml,application/xml,text/xml',
},
onload: function(responseDetails) {
console.log(responseDetails);
}
});
return false;
}
});
ScrobbleSong = jQuery.klass({
initialize : function(options) {
var el = jQuery(this.element);
/* Some code in here where I create the url */
el.append('<a href="'+url+'" class="scrobble">Scrobble This</a>');
el.find('.scrobble').attach(ScrobbleClick);
}
});
setTimeout(function(){
jQuery('.song').each(function(){
jQuery(this).attach(ScrobbleSong);
});
}, 3000);
What the script does is wait until a auth request has been made (not
shown here) which is successful, I attach the link to the div. Then I
bind the ScrobbleClick. As I've said, the initialize works, so it
must know the element is there, however it ignores the onclick
function.
Anyone any ideas????