Jump to content

User:Zanaq/browse.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
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">&nbsp<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> &middot; ' + 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 + ' &middot; <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);
}

});

});

}