User talk:GregU/randomlink.js
This tool adds a "Random link" option to the sidebar menu. When selected, you will travel to a random link on the current page (or specified page or pages). This is useful if you wish to view a random article that is related to the current article. It is also useful for unbiasedly selecting an article from a specified category or list of articles, to work on.
The tool will consider only "normal" links in an article. It is also designed to do the right thing on special pages, considering only the "main" links. For example, on recent changes or user contributions (among many others), it will choose a title from the list, excluding user links and other links. But on history pages, it will follow only user page links, as they are the main thing there. In categories, it will choose only items... if there are any pages or files in the category. Else, it will use content links and subcategories (and parent categories, currently).
Installation
To enable this tool, just add importScript("User:GregU/randomlink.js")
to your monobook.js page, then hit reload.
Customization
Several variables can be added to your monobook.js to customize the tool.
- randomlink_open = true;
- Set this variable to true to cause the new page to be opened in a new window or tab, leaving the current window/tab unchanged.
- randomlink_start = "Wikipedia:Featured articles";
- randomlink_start = [ "Wikipedia:Featured articles", "Wikipedia:Featured pictures" ];
- Use this variable to choose from a specified starting point rather than from the current page. If you list multiple start pages (as an array or as a pipe-delimited string), the tool will select randomly among them. To weight a start page more strongly (because it has more links under it), list it multiple times.
- randomlink_hops = 2;
- Normally, only one level is followed, not counting the start page. But if your start page is a category that lists other categories, it will take several hops to reach an actual article. Hops are limited to 4.
- randomlink_paged = true;
- Some special pages are paged, with the first page listing only the first hundred or so links. To remove this limitation, set this variable to true, and the tool will attempt to select a random section of the full result set for its start page. For example, if your start page is a category that usually has over 200 articles in it or what links here with over 500 links, you should probably set this. Also use it on special pages like uncategorized pages.
- randomlink_exclude = /^List of|\(series\)/;
- If certain titles are being selected that you wish to exclude, you can use this variable to filter them out based on a regular expression. The above example excludes titles beginning with "List of" or containing "(series)".
You can also add extra menu options to use the tool for several different purposes. This code adds three menu options in addition to the "Random link" option:
addOnloadHook (function()
{
addPortletLink('p-navigation', 'javascript:randomLink("Special:AllPages",4)',
'Random page', 'n-randompage2', 'Load a random article, the slow way');
vgcats = "Top|High|Mid|Low|Low|Low|Low|Low|Low|Low|NA|Unknown";
vgcats = vgcats.replace(/\w+/g, "Category:$&-importance video game articles");
addPortletLink('p-navigation', 'javascript:randomlink_paged=1;randomLink(vgcats)',
'Video game article', 'n-randomvg', 'Random article in WikiProject Video games');
bblist = "Special:WhatLinksHere/Template:WikiProject_Baseball?namespace=1&hidelinks=1&limit=100";
addPortletLink('p-navigation', 'javascript:randomlink_paged=1;randomLink(bblist)',
'Baseball article', 'n-randombb', 'Random article in WikiProject Baseball');
});