Help:User scripts

User scripts are short JavaScript computer programs that add extra functionality to the Wikidata user interface for an individual, logged-in, user.

Scripts can be stored on any JavaScript file wiki page (the page name ends in .js).

Each user has a special page called their common.js where they list the scripts they wish to use (for example, User:Pigsonthewing/common.js). It can be accessed via Special:Mypage/common.js, which will redirect you to your own common.js page.

You can find scripts to add that were created by the community here.

Adding a user script to your Wikidata profileEdit

The easiest way to add user scripts to your profile is to first add the ScriptInstaller user script. This script allows you to install user scripts with the click of a button from the page of the user script. To add this script, or any other script without using ScriptInstaller, follow the instructions below.

Once you have logged in, edit your common.js, and add a line like:

mw.loader.load( '//' );

where script_path is the title for the page containing the user script. Be sure to replace any spaces with underscores.

For example, in order to add the user script User:So9q/ScriptInstaller.js, you add:

mw.loader.load( '//' );

Creating a user scriptEdit

To create a userscript, create a wiki page whose name ends in .js. It is recommend that you create your userscript as a subpage of your userspace. You can easily do this below:

Wikidata user scripts often utilize:

For example, an element can be added to the page using JQuery after a statement has been saved (the wikibase.statement.saved hook is fired). It is a good idea to look at others' scripts to see how this is done.

See alsoEdit

For more advice on adding user scripts, see en:Wikipedia:User scripts, but remember to add Wikidata user scripts to your Wikidata user-space, not the one on Wikipedia!