« first day (762 days earlier)      last day (677 days later) » 

4:51 AM
@HenryEcker the only reasonable one I am aware of is running the userscript as soon as possible and registering a listener for the load event on window - hsn't failed me once so far in terms of having StackExchange defined. One might also want to register a callback for StackExchange.ready hook just in case
 
5:09 AM
@RyanM If only copy-pasting were the only thing it broke...
@OlegValteriswithUkraine I mean, yeah. And also if that made the entire person cute. Because isn't that how it works?
 
@CodyGray They can break our tools, but they can't break our spirit?
 
@CodyGray I'd settle on the glasses being cute, but not the whole person
 
@RyanM Don't lie to me.
@OlegValteriswithUkraine But then what's the point of glasses?
@OlegValteriswithUkraine There's one: it doesn't integrate well with existing tools/code/infrastructure. Well, when I say "well", I mean "requires at least one extra step".
For example, double-beep wrote an add-on to one of the Charcoal userscripts in TypeScript, which means that his additions cannot be backported directly to the official Charcoal userscript.
 
@CodyGray are you having an existential crisis?
@CodyGray actually, it can be backported: compile to the same target with the preserve comments flag on, and it will be 100% compatible :)
 
You mean, compile the TS source to the same dialect of JS used by the original, then copy-paste that in?
 
Yeah, that'd possibly work. But: (1) that's an extra step that requires a development environment so cannot be done by the maintainer who doesn't know or use TS, and (2) it only goes in one direction, so the benefits of TS are lost at that point (just like a hamburger doesn't have legs and can't walk around).
 
or just add TS to Fire - TS can compile JS to JS (or, in other terms, it does not touch them)
 
Well, you can always do things by adding more tools and complexity.
But that's cheating. Maybe the maintainer of Fire doesn't want all of that extra work.
 
well, if npm i -D typescript is too much work, I agree it's a downside :)
@CodyGray (1) is not applicable as any JS code is 100% valid TS code (unless strict mode or its parts are on)
 
That's great for going in the other direction
 
5:25 AM
there's only one true direction :)
 
North?
 
Northwest to TypeScript
when one goes from TS, things usually go south
 
5:40 AM
Which is precisely the direction we'd need to go in my scenario
 
if you mean it shouldn't have been the case in the first place - well, yeah, but it's a bit too late for that now. TS team is championing adding type hints to ECMA directly, though, so it's a start
 
6:36 AM
Well, no
I mean that the scenario I was describing was integrating code that someone wrote in TS into a codebase consisting of JS.
 
aaand we officially looped back to start :) npm i -D typescript + copy-paste
 
 
5 hours later…
11:42 AM
@OlegValteriswithUkraine No sorry. I really meant the instant StackExchange becomes defined in the global space. I need to run a UserScript before the welcome back message call. But this is difficult because it comes in the server-side rendered HTML in the form of a <script> in the head almost immediately after the stub is brought in.
<head>
    <!--- title, meta, links, etc -->
    <script src="https://cdn.sstatic.net/Js/stub.en.js?v=e700279bb0cc"></script>
    <!--- more meta, links, etc -->
        <script>
            StackExchange.ready(function () {

                StackExchange.using("postValidation", function () {
                    StackExchange.postValidation.initOnBlurAndSubmit($('#post-form'), 2, 'answer');
                });


                    StackExchange.helpers.showFancyOverlay({ message: 'Welcome back! If you found this question useful,\u003cbr/\u003edon\u0027t forget to vote both the question and
I need something to run between StackExchange being defined and this <script>. So what I've been doing is running at document-start, but sometimes StackExchange isn't defined at that time. Running at document-end, but not using readyhas worked fairly well, but I don't know if it will always work.
 
Have you considered just disabling showFancyOverlay? What would be the casualties?
 
This is exactly what my script is attempting to do. But again my code that replaces showFancyOverlay is running after theirs is running. Once the element is already in the DOM it doesn’t matter that the function was removed from StackExchange
 
12:36 PM
To be clear, you want to kill that "Welcome back!" message?
 
He doesn't want to welcome it back
 
You can have a workaround that is slightly kludgy but guaranteed to work: listen for the message trying to show up in the DOM and close it immediately. Although, I'm not sure if it will flicker in that case and if that can be directly prevented.
 
1:05 PM
@HenryEcker Hmm, there is also another sort of workaround. Might match closer to what you want to do. You can create setter for StackExchange on window. This will allow you to intercept assignments to it and act just before it happens. You can run some code, then self-destruct that computed property, then assign the real one: jsbin.com/pipibodeku/1/edit?js,console
 
@HenryEcker so... do you need to run it before the window load event is fired? If you run at document-start but wrap the script's code in an event listener, then it is guaranteed (at least I do not remember a single instance where the object is not defined at this point) to be available
An alternative is to create a promise with setInterval / recursive setTimeout under the hood and resolve once the global appears in the scope
 
However, that works if you do direct assignment window.Foo = something But not if you define a function: function Foo() {} bypasses that setter.
I've not checked how StackExchange is added to window, so might not exactly work.
 
@VLAZ Yeah. This was my initial approach. Interestingly, window.StackExchange is set to an empty object about 4 times before it actually contains useful information (apparently).
So the immediate delete thing doesn't work. I had something working where I waited for Object.keys(newValue).length !== 0 before deleting window.StackExchange, but it then just got a bit convoluted
 
Yeah, I was just looking at the code. They are doing the AMD approach window.Foo = window.Foo || {} - this is an older approach but it checks out.
 
@HenryEcker yet another approach is a mutation observer wrapped into a promise constructor pending until the element you need to remove appears in the DOM. I've come to like DIY'ing a version of Puppeteers waitFor
 
1:12 PM
@OlegValteriswithUkraine I keep needing a waitFor but deciding to take a different approach when I realise I have to DIY it.
I mean, it's not too much. And I just need one that I can reuse.
But it usually comes up for really small things, so I can't justify the effort for it just to solve a relatively simple task. I really should just write one I can drop in when needed. It's not too hard. And once it's there, I'd probably find more applications for it.
 
 
1 hour later…
2:22 PM
@HenryEcker This is/was the thing that I was trying to find a less awkward way to solve. But it seems like this is probably a valid approach to solve this problem in any case...
@OlegValteriswithUkraine I'm was trying to make something a bit more durable (hopefully). I'm proxying the helper functions to just not run on certain inputs. I'm doing this so renaming a class or something trivial won't be breaking the functionality of it.
 
2:35 PM
@HenryEcker What you currently have seems to be the most reliable thing. At least, I can't think of how to improve it meaningfully.
 
Welp. Ugly and working is better than not working and pretty. Thanks for taking a look :)
 
Yeah. I agree it's ugly but it's also how things are. If you're trying to monkeypatch something, it's inevitably going to not look great.
 
I suppose... Almost everything else works nicely with just StackExchange.ready. It's just where they inject the welcome banner into the HTML they ship to me. If it was added to the end of the body I wouldn't have to deal with any of it...
It's almost like they don't want people to suppress that message or something XD
I have to say though I've really enjoyed not having the 'You haven&#39;t voted on questions in a while; questions need votes too!' messages. I actually forgot they were a thing until I needed to use a computer without UserScripts
 
3:12 PM
0
Q: SE Toast/FancyOverlay Suppressor

Henry EckerStackExchange provides a variety of notices and toast messages, but sometimes they can get a bit annoying for experienced users. This UserScript adds a Proxy to the two helper functions which cause these popups and conditionally runs the function or not based on the arguments. Preview Nothing to ...

 
3:39 PM
@HenryEcker It's still not fixed?!
 
4:12 PM
@VLAZ no it renders correctly. There’s a config {rawHTML: true} that makes it render correctly. But that’s how the message arrives from the server.
 
I see...
It also starts to explain why these messages were broken for such a long time.
Read: more than a couple of days.
 
 
2 hours later…
5:50 PM
@HenryEcker heh, well, till the next time they break the API :) Although they did promise not to...
@VLAZ well, at this point I have a full library for those, so I am just copy-pasting, and there are plans to add them to common helpers shared by all userscripters repos
@HenryEcker that's an interesting approach
 
@VLAZ So this is the call that is made StackExchange.helpers.showToast('You haven&#39;t voted on questions in a while; questions need votes too!', {useRawHtml: true}) I was close on the attribute name (I was just doing that from memory earlier).
@OlegValteriswithUkraine I was hoping it would be more durable than DOM manipulation. Though only time will tell.
@OlegValteriswithUkraine I'm sure you can see why I was trying to see if there were other options :)
@HenryEcker It's also helpful because this way the Proxy is set up. You can do things like make certain toasts non-transient or increase/decrease the duration etc.
 
6:05 PM
@HenryEcker it seems to work at the first glance, though - I'd also call it elegant. The only issue here is when SE eventually changes the helpers, the script is screwed, but... on the other hand, it's as, if not more, likely they change the CSS classes and/or generated HTML, so...
 
Yeah. Monkey-patching is never going to be fully stable. I did want to try something new/different than the other things I've done. If I'm going to put in the effort I might as well learn something new :)
 
heh, yea, that's the life of a userscript author on SE - we might as well just accept the chaos and expect things to break once in a while. I just hope they make good on the promise not to break the API of commonly used helpers, and IIRC those are tapped into often. But one never knows...
 

« first day (762 days earlier)      last day (677 days later) »