The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.
Proposed new code: User:Xover/EasyLinks.js
Specific issues / areas for feedback: Not a change to an existing script, but rather a new user script for which I would appreciate review and feedback (both at the level of code and functionality and docs, if you're so inclined).
I've written a user script to make it easier to grab internal wikilinks to diffs, specific page revisions, and sections. Mainly to scratch my own itch, but hopefully it'll be useful for others as well. However, since this is my first user script, I would appreciate a sanity check on the code (and docs, functionality, etc., if you're inclined) before I subject others to it.
Obvious stuff that might be considered problematic or for which there may be better solutions that I'm not aware of:
document.execCommand("copy"). Because this API mimics the interactive "Copy" command (vs. manipulating the clipboard directly and programatically) it inherently requires that the data to be put on the clipboard must first exist somewhere as a text selection. This in turn means EasyLinks must insert the links into the page somewhere before selecting and copying. In addition to this, even the old clipboard API has limitations in browser support (e.g. Safari added support in a 2016 tech preview).The approach I've picked is to pop up a OO.ui.MessageDialog with an embedded OO.ui.TextInputWidget to hold the wikilink. This is both to be transparent to the user about what's happening, and to provide a manual fallback if copying fails: the dialog remains up so the user can hit Ctrl-c and dismiss the dialog with the mouse (or hit Enter). Is popping up such dialogs appropriate for this interaction? When automatic copying works it will only briefly flash up and then disappear, which is not a particularly good user interface. Would it be better to insert a simple text field or span somewhere unobtrusive and remove it afterwards?&diff= parameter in the URL is prev or cur (instead of an actual diff or rev id). I haven't figured out in what situations that happens and I'm not sure if there's any way to make EasyLinks' various functions work in those situations.p-cactions the right place to put the portlets? And I'm just throwing them in there, so random timing and JS load order determines where in the menu the EasyLinks functions end up. Should I be trying to add a specific position or order? Should I be looking at creating my own group like Twinkle does?
Thanks, Xover
mw.util.addPortletLink, you set the "url" target to #. I suggest changing it to javascript:void(0) - neither should take you anywhere, but using # has (for me) caused some issues with it working as a link to # and/or conflicting with other scripts that also use # for their triggers, since you might inadvertently trigger other code in other scripts too. --DannyS712 (talk) 22:52, 15 May 2019 (UTC)
window.location or triggering off a .onfocus event somewhere awkward. As for following the link when clicked that's a problem when the handler returns something other than false (which the undefined returned by void(0) coerces to), for example because it errors out before getting to a return false; at the end of the handler (or because you forget to add it, of course). But in anything post-IE6 I believe the preferred way to handle that is with event.preventDefault() which explicitly tells the JS engine to suppress normal link behaviour. Granted I'm a rank amateur at this, but, anecdotally, this has worked fine in those cases I've had occasion to test (very small sample size, admittedly). --Xover (talk) 14:36, 16 May 2019 (UTC)