Wikipedia talk:Text reactions

Text reactions
A feature I've seen suggested a couple of times is for the editor to "react" to what the user is typing. Such a feature, I think, is naturally implemented in javascript rather than server-side to avoid excessive data transfer. I made a prototype (User:SD0001/text-reactions.js) of how this could be worked out. It's a WIP (though I'm beginning to run out of ideas of how it can be improved). I'm calling this "text reactions" (after an internal feature in Convenient Discussions that's similar).

The current prototype is pretty basic – you can configure the  array to react to keypress of a given key (though this by itself seems a useless feature), and by extension to react to words (by listening to keypress of word delimiters like space, comma, period, semi-colon, etc). So if someone writes "fuck" maybe we could show a pointer to WP:CIVIL. A more useful feature would be to react to insertion of a reference (so we can alert them of unreliable ones), but how to implement this?

As for performance, I've tried to optimise a lot as running many JS checks on every keystroke isn't that feasible – but also, most of the checks would anyway require more intelligent triggers than keystrokes.

This works on the 2010 editor with or without syntax highlightening enabled. I think 2017 editor support could also be added easily. But as for VisualEditor, I've no idea.

Let me know what you folks think! – SD0001  (talk) 14:30, 2 December 2021 (UTC)
 * just realized it's possible to listen to pasting of text as well in the editbox. – SD0001  (talk) 15:26, 2 December 2021 (UTC)
 * It's technically like jQuery.IME. P.T.Đ (talk) 06:41, 3 December 2021 (UTC)
 * Hmm, yeah - IME also seems to work primarily through a keyup listener. – SD0001  (talk) 09:32, 5 December 2021 (UTC)
 * Just amended the script to allow for reactions to pastes and drag-drops, as well as to ref insertions via RefToolbar which is by a horrific hack – as there doesn't seem to be any event listener that can catch textbox modifications done by some other JS on the page. The hack could be removed by editing the RefToolbar gadget to fire an event (via mw.hook) on ref insertions. – SD0001  (talk) 09:36, 5 December 2021 (UTC)
 * This sounds fantastic! For practical directions to go with it, it looks from the code like you've got something for dab pages, which is clearly wanted. Beyond that, I think MOS:WTW would be a great area to explore to help out newcomers—there aren't that many instances where you can legitimately use "award-winning" or most of the other words on that list. For potentially unreliable sources, you could use redlisted entries at WP:RSP as a starting point. &#123;{u&#124; Sdkb  }&#125;  talk 04:32, 6 December 2021 (UTC)
 * As for words to watch, there exists a list at https://github.com/mourner/bullshit.js/blob/master/src/terms.js (although many of those are likely overkill). For unreliable sources, we could use the regexes out of User:Headbomb/unreliable.js. – SD0001  (talk) 07:49, 11 December 2021 (UTC)
 * If this will be an extension, be sure to build opt-out/opt-in controls in to it! — xaosflux  Talk 16:26, 29 January 2022 (UTC)

Edit filter popup trigger
See T315072. This is similar to text reactions, but with checks defined as AbuseFilter rules. – SD0001  (talk) 12:40, 15 August 2022 (UTC)