mercredi 28 janvier 2015

How to execute a Greasemonkey script on every infinite scrolling event in a Twitter conversation?


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 in order to see the rest of replies.


How can I make my script executed on every infinite scrolling event (on every Mousewheel down or PgDn or Down arrow ↓ keypress)?


Someone has kindly suggested:



Try inspecting the code in FF devtools debugger (right click the code and choose 'prettify source') to see how infiniteScrollWatcher is triggered



So, I suppose that I should bind an event listener to this function using EventTarget.addEventListener, but I don't know how (this function is way too advanced for me).


The prettified source of that function is:



function infiniteScrollWatcher() {
var a = 0,
b = 1;
this.checkScrollPosition = function () {
var c = this.webkitFullscreenElement();
if (c && this.node != c && !c.contains(this.node)) return;
var d = this.$content.height(),
e = !1;
this.inTriggerRange(a) && (d > this.lastTriggeredHeight || this.lastTriggeredFrom(b)) ? (this.trigger('uiNearTheTop'), this.lastTriggerFrom = a, e = !0) : this.inTriggerRange(b) && (d > this.lastTriggeredHeight || this.lastTriggeredFrom(a)) && (this.trigger('uiNearTheBottom'), this.lastTriggerFrom = b, e = !0),
e && (this.lastTriggeredHeight = d)
},
this.inTriggerRange = function (c) {
var d = this.$content.height(),
e = this.$node.scrollTop(),
f = e + this.$node.height(),
g = Math.abs(Math.min(f - d, 0)),
h = this.$node.height() / 2;
return e < h && c == a || g < h && c == b
},
this.lastTriggeredFrom = function (a) {
return this.lastTriggerFrom === a
},
this.resetScrollState = function () {
this.lastTriggeredHeight = 0,
this.lastTriggerFrom = - 1
},
this.webkitFullscreenElement = function () {
return document.webkitFullscreenElement
},
this.after('initialize', function () {
this.resetScrollState(),
this.$content = this.attr.contentSelector ? this.select('contentSelector') : $(document),
this.on('scroll', utils.throttle(this.checkScrollPosition.bind(this), 100)),
this.on('uiTimelineReset', this.resetScrollState),
this.on('uiSwiftLoaded uiPageChanged', this.checkScrollPosition)
})
}




Aucun commentaire:

Enregistrer un commentaire