« first day (730 days earlier)      last day (935 days later) » 

04:50
@OlegValteriswithUkraine The "OMG", the "squeee", or both? :-)
@richardec @OlegValteriswithUkraine Yes, that's exactly what I do in order to retrieve the main site fkey from a chat context. See: github.com/SOBotics/UserStalkerHelper/blob/master/…
@OlegValteriswithUkraine heading to a bar in 4-5 hours... "12 hours later"... should we send help? :-p
user17242583
05:14
@CodyGray Thank you! I used a regex to parse the fkey out of the HTML (yeah...), but I like the jQuery approach better. As for the function name...getMainSiteFkey is almost identical to what I used - getSOMainSiteFkey :P
user17242583
@CodyGray It's annoying and odd, but beyond that it's not a major inconvenience for me, so no pressure :)
05:27
@richardec Yeah, opinions about jQuery aside, I tend to use it heavily in userscripts for SO, since it's already there.
It would be trivial to do this in pure/vanilla JS, too. You're just fetching the input element with the appropriate name (fkey), so you can use element.querySelectorAll.
That's virtually a direct equivalent of jQuery's find. So, in this case: element.querySelectorAll('input[name="fkey"]')
 
2 hours later…
07:59
@OlegValteriswithUkraine no it's not safe to rebuild, there are also some local commits I haven't pushed to GH yet
 
2 hours later…
09:35
hmm.. @oleg migrating from name-/desc- doesn't work in ARC: TypeError: Cannot read properties of undefined (reading 'join') from L1423
same error if I clear the userscript's storage
 
2 hours later…
11:55
[mumbles some profanities incoherently]
@double-beep I see, I'll install the original ARC again, save some comments, and try to interop
this is a cursed PR :)
@double-beep glad I asked then! so... you have it under control then? I'll just keep it rebuilt for me locally till the update
@richardec thanks, certainly :)
@CodyGray both :)
@CodyGray I wouldn't mind an extraction team xD Joking aside, yeah, 4-5 hours stretched a bit
@OlegValteriswithUkraine Greetings to you, too! :-)
[enthusiastically mumbles some more profanitities] :)
dang it, it's 3PM already
12:15
I think you're supposed to come home from the bar at 3 AM, not 3 PM.
Ah, I see. And then you did 12 hours of sleeping?
So why are you spewing profanities?
Alarms were supposed to go off at 12PM :) well, I guess they did
 
6 hours later…
17:54
poing
@richardec hmm, works fine for me (also, sorry 'bout underestimating how long will it take for me to boot back up :)), can you post the source you are using?
poing
18:05
@double-beep I fixed at least 1/2 of the issue after installing the old ARC again and starting fresh, but I had a different problem than you, so I am still looking into it
user17242583
@OlegValteriswithUkraine Inside an async arrow function, I call CHAT.addEventHandlerHook with another async arrow function as the handler. Inside that I proceed to vote on/flag the posts in the message based on certain criteria
I mean... can you show it? :)
user17242583
and here's the code
```
CHAT.addEventHandlerHook(async (event) => {
if (event.event_type != 1) {
return;
}

let match;
if (match = event.content.match(/@natty feedback (?:https?:\/\/)?stackoverflow.com\/a\/(\d+)(?:\/\d+)? (\w+)/i)) {
const [, answerId, status] = match;
if (status.toLowerCase() === "tp") {

if (!store[answerId]) {
await downvote(answerId);
await flag(answerId, FlagTypes.NAA);
console.log(
`Downvoted https://stackoverflow.com/a/${answerId} and flagged as NAA (from Natty; tp'd by ${event.user_name}[${event.user_id}])`
user17242583
(sorry for the ugly formatting)
user17242583
18:07
If you need the whole script I'll send it...it's just a bit longer than that ;)
user17242583
It works great except that no message show up in the UI. The UI even says "The last message was posted 16 hours ago." at the bottom...!
@richardec ah, no need
hmm, let me clarify a little - so after you hook the listener, new messages stop appearing in the normal chat UI?
user17242583
Yes. If I disable that user script, and on pages where it doesn't activate, the messages flow in like normal.
hmm
poing!
hmm
yeah, let's see your full script
right now I don't see any reason for this to be happening
at least what concerns your code
and it works well in Chrome, W10
user17242583
```
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://chat.stackoverflow.com/rooms/111347/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest

// ==/UserScript==

(async () => {
console.log("AutoDVSOBotics listing to messages");

const store = {};
user17242583
18:18
Sorry, I didn't see those msgs. There you go :)
user17242583
I'm using FF, macOS 12.1 btw, if that helps
thanks! hmmm, looks like nothing is out of the ordinary
I'll try testing on FF, W10, but can't do macOS
my first guess was that maybe you had a stopPropagation or similar, and it managed to register before chat's own handling of message events (if it even relies on it, haven't inspected the source in a while), but it does not seem so
user17242583
Okay, thank you anyway. I'll play around with a few things...as I said, it's not too much of a concern because reloading the page loads the newest messages...
post something in 5-10 secs please
user17242583
okay
user17242583
18:29
dang, I didn't see your message
aha!
it's a chat bug!
so
the callback can't be async
because in the source code, there is a guard
user17242583
really! I wondered if that was the problem.
that treats those callbacks as synchronous and does something like:
if( callback(a,b,c) ) { return; }
since async callbacks always return a promise, it's always truthy, and, well, here you go :)
suggestion: make the callback sync and put an async IIFE inside it
user17242583
Great idea. I'll do that. Thank you! That was interesting.
your catch really shows that chat hasn't been touched since 2016 :)
user17242583
18:33
I'll add a note about this to Makyen's post.
that seems to be a genuinely problematic bug
user17242583
That's terrible. What happened then that caused that?
a developer happened :)
if (i[o](e, s, a)) return;
^ this is the offender
user17242583
What I find weird is...why do they cancel everything if the function returns something?
basically, all registered callbacks are run in a loop
¯\_(ツ)_/¯
it's weird to me too
there is no documentation on chat source, though, and it is only available as minified, so who knows
I suspect the developer wanted to do if (i[o](e, s, a)) continue;
Or that they imagined they might need a circuit breaker callback
other than that - it does, indeed, look rather pointless
@richardec I think it's faster to just ping Makyen :)
I have to note that a better advice would be "make sure the function does not return a truthy value"
Because any such will break chat
However, I can neither review nor improve it :) the subset of 2k+ users on stackapps is incredibly small
user17242583
Oh, much better idea. But oops...Glorfindel just approved that edit...so I'll try another one
Yeah, they have an advantage of having a binding vote :)
user17242583
If you still think Makyen should know, I'll ping him
user17242583
18:52
Thank you @Oleg; it's working perfectly now.
@richardec I am pretty sure they know already :) most likely you'll also get a detailed lecture on why it happens (which is a good thing, although it might look like I am complaining :))
In any case, now that the edit is approved, they'll see it either way
@richardec NP!
19:22
@double-beep when you have time, can you also add a feed, please? there was a question that slipped under radar
@OlegValteriswithUkraine further chat event processing, dang it
@OlegValteriswithUkraine I wouldn't call it a bug. That's fairly standard operating procedure when you're wanting callbacks to be able to let you cancel events. It's largely synonymous with how events work in JavaScript, so "normal".
@Makyen yeah, I am just not sure any truthy value returned essentially cancelling the event is not a problem - maybe I am misremembering, but event listeners can safely return promises
@richardec Pinging for an edit of any notable length is redundant. The owner of the post is notified about edits, unless the edit is "trivial" (which doesn't actually mean they are really trivial edits, just that the edit fits what SE's system defines as "trivial", which I don't agree with).
@OlegValteriswithUkraine Yeah, it would be better, IMO, for the check to be === true, but, then, chat predates Promise and async function(), so...
@Makyen yeah, figured it's likely just due to the age of the chat codebase... I only call it a bug as it is unexpected behavior when passing an async function as the callback unless you know what's going on behind the scenes
what I am unsure about is why not just extend EventTarget?
* not necessarily in the sence of literally extending as I realise that would exclude IE at the time
^ that.
19:35
Yeah, more like at least "model" it according to the interface. Although it was likely the intention, just with an assumption that implicit conversion should be fine turning out to be flawed as time passed
It was substantially easier to just roll their own with CHAT.addEventHandlerHook(callback). It's literally just a few statements (8 statements: an IIFE, define a [], 2 function definitions with one statement each, and a for loop with 1 statement) for everything.
Other code even get access to the call queue and directly manipulate it (for example put itself first, or remove something you know you're incompatible with; this is both a positive and negative, depending on how you look at it). OTOH, I agree that a test for truthy there, rather than === true is problematic, but it's certainly not the worst thing they did. :;
@Makyen yeah, just a bit weird they went with truthyness check
@Makyen huh, sometimes I wish there was something like preprendEventListener
@OlegValteriswithUkraine It was simple and easy and really didn't matter all that much at the time, given that async function() was years away and they really weren't designing it for extensibility.
@OlegValteriswithUkraine Yeah, there are times when that would be convenient, but then you'd have to account for it being used by page scripts when writing a userscript or content script, which would be a bit of a pain.
19:50
@Makyen yeah, sure, I understand the line of reasoning, just oh, well...
I wouldn't mind if it was something which was only available to content scripts (i.e. only available to scripts running in a higher security context than a page script).
@Makyen guess so - kind of a "a man can dream" thing :) As with getEventListeners
@OlegValteriswithUkraine Yeah, that would be really nice. :;
devtools constantly remind me of this :) at least a readonly collection would be very nice
20:36
cont: @double-beep - I think I seem to know why your issue with the interop happens. I was pondering whether to default targets to an empty array if missing, but ended with "nah, seems like all bases are covered", which seems to, well, not to be the case :)

« first day (730 days earlier)      last day (935 days later) »