This user script looks for shortcut boxes[a] (used extensively on project pages such as WP:MOS) and adds beside each shortcut link a button that copies the markup necessary to use that shortcut. For example, a link to WP:US will get a button that copies [[WP:US]] to the clipboard, and a link to Template:Shc displayed as {{Shc}} will get a button that copies {{Shc}} to the clipboard.
The text on each button is exactly what that button copies to the clipboard. The original link to the redirect page for the shortcut is moved to the side and shortened to "v" (for "view"), so the script does not remove the original functionality. (This does not apply to Short URL box; see below.)
For template shortcuts, the script will ensure subst: is included in the markup if it detects that it is required.[b] Otherwise, the markup is that of a {{transclusion}}. The result is that lists of template shortcuts (as seen at Template:Uw-vandalism1 and Template:Template link, for instance) become lists of buttons allowing valid template markup to be quickly copied.
Slightly different treatment is given to links in Short URL boxes. First, the button copies w.wiki/url (not the markup [https://w.wiki/url]) to the clipboard when clicked. This is so the link can be shared off-wiki. Second, the button replaces the link to save space, since the link is usually directly to the page that the template is on, and thus serves no purpose.
This script is designed to work on both desktop and mobile.
Installation
As described at Wikipedia:User scripts § Installation. Once installed, you can try out the script by looking at Template:Shortcut templates. (Note that Template:Shortcut-style further links, which is included in that table, is explicitly ignored by this script.)
Options
Behaviour can be controlled by setting values in your common.js before loading this script: set window.scc_noMonospace = true to use the normal font family for the buttons rather than the monospaced one, and set window.scc_selectOnClick = true to select the text in the button when you click it. (The latter is useful if you have clipboard permissions turned off, because the automatic copying won't work, but once the markup is selected you can copy it manually.)
Notes
- ^ a b Specifically, the Shortcut, Template shortcut, Template redirect, Short URL box, Shortcut mini and Shortcut compact templates.
- ^ The method by which the script does this is not perfect. If it breaks, please let me know.
