JavaScript gadget to add specific functionality on pages: Open particular links automatically on new browser window or tab.

This affects namely

On most browsers a different window can be forced by simultaneous pressing [Ctrl] or [Shift]. If forgotten on page preview the edit change may be lost when returning to edit mode.

Usage

edit
  • If your project has registered this as a gadget, just activate on your Preferences page.
  • Otherwise include the following lines into your common.js or similar:
mw.loader.load("https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/clickDivertimento/r.js&action=raw&bcache=1&maxage=86400&ctype=text/javascript");
  • The gadget works also with non-WMF sites using MediaWiki 1.18 or higher.
  • If not working as registered user the gadget can be activated by greasemonkey or browser user script.

User options

edit

Quick interactive costumization

edit

The simple on/off switch options can be set interactively on Special:Blankpage as soon as the script library has been loaded.

When reloading a page the preferences declared here come into effect. This dynamic assignment overrides the static setting by JavaScript.

These user preferences are not visible to other users.

Even anonymous users may store preferences, but for current browser profile only (utilizing localStorage).

Configuration by JavaScript

edit

Insert the following lines into your common.js (best before mw.loader.load, if present):

if ( typeof mw.libs.clickDivertimento !== "object" ) {
   mw.libs.clickDivertimento  =  { };
}
mw.libs.clickDivertimento.key1 = value1;
Key Value Meaning
large true Include more list pages.
Default: false – watchlists and “recent changes”
leave true All external links shall be opened in new browser window.
Default: false – unchanged layout
mode 0 Create entirely new window.
Default: 0 – For all diverted targets
  • 1 – Shared windows for the same tasks
  • 2 – All in the same different window
targets object Use the same window for similar links
Default: No specification.
Assigns to a window name one of
  • string – to be found literally in URL
  • Array with elements
    • string – to be found literally in URL
    • RegExp – to be matched by URL

A window name should begin with letter, only ASCII letters and digits, no more than 10 for distictive name.

Example:

if ( typeof mw.libs.clickDivertimento !== "object" ) {
   mw.libs.clickDivertimento  =  { };
}
mw.libs.clickDivertimento.large    = true;
mw.libs.clickDivertimento.targets  = { wphelp: "/wiki/Help:",                                  
                                       DNB:    "http://d-nb.info/",                                  
                                       jdk:    [ "http://java.com/", 
                                                 /http:\/\/(:?docs\.)?oracle\.com\// ]
                                     };

Include more list pages

edit

On individual request apply to:

The target window diverting is always applied to the list section of

edit

On any page all links written as URL in source text shall be diverted.

  • Default: open in the same window, if no other reason.

Create entirely new window

edit
  • For all diverted targets (default)
  • 1 – Shared windows for the same tasks
  • 2 – All in the same but different window
edit

Specified URL patterns shall be collected within the same window. This window gets a specific name and will be reused.

This comes into effect if not requested “entirely new window for all diverted targets”, but some kind of window sharing.

A window name should begin with letter, only ASCII letters and digits, no more than 10 for distictive name.

Codes

edit
Source code
ResourceLoader
Namespaces all
Cookie anonymous users only: preferencesGadgetOptions (localStorage)
mw.libs clickDivertimento
MediaWiki
  • 1.26 (mw.storage) options for anonymous users
  • 1.23 for registered users

Other languages

edit

This gadget is prepared for multilingual support.