User:Shahadat/InsertShortcuts

From Justapedia, unleashing the power of collective wisdom
Jump to navigation Jump to search




User script
Insert Shortcuts
DescriptionAllows the insertion of user-defined tags into the edit area.
Author(s)Shahadat
StatusBeta
First releasedMarch 20, 2020; 4 years ago (2020-03-20)
Version01.04.20
UpdatedApril 1, 2020; 4 years ago (2020-04-01)
Skin supportGreen tickY All skins supported.
SourceUser:Shahadat/InsertShortcuts.js

Insert Shortcuts

Do you spend a lot of time wrapping text in formatting, tags, or templates? Unless you're a WikiGnome, this is probably tiring. Insert Shortcuts is what you need! This script maps the insertion of user-defined text to Alt+1 through Alt+0 (⌥ Option+1 through ⌥ Option+0 on Mac). It is only usable while source editing. Bold and italics are defined by default, and are mapped to Ctrl+B and Ctrl+I, respectively (+B and +I on Mac).

This script will insert text into the edit area based on specially defined rules. If you are not selecting anything, the script will expand your selection to the word at the caret position. Before using the script, you must define your tags at Special:MyPage/InsertShortcutsSettings.js. It's a JS file so only you can edit it. Ignore the warnings when saving.

Here is an example tag definition file:

{{useful template|_}}
<useful tag>_</useful tag>
<code>_</code>
<pre>\n_\n</pre>

The tags are numbered starting at 1 from the top. The _ (underscore) defines where the text you are selecting goes, and the \n expands to an actual 'newline'.

Start Keys Result
Lorem ipsum dolor sit amet. Alt+1 Lorem {{useful template|ipsum}} dolor sit amet.
Lorem ipsum do|lor sit amet. Ctrl+B Lorem ipsum '''dolor''' sit amet.
Lorem ipsum dolor sit amet. Alt+3 <code>Lorem ipsum dolor sit amet.</code>
Pre|stuff Alt+4
<pre>
Prestuff
</pre>
The vertical bar | denotes the caret position.

If you want the tag definition to span multiple lines (in the definition file), you can escape newlines with a backslash \, like so:

{{long template\
|param1\
|param2\
|param3\
|param4\
}}

When you insert this tag, it will become: {{long template|param1|param2|param3|param4}}. If you want it to span multiple lines in the definition file and in the edit area when it is inserted, you need to use \n\, like so:

{{long template\n\
|param1\n\
|param2\n\
|param3\n\
|param4\n\
}}

The 'tag' definitions can take any one of these forms:

  • x_y – Asymmetric wrap.
  • x_ – Prepend.
  • _x – Append.
  • x_x – Symmetric wrap.
  • x – Effectively replaces your selection.
  • _ – Take my word for it, this does nothing. Seriously.


Installation

To use this script, add the following to your common.js (or other):

mw.loader.getScript("/w/index.php?title=User:Shahadat/InsertShortcuts.js&action=raw&ctype=text/javascript"); // Backlink: [[User:Shahadat/InsertShortcuts.js]]

Script Attribution