Greasy Fork is available in English.

Discussões » Desenvolvimento

How to make all replies immediately visible in a Twitter conversation using Javascript?

§
Publicado: 10/12/2014

How to make all replies immediately visible in a Twitter conversation using Javascript?

I'm trying to make a greasemonkey userscript that will work in Twitter conversations
(colorize names,usernames and each 1st @reply).

When a Twitter conversation has a lot of replies (example link),
then opening such a link displays only 3 screenfuls of replies(the initial screenful+2 more)
-at least in my 1920x1200 display-
and then you have to scroll down manually (with page down or mouse) in order to see he rest of replies.

Is there a way to make all replies in a conversation immediately visible?

What I've found is to try to simulate (using jQuery) a few keypresses of 'PgDn' and then a keypress of 'Home' to navigate back to the page start based on this answer. So I tried this code in a new greasemonkey userscript (this supposedly simulates just 1 PgDn):

// ==UserScript==
// @name        Twitter - colorize tweets in conversations
// @namespace   rikkie
// @include     https://twitter.com/*/status/*
// @version     1
// @grant       none
// @require     http://code.jquery.com/jquery-2.1.1.min.js
// ==/UserScript==

var press = jQuery.Event("keypress");
press.ctrlKey = false;
press.which = 33;
$('window.onload').trigger(press);

but it doesn't work (and it doesn't generate any errors in Browser Console or Browser Toolbox in Firefox 33.1.1, neither).

Also, I looked in the Twitter API (my programming knowledge is limited, unfortunately) and couldn't find anything relevant.

Or, is there any other better way, without simulating keypresses?

woxxomMod
§
Publicado: 11/12/2014
Editado: 11/12/2014

Try inspecting the code in FF devtools debugger (right click the code and choose 'prettify source') to see how infiniteScrollWatcher is triggered, maybe you can simulate one of the conditions.

As for your code above you're using both jQuery and $, try using jQuery in both places. And maybe one pagedown isn't enough... And I think instead of $('window.onload').trigger(press); you should use $(document).ready(function() { $(document).trigger(press) }); (or use jQuery instead of $)

§
Publicado: 28/01/2015

Thank you very much for your detailed reply.

woxxomMod
§
Publicado: 17/04/2015

If you haven't solved the problem then try moving the "load more" html element into the visible part of the page, it works for dynamically loaded youtube comments (the code also sets element's visibility to 'hidden' temporarily in order to avoid flicker).

§
Publicado: 18/04/2015
Editado: 18/04/2015

Thank you.
Yes, I had quit my attempt...
I'll give it a try again based on your script (though it seems way too difficult/advanced for me).

woxxomMod
§
Publicado: 18/04/2015

Well, I was lazy to adapt it, but it's simple once you get the idea:

  1. find the load more button
  2. get its offset from the visible window part's top edge: getBoundingClientRect().top
  3. move the button into the visible part by setting its 'position' to 'relative' and 'top' property to the negative of the value from 2)
  4. wait for something to load
  5. either move the button back (by resetting its 'position' and 'top' properties) or do nothing if the button is deleted by twitter site

Publicar resposta

Faça o login para publicar uma resposta.