User:Kephir/gadgets/unclutter

From Wikipedia, the free encyclopedia
Unclutter
Author(s)Keφr
StatusSemi-stable
Updated2013-09-22
Browser support
  • Developed on Chromium Firefox
Skin support
  • Tested mostly on Vector
  • No issues noticed on Modern and Monobook
Source

Unclutter helps in freeing Wikipedia from distractions. It does so by hiding some of the editing hints, warnings, never-to-be-used helpers, policy reminders on talk pages and other unnecessary verbosity. It also adds hiding links to discussion headers and editnotices, wraps and minimises user signatures.

Warning: Enabling the stylesheet installed by Unclutter is not recommended for inexperienced editors, who might find the advice hidden by this script to be occasionally useful. Specifically, hiding messages reminding you of Wikipedia policies does NOT exempt you from these policies. New users may wish to install Unclutter with the stylesheet disabled by default, see the configuration section below.

Installation[edit]

Copy the following line into your common.js:

window.kephirUnclutter = { /* configuration */ };
importScript('User:Kephir/gadgets/unclutter.js'); // [[User:Kephir/gadgets/unclutter]]

You may want to insert configuration options before importing the script; again, see the configuration section.

The CSS stylesheet will be pulled automatically from the page User:Kephir/gadgets/unclutter.css.

Templates and interface affected[edit]

Items marked "heuristic" may be potentially incomplete or affect unexpected places, although the selectors have been chosen to be as specific as possible.

By the stylesheet[edit]

  • Copyright and policy warnings and reminders in the old editor — hidden
  • JavaScript, CSS, category and file editnotices — hidden
  • Instructions how to WP:BYPASS browser caches on JavaScript and CSS pages — hidden
  • {{talk header}} — notice hidden; archive box kept
  • {{calm}} — hidden
  • {{off topic warning}} — hidden
  • {{controversial}} — hidden
  • {{not a forum}} — hidden
  • {{db-meta}} — trimmed down
  • {{proposed deletion/dated}} — trimmed down
  • Overly fancy user talk pages — restored default styles (heuristic)
  • Welcome templates — trimmed down (heuristic)
  • Twinkle preferences notice — hidden

By JavaScript[edit]

  • Editnotices and editintros — made collapsible
  • Category and template list in the old editor — made collapsible, hidden by default
  • Discussions on talk pages and other discussion pages — made collapsible
  • Signatures — minimised

Importing the script will also add a "Toggle Unclutter" item to the toolbox. Clicking it will change whether the stylesheet affects the page.

Signature minimisation[edit]

Custom-styled Unclutter and Comments in Local Time reformatting signatures and timestamps in a Wikipedia discussion.

By default, Unclutter scans non-special non-article pages for timestamped signatures, wraps them up and replaces with a text of the form:

Example (annotation) (talkcontribactionslogsig)

The last link will show the original signature. In the section below, you can learn how to change the default behaviour; instead of completely hiding customised signatures, you might want to apply styles to specific users or groups (i.e. IP editors). Unclutter wraps signatures inside a span element and attaches CSS classes to them to allow this. When signature minimisation is disabled, this is the only thing Unclutter does.

kephir-unclutter-minisig
Attached to the minimised signature.
kephir-unclutter-signature-wrapper
Attached to the original signature.
signature
Attached to both of the above.
signature-username
Attached to signify whose signature it is. When referring to this class, some special characters may need to be escaped according to the CSS escaping rules.
ipv4
Attached to signatures of editors identified by an IPv4 address.
ipv6
Attached to signatures of editors identified by an IPv6 address.
unregistered
Attached to all signatures of unregistered editors.

The following classes are used in the minimised signature:

dash
The initial em-dash (—).
username
The user's name.
annotation
The username annotation, if any.
tlk-link
The talk page link.
ctb-link
The contributions page link.
act-link
The user's act link (for actions performed by this user).
log-link
The user's log link (for actions performed on this user).
sig-link
The "sig" link.

For example, to hide the log link, add this to your stylesheet:

.kephir-unclutter-minisig .log-link {
	display: none;
}

Limitations[edit]

Signatures have very few distinguishing features both in the wiki markup and in the rendered page; there is no 100% reliable way to identify them. Unclutter's approximate heuristic is: any fragment of the DOM tree starting with a link to a user-related page (user page, user talk page, Special:Contributions, Special:EmailUser, Special:Log) and ending with a timestamp appearing on a non-article page is considered a signature. To protect against false positives, Unclutter will not recognise, or may recognise less reliably signatures which:

  • Have no timestamp;
  • Have a timestamp in a format other than H:i, j F Y (T) ("15:29, 27 March 2024 (UTC)"), i.e. as generated by ~~~~~;
  • Have a timestamp wrapped in special markup;
  • Contain block-level elements, or elements like <br>, which are not usually found in signatures;
  • Contain long text;
  • Do not contain any link to a user-related page;
  • Contain any images whatsoever;
  • Contain any external links (including interwiki links);
  • Contain links to pages in unusual namespaces (like Draft:, Help:, MediaWiki:, Category: or File:)
  • Contain links to special pages which are not user-related;
  • Contain links to user-related pages of other accounts.

Unclutter may be therefore unsuitable for sites with signature policies even more relaxed than English Wikipedia's. The only signature format which should not ever cause problems is the default format used by MediaWiki.

If you encounter a user whose signature Unclutter cannot recognise, consider asking them to use the default signature. Chances are that their fancy signature is already in violation of the signature policy.

Configuration[edit]

To configure Unclutter, add the following code before importing the script:

window.kephirUnclutter = {
	enableOnPageLoad            : true,
	wrapDiscussions             : true,
	collapseDiscussionsByDefault: false,
	signaturesProcess           : true,
	signaturesMinimise          : true,
	signaturesColourise         : true,
	signaturesExceptions        : [],
	userAnnotations             : { /* "username": "annotation" pairs, separated by commas */ },
	processSig                  : function (context) { return false; },
	postProcessSig              : function (context) { return false; }
};

To set options, change values to the right of the colon. The values listed here are the defaults. Any line in the above code may be omitted, except for the first and the last. The last item should not end with a comma; this is a syntax error and will prevent the script from executing.

enableOnPageLoad
Whether to enable the stylesheet on page load. Inexperienced users should set this to false, otherwise nasty things may happen. At worst, a visit to Administrators' noticeboards. You have been warned.
wrapDiscussions
Whether to wrap discussions inside divs to make them collapsible. Disabling this might improve performance slightly, if you do not use this feature.
collapseDiscussionsByDefault
Whether previously unseen discussions should be collapsed or expanded by default. Previously seen discussions are left in the state they were last seen; HTML5 localStorage is used to remember it.
signaturesProcess
Determines whether to scan pages for signatures to process. Articles and special pages are never scanned. Only timestamped signatures are recognised, as non-timestamped signatures are too difficult to identify.
signaturesMinimise
Determines whether to minimise found signatures.
signaturesColourise
Determines whether Unclutter will set different background colours for signatures of different users.
signaturesExceptions
An array of names of users whose signatures are exempted from minimisation. Usernames should be written inside single or double quotes, separated by commas, like this: ["Example", 'Undefined']
userAnnotations
A braced list of username: annotation pairs, both enclosed within double or single quotes, separated by commas. The signature minimiser will attach the appropriate annotation to the username specified. For example: { "קיפודנחש": 'kipod' } (past default).
processSig
A JavaScript function which is called before minimisation and may return true to prevent Unclutter from performing it. The context is an object containing various information like the username, the DOM node of the minimised signature, etc. See the source code for details.
postProcessSig
A JavaScript function which is called after minimisation. context is the same as above.