« first day (989 days earlier)      last day (450 days later) » 

12:41 PM
Hey, @OlegValter, what was it that you ended up doing with respect to saving configuration for userscripts?
I've been using a very simplistic method where I define constants at the top of the source file, which means that the user can either: (A) manually change the default value to the value of their choosing (which has the disadvantage of modifying the code, thus making updating difficult), or (B) set a value in localStorage that the script will pick up as the default.
E.g.:
// This option defaults to "false". Manually set it to "true" (or set the corresponding value
// in your Local Storage) to allow destroying spam accounts as fast as possible
// without multiple confirmations.
const underSpamAttackMode = (localStorage.getItem('SOMU-APMM.underSpamAttackMode') ?? 'false') === 'true';
Option (B) actually works extremely well, especially considering how simple it is. There are only two drawbacks that I can see: (1) it requires that someone have a basic level of comfort using the console to execute a localStorage.setValue(...) command (which isn't really too much to ask, in my opinion, and (2) local storage is per-domain, which is the bigger drawback on SE, where you probably want these settings to apply on all SE sites.
A cursory web search finds this: github.com/sizzlemctwizzle/GM_config/wiki. Are you familiar with that library or others like it? I know you ended up rolling your own solution for Userscripters, and I remember that we discussed it, but I don't recall how it worked. Was it based around the same GM_getValue/GM_setValue functionality?
Is that portable to all userscript managers that anyone would care about nowadays?
Also, on an unrelated note, are you familiar with ==UserLibrary==? I see that's something Greasemonkey supported, but I can't find that Tampermonkey or any other userscript manager documents it.
 
@CodyGray heya! Basically continued to develop the configurer: stackapps.com/q/9403. If you recall, we discussed changing the placement of the icon that opens it, so I went ahead and made the position configurable (top nav bar icon, sidebar button, and a footer link button). Still have some kinks to work on (such as sidebar button styling), though
it's dependent on a script that provides a standardized API for interacting with storage of userscript managers, falling back to localStorage if none found
 
12:59 PM
So it's basically a script that encapsulates the difference between GM_getValue and GM.getValue (and the "set" equivalents)? This is a script you wrote yourself?
 
yup
basically using the adapter pattern
the configurer built on top of it works kind of in the same way as the GM_config lib you mentioned above
 
Is there a reason that you built something new, instead of using that other library? Were you unfamiliar with any existing library? Or just interested in the challenge? Or is there some improvement that it provides?
@OlegValteriswithUkraine "Adapter pattern". I see. :-) So you did not like my simplistic pattern: const GM_XML_HTTP_REQUEST = ((typeof GM !== 'undefined') ? GM.xmlHttpRequest.bind(GM) : GM_xmlhttpRequest);
 
@CodyGray hmm, I don't recall ever using this metadata block header - seems like it isn't officially supported right now by GM anyway
 
The reason I ask is that SO has promised to make more breaking changes that will affect userscripts, so I'm planning to try to reduce the maintenance burden by consolidating common code that is currently repeated across multiple scripts into a single library that hopefully all scripts can use. Earlier today, I extracted all the helper functions used by one script and put them into a common code file: github.com/codygray/SO-mod-userscripts/blob/…
(And barely resisted the urge to put that in an IIFE named SEX.)
Anyway, having a more formal, better supported way of doing this would be nice, rather than just brute-forcing it.
 
@CodyGray well, for the most part, interested in the challenge as usual + making something more customizable than a packaged solution. The library that manages script configuration provides classes sharing a common API for different script managers (GreasemonkeyStorage, TampermonkeyStorage), allows hot reloading of those storages, can determines which storage to use automatically.
@CodyGray you used the same pattern there :) The reason that interaction with storage lead me to the idea of making a library is that there is a wider discrepancy between localStorage, the API that Greasemonkey provides, and what the rest of the managers provide.
Were it as simple as const setValue = GM.setValue.bind(GM) || GM_setValue, I'd probably go for the same simple approach
 
1:17 PM
I see. Yeah, I haven't actually looked into this specific API, so I don't know what complexity there is.
 
@CodyGray yeah, I've actually been thinking about extracting a bunch of commonly used things in SOMU scripts to a shared library, but you've beaten me to it :)
 
Yeah, I think this is a very important project.
Every script has its own copy-pasted or written-from-scratch variants of the same basic functions.
So when SO/SE changes something, it's too damn hard to update everything. Not to mention that when there's some enhancement made (e.g., better error handling), only that specific script benefits, not all of them.
Plus, if that kind of thing exists, building new userscripts becomes a lot easier!
(I know I'm extolling the virtues of code-reuse and object-oriented programming like I just invented it...)
 
@CodyGray yeah, I guess it's a natural outcome of the SOMU becoming a collection over time - by now it definitely warrants a common library. In my experience, it's a common lifecycle thing: I know Makyen has a library of shared utilities, we have a library of helpers (IIRC, double-beep currently knows more about it by now than I do - I haven't been very active on SE lately), and I am sure others have those as well. Would be cool to consolidate all these projects, but that'd require ...
... more free time to dedicate to it than I currently have to tackle
 
I mean, yeah. But what I'm thinking is, I have a limited amount of time to devote, but spending time on this will mean a lot less time in the aggregate.
I just want to do it right, not some hacky, half-arsed attempt that I come up with because I have no idea what I'm doing when it comes to JS.
 
@CodyGray yeah, I know the struggle all too well - that's really great that you dedicated time to extract common SOMU functions in a shared library
 
1:29 PM
It was only one layer of the onion.
There's a script that adds additional quicklinks to a post. Sam's original version added them to something that popped-up on hover, which I hated. So he made me an "inline" version. Time passes, and those two variants of the script have diverged, because everyone only improves/maintains the one that they personally use.
 
@CodyGray yeah, the usual dilemma of spending more time in the short term for long-term benefits. But sometimes the temptation to just copy-paste a utility is too damn strong :)
 
I recently made a whole bunch of significant improvements to the "inline" variant (because that's the one I use), and I decided that there's no good reason why the two shouldn't be combined. So I did that. Which is good. Except that then you have to pick a default setting for whether it's inline or out-of-line, and there's no good default.
So I decided I'd extract all of the SE-related functions into a shared library, and then I'd extract all of the code that actually implements this particular userscript into another file. Then, the two different userscripts would become simply stubs that call into this "worker" library. github.com/codygray/SO-mod-userscripts/commit/…
It feels kinda weird, but... it's working?
Thus, whichever variant of the script you install controls the default, but you can easily override it by setting a value in your local storage.
And all of the code is fully shared, even though there are two different variants of the userscript itself.
So, unless this is like a really horrible idea for some reason I don't know about, the only remaining thing to think about is how to make the options reasonably configurable. Previously, anyone who installed the script would at least see the options (and the documentation related to them) at the top of the userscript code, so they would at least know about them if they cared. But now, they're hidden away in a shared implementation file, so they're not at all visible.
 

« first day (989 days earlier)      last day (450 days later) »