User:Zanaq/browse.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Zanaq/browse. |
/*
Browse through the articles alphabetically.
(c) Zanaq 2013, GPL
inspired by Trewal, http://nl.wikipedia.org/enwiki/w/index.php?title=Wikipedia:De_kroeg&diff=36578376&oldid=36577552
*/
if (wgNamespaceNumber != -1)
{
if (typeof(browseShowRedirects) == "undefined") browseShowRedirects = true;
if (typeof(browseShowNavigationBelowTitle) == "undefined") browseShowNavigationBelowTitle = true;
if (typeof(browseNumberOfPagesToShowInNavigation) == "undefined") browseNumberOfPagesToShowInNavigation= 3;
browseNumberOfPagesToShowInNavigation = browseNumberOfPagesToShowInNavigation + 1;
if (browseNumberOfPagesToShowInNavigation < 2) browseNumberOfPagesToShowInNavigation = 2;
if (browseNumberOfPagesToShowInNavigation > 100) browseNumberOfPagesToShowInNavigation = 100;
var nextpage = null;
var nextpagedata = null;
var previouspage = null;
var nextredirect = false;
var previousredirect = false;
var navigation = '';
var encodedTitle = encodeURIComponent(wgTitle);
var thispagename = wgPageName.replace(/_/g," ");
var redirectfilter = (browseShowRedirects) ? '' : '&gapfilterredir=nonredirects';
if (mw.user.options.values.skin == 'vector')
{
appendCSS('.browse-navigation-top {font-size:70%;}');
} else {
appendCSS('.browse-navigation-top {font-size:85%;}');
}
if (document.getElementById('coordinates') != null)
{
appendCSS('.browse-navigation-top {width:75%;}');
}
appendCSS('#siteSub {display:none;}');
appendCSS('.browse-navigation-top {position:relative;top:-4px;padding-top:0;padding-bottom:0}');
appendCSS('#firstHeading {border-bottom:none}');
appendCSS('.browse-navigation-bottom {margin-top:.5em;}');
if (browseShowNavigationBelowTitle)
{
navigationtop = '<div class="toc browse-navigation-top" id="browse-navigation-top"> <div>';
$(navigationtop).insertAfter('#firstHeading');
}
$('<span/>', {
id: 'linknextpage',
text: '>',
style:'margin-left:.25em;'
}).appendTo('#firstHeading');
dontredirect = (previousredirect == '') ? '?redirect=no' : '';
$('<span/>', {
id: 'linkpreviouspage',
text: '<',
style:'margin-right:.25em;'
}).prependTo('#firstHeading');
$.getJSON('/enwiki/w/api.php?action=query&generator=allpages&format=json&gapfrom=' + encodedTitle + '&gapnamespace=' + wgNamespaceNumber + '&gaplimit=' + browseNumberOfPagesToShowInNavigation + '&gapdir=ascending&prop=info&indexpageids' + redirectfilter ,
function(data) {
nextpage = data.query.pages[data.query.pageids[0]].title;
nextpagedata = data;
nextredirect = data.query.pages[data.query.pageids[0]].redirect;
if (nextpage == thispagename)
{
nextpage = data.query.pages[data.query.pageids[1]].title;
nextredirect = data.query.pages[data.query.pageids[1]].redirect;
}
$.getJSON('/enwiki/w/api.php?action=query&generator=allpages&format=json&gapfrom=' + encodedTitle + '&gapnamespace=' + wgNamespaceNumber + '&gaplimit=' + browseNumberOfPagesToShowInNavigation + '&gapdir=descending&prop=info&indexpageids' + redirectfilter,
function(data) {
previouspage = data.query.pages[data.query.pageids[0]].title;
previousredirect = data.query.pages[data.query.pageids[0]].redirect;
if (previouspage == thispagename)
{
previouspage = data.query.pages[data.query.pageids[1]].title;
previousredirect = data.query.pages[data.query.pageids[1]].redirect;
}
dontredirect = (nextredirect == '') ? '?redirect=no' : '';
$('#linknextpage').html($('<a/>', {
id: 'linknextpage',
href: '/wiki/' + encodeURIComponent(nextpage) + dontredirect ,
title: nextpage,
text: '>',
}));
dontredirect = (previousredirect == '') ? '?redirect=no' : '';
$('#linkpreviouspage').html($('<a/>', {
id: 'linkpreviouspage',
href: '/wiki/' + encodeURIComponent(previouspage) + dontredirect,
title: previouspage,
text: '<',
}));
$(data.query.pageids).each(
function(id, pageid)
{
page = data.query.pages[pageid];
if (page.title != thispagename)
{
showntitle = (wgNamespaceNumber == 0) ? page.title : page.title.substr(page.title.indexOf(':') + 1);
classname = (typeof(page.redirect) != 'undefined') ? ' class="mw-redirect" ' : '';
href = '/wiki/' + encodeURIComponent(page.title);
redirectclassname = (typeof(page.redirect) != 'undefined') ? ' class="allpagesredirect browse-redirect" ' : '';
navigation = '<span ' + redirectclassname + '><a href="' + href + '"' + classname + ' >' + showntitle + '</a></span> · ' + navigation;
}
}
);
showntitle = (wgNamespaceNumber == 0) ? thispagename : thispagename.substr(thispagename.indexOf(':') + 1);
navigation += '<strong class="selflink">' + showntitle + '</strong class="selflink">'
$(nextpagedata.query.pageids).each(
function(id, pageid)
{
page = nextpagedata.query.pages[pageid];
if (page.title != thispagename)
{
showntitle = (wgNamespaceNumber == 0) ? page.title : page.title.substr(page.title.indexOf(':') + 1);
href = '/wiki/' + encodeURIComponent(page.title);
redirectclassname = (typeof(page.redirect) != 'undefined') ? ' class="allpagesredirect browse-redirect" ' : '';
navigation = navigation + ' · <span ' + redirectclassname + '><a href="' + href + '"' + classname + '>' + showntitle + '</a></span>';
}
}
);
navigationbottom = '<div class="toc browse-navigation-bottom">' + navigation + '<div>';
$('#content').append(navigationbottom );
if (browseShowNavigationBelowTitle)
{
$('#browse-navigation-top').html(navigation);
}
});
});
}