0

I don't even know if my question is right, I mean, I couldn't say if it's a css button that doesn't let my code works. I want to load all comments of this news site.

As you can see, at the bottom of the page, the most 5 recents comments is opened and below them a button to load more comments. This button is what I intended to auto-click and I believe it's a css button.

As my attempt to click failed I tryied an alternate solution without success. The hidden comments are marked with the:

class="off"

class=off

When I remove this class on firebug, the comment instantly appears on the page, but I couldn't get it selected or founded with jQuery, when I tryied the following:

$("li").removeClass("off");

- Here is my fail code, which appears to never found the elements waited:

// ==UserScript==
// @name        globo coments
// @description globo coments
// @include     http://*.globo.com/*.html
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version     1
// @grant       GM_addStyle
// ==/UserScript==

function maisComents(jNode) {
        alert('???');
}

waitForKeyElements ("#glb-materia .widget widget-comentarios #boxComentarios .glbComentarios-lista glbComentarios-lista-recentes button .glbComentarios-botao-mais", maisComents);

- At the script tab of firebug you can see this:

<div id='boxComentarios'></div>
    <script type="text/javascript">
        glb.runner.push('comentarios', function(global, $) {
        var articleUrl = 'http://ego.globo.com/biquini/noticia/2013/11/marina-elali-exibe-boa-forma-de-biquini.html',
        slug = articleUrl.split('/').pop().split('.').shift(),
        hash = global.sha1(slug);
        $('#boxComentarios').comentarios({
           'uri': '/jornalismo/ego/biquini',
           'url': articleUrl,
           'titulo': slug,
           'idExterno': hash,
           'exibeTeaserComentarios': true,
           'qtdComentariosNoTeaser': 5,                 
           'botaoComentario': {'topo': '.listar-comentarios-topo'}
    });
});
</script>
</div> 

Which in this line, is set the numbers of comments

'qtdComentariosNoTeaser': 5,    

- I believe there is many ways to load all comments, but I couldn't find any solution. Could you please anybody help me?

Commentator
  • 640
  • 1
  • 6
  • 22

2 Answers2

0

You can get all elements matching the class name of the button and store in an array. Then you can directly reference index in array and click. This may not be the best method, but it does click the button. Hope it helps.

Javascript to click the load more comments button:

var arrEle = document.getElementsByClassName('glbComentarios-botao-mais');
arrEle[0].click();

jQuery solution as requested:

$(".glbComentarios-botao-mais").click();
Christopher Ellis
  • 1,106
  • 1
  • 8
  • 12
  • The OP is using jQuery, therefore you should give a jQuery solution. A native JS solution _in addition_ is a useful bonus to those not using jQuery – Bojangles Nov 21 '13 at 18:50
  • Thanks for your reply, but it didn't work. I think the problem is that the comments is AJAX and need waitKeyForElements to work, which is not being actived. In my code I used alert to check that and the alert never came. Finding the object in the DOM had been one of the issues. – Commentator Nov 21 '13 at 18:56
  • Yes, the comments are initally loaded using AJAX and therefore when you make this call the elements are not present in the page. Unless `comentarios()` has a success event on which to call this, you're going to struggle. – jammykam Nov 21 '13 at 19:07
0

You are not going to be able to achieve what you need by clicking the button. There are "some" hidden comments, and clicking the button once does reveal the initial hidden comments, but addition clicks make an AJAX call to load more comments, calls to:

http://comentarios.globo.com/comentarios/%40%40jornalismo%40%40ego%40%40biquini/bb7ac85e446f9d568d9047886db0f0665b1753a1/http%3A%40%40%40%40ego.globo.com%40%40biquini%40%40noticia%40%402013%40%4011%40%40marina-elali-exibe-boa-forma-de-biquini.html/shorturl/marina-elali-exibe-boa-forma-de-biquini/2.json

3.json, 4.json etc

Did you try removing the line 'qtdComentariosNoTeaser': 5, or setting it to a really high number like 9999

jammykam
  • 16,940
  • 2
  • 36
  • 71