User:Inductiveload/save load actions

Save/Load Actions provides a simple way to run functions on page load and save. This can be used to automatically insert templates, tidy formatting and construct page headers or footers.

Installation
Add to your common.js:

Auto Refs
Auto Refs is a built-in function of Save/Load Actions that simplifies the placement of references on a page. This saves effort in copy-pasting ref content, which usually OCRs at the end of the page, into ref tags in the text. Simply leave a  tag in the text body and give the refs a matching prefix at the bottom and Auto Refs does the rest: it formats the reference with   tags and places them in the text at the right places.

You can turn this function off by setting  in the configuration object. By default it is enabled.

The gadget conducts a replacement of references matching a set pattern:

After Auto Refs runs:

Follow-refs

 * Refs called  will be treated as a follow-ref. Enter the name of the ref on the previous page to use in the   attribute. They will be placed at the start of the page.

Named refs

 * If there are multiple instances of, the first one will contain the content and the second one will be a self-closed ref tag with the same name attribute. By default, the script will try to choose a sensible name that won't clash, by using the page number.
 * If the ref name after the asterisk contains an equals (=), the ref will be named, even it's the only instance. This allows a follow-ref on a subsequent page.
 * A name can be entered after the "=" and it will be used instead of the default ref name. E.g.  will become.

Configuration
You can configure the Save/Load Actions gadget like this, using the  hook:

There are the following options that you can pass into the config hook:

function callback(editbox) { ... }
 * : set to false to disable the gadget entirely for this page
 * : a list of namespaces to enable the Gadget for (default is )
 * : a list of functions to run when "Save", "Show Preview" or "Show Changes" are clicked. This list is empty by default. The functions are of the form:
 * : a list of functions to run when the page is first loaded. This list is empty by default.
 * : a list of replacements to make on page save. This list is empty by default. You can use these replacements to write your own "instant shortcuts" which are automatically replaced when you Save or Preview the page. This is a list of pairs of regular expressions and the replacements, which can be strings or functions.
 * : enable the "auto refs" function.

Replace | with Bar
This is useful when constructing ToCs.

Write a running header on page creation, changing sides as needed
The following load function will put it into a running header on the correct side. You can add more logic to control what title is used, or even pull text out of the main text box and use that.