Frage

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!

War es hilfreich?

Lösung 2

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!

Andere Tipps

This ended up working for me thanks to Ashwin for your help!

// ==UserScript==
// @name       Imgur - Upvote all comments
// @namespace  http://mydomain.com/
// @version    0.1
// @description  inserts a button into the html of the Imgur gallery page that allows you to upvote every comment
// @match      http://imgur.com/gallery/*
// @copyright  2013+, stackoverflow
// ==/UserScript==


$(document).ready(function() { 
    $('body').append('<input type="button" value="upvote all comments" id="upallcomments">')
    $('#upallcomments').css('position', 'fixed').css('top', 0).css('left', 0);
    $('#upallcomments').click(function(){ 
        $('[title="like"]').click();
    });
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top