Search code examples
jquerygoogle-chromeuserscriptsimgurtampermonkey

Tampermonkey script for Imgur


I'm wanting to make what should be a quick comment upvote script for Imgur. What I'd like to do is insert a button while browsing the imgur gallery "http://imgur.com/gallery/*" that will upvote every comment on that particular page. It should be as simple as grabbing all the upvote links by class and writing a function to iterate through them all and using jquery click(), but the problem is the comments are loaded via ajax after the page has been loaded, so the html elements are not in the DOM source. Is what I want to do still possible?

I have 8+ years of web development/programming experience but I've never written a userscript before. Thanks in advance for all your help!


Solution

  • The HTML elements are injected into the DOM through AJAX, which makes them available in the DOM when the document is finished loading, so you can very simply write a script which runs AFTER the document has completely loaded.

    $(document).ready(function() { $(".comment .arrow.up").click() });
    

    PS: UPVOTES FOR ALL!