1

I am writing Tampermonkey Userscript to help autoswipe profiles.

Problem is that I cannot click on vote buttons - standard method to be used to click, being: document.querySelector(button_selector).click(); does not work here. No error message is there. Peaking with Firefox Developer Edition, the buttons (divs) have only mouseenter and mouseleave events.

So I thought of using keyboard shortcuts (pressing 1 = liking profile, pressing 2 = disliking/skipping). With solutions from topics like this - Is it possible to simulate key press events programmatically?. Also does not work.

The only thing that seems to be potential culprit is isTrusted event - read more.

When I try to examine the code for keydown or keyup events (from Developer Console -> Elements -> Event Listeners), it looks like gibberish in source code, example:

//Partial code
  case "keydown":
  case "keyup":
     Cn(s, r, i)

//Function "Cn"
            function Cn(e, t, r) {
                var n = r.window === r ? r.document : 9 === r.nodeType ? r : r.ownerDocument;
                Sn || null == En || En !== X(n) || ("selectionStart"in (n = En) && vn(n) ? n = {
                    start: n.selectionStart,
                    end: n.selectionEnd
                } : n = {
                    anchorNode: (n = (n.ownerDocument && n.ownerDocument.defaultView || window).getSelection()).anchorNode,
                    anchorOffset: n.anchorOffset,
                    focusNode: n.focusNode,
                    focusOffset: n.focusOffset
                },
                bn && dn(bn, n) || (bn = n,
                0 < (n = Vn(yn, "onSelect")).length && (t = new dr("onSelect","select",null,t,r),
                e.push({
                    event: t,
                    listeners: n
                }),
                t.target = En)))
            }

Is there any way to detect what actually triggers voting yes-or-no?

And how to code it in JavaScript, to make voting for me, with potential hacks that Tampermonkey provides. I thought that maybe "unsafeWindow" would help here, but I am highly unsure if I understand concept of that.

1 Answers1

0

You can find the code being triggered on click by looking at Event Listener section of Chrome DevTools

See the screenshot below of this page. It shows the event listener registered on up-vote button on the question. You should generally look at the last one only in click event. All the other listeners are registered on container elements like document or body.

It may not give you the exact location of the code where event is registered, but it will be pretty close.

Event listener for vote button

Click on the source location link against the listener to open source code in Sources tab. You can now debug this script to find which function gets triggered on click. Source code may be minified, you can click on the prettify button to format it.

Here's what it looks like when I do it for up-vote button on this page. I first placed a break point then, used step-into (F11) to go in the function being called on click.

Break point

Actual function

11thdimension
  • 10,333
  • 4
  • 33
  • 71
  • That's basically what I did. But minified code does not help me at all. I did not use breakpoints and this does not really provide real solution (yet), how to write piece of code that will trigger correct action. `!b.repeat && G[b.keyCode] && this.a.postMessage([31, b.keyCode, "keydown" == b.type])`` I will try to find solution myself, but it feels like hitting my head on wall currently. – Fapka Master Oct 08 '22 at 18:18