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 to work on from a specified category or list of articles.
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). However if hops > 1, it will always descend into subcategories if there are any.
The example configuration at the end shows the kinds of things you can do, adding these menu options:
To enable this tool, add importScript("User:GregU/randomlink.js")
to your
personal JavaScript page, then hit reload.
Several variables can be added to your vector.js to customize the tool.
To configure the tool for several different purposes, you can add your own menu options that call randomLink(). The randomlink_start and randomlink_hops settings can be specified as parameters to randomLink() in this case. The following code adds five menu options in addition to "Random link":
importScript("User:GregU/randomlink.js");
addOnloadHook( function()
{
// Other special cases are "Special:RecentChangesLinked" and "Special:Contributions"
addPortletLink('p-navigation', 'javascript:randomLink("Special:WhatLinksHere")',
'Random back-link', 'n-randomback', 'Random page that links here');
addPortletLink('p-navigation', 'javascript:randomLink("Special:AllPages",4)',
'Random page', 'n-randompage2', 'Load a random article, the slow way');
// Ignore most of the top and bottom meta links on WP:FA
randomlink_exclude = /^Wikipedia:|^Portal:|^(Lists?|Outline|Library) of|^(Deaths in )?20\d\d$/;
addPortletLink('p-navigation', 'javascript:randomLink("Wikipedia:Featured articles")',
'Featured article', 'n-randomfa', 'Pick a random featured article');
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');
// WhatLinksHere is probably a better way to find all articles in a WikiProject
bblist = "Special:WhatLinksHere/Template:WikiProject_Baseball?namespace=1&hidelinks=1&limit=250";
addPortletLink('p-navigation', 'javascript:randomlink_paged=1;randomlink_maxfrom=24000000;randomLink(bblist)',
'Baseball article', 'n-randombb', 'Random article in WikiProject Baseball');
});
See wikibits.js for documention on addPortletLink().
To access this tool from browser bookmarks, see this discussion.
This
edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
When trying to install and use the script, I found that it was broken. Specifically, manually calling randomLink()
lead to an error regarding the fact that getElementsByClassName
is not defined in a script. A quick search and testing in
my common.js (
version as of writing) revealed that the problem could be fixed by replacing line 21, which currently reads var spec = getElementsByClassName(topnode, 'div', 'mw-spcontent');
, with var spec = document.getElementsByClassName(topnode, 'div', 'mw-spcontent');
. I personally would appreciate being able to load the script rather than copy and paste the fixed version into my common.js and I am sure others who learn of this script would feel the same. Thank you for any help and take care. —
The Editor's Apprentice (
talk) 19:12, 25 August 2022 (UTC)
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 to work on from a specified category or list of articles.
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). However if hops > 1, it will always descend into subcategories if there are any.
The example configuration at the end shows the kinds of things you can do, adding these menu options:
To enable this tool, add importScript("User:GregU/randomlink.js")
to your
personal JavaScript page, then hit reload.
Several variables can be added to your vector.js to customize the tool.
To configure the tool for several different purposes, you can add your own menu options that call randomLink(). The randomlink_start and randomlink_hops settings can be specified as parameters to randomLink() in this case. The following code adds five menu options in addition to "Random link":
importScript("User:GregU/randomlink.js");
addOnloadHook( function()
{
// Other special cases are "Special:RecentChangesLinked" and "Special:Contributions"
addPortletLink('p-navigation', 'javascript:randomLink("Special:WhatLinksHere")',
'Random back-link', 'n-randomback', 'Random page that links here');
addPortletLink('p-navigation', 'javascript:randomLink("Special:AllPages",4)',
'Random page', 'n-randompage2', 'Load a random article, the slow way');
// Ignore most of the top and bottom meta links on WP:FA
randomlink_exclude = /^Wikipedia:|^Portal:|^(Lists?|Outline|Library) of|^(Deaths in )?20\d\d$/;
addPortletLink('p-navigation', 'javascript:randomLink("Wikipedia:Featured articles")',
'Featured article', 'n-randomfa', 'Pick a random featured article');
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');
// WhatLinksHere is probably a better way to find all articles in a WikiProject
bblist = "Special:WhatLinksHere/Template:WikiProject_Baseball?namespace=1&hidelinks=1&limit=250";
addPortletLink('p-navigation', 'javascript:randomlink_paged=1;randomlink_maxfrom=24000000;randomLink(bblist)',
'Baseball article', 'n-randombb', 'Random article in WikiProject Baseball');
});
See wikibits.js for documention on addPortletLink().
To access this tool from browser bookmarks, see this discussion.
This
edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
When trying to install and use the script, I found that it was broken. Specifically, manually calling randomLink()
lead to an error regarding the fact that getElementsByClassName
is not defined in a script. A quick search and testing in
my common.js (
version as of writing) revealed that the problem could be fixed by replacing line 21, which currently reads var spec = getElementsByClassName(topnode, 'div', 'mw-spcontent');
, with var spec = document.getElementsByClassName(topnode, 'div', 'mw-spcontent');
. I personally would appreciate being able to load the script rather than copy and paste the fixed version into my common.js and I am sure others who learn of this script would feel the same. Thank you for any help and take care. —
The Editor's Apprentice (
talk) 19:12, 25 August 2022 (UTC)